src/os2.cpp
changeset 6317 70f4e9e52eb1
parent 6298 01c80746f308
child 6318 b72c7e36a2bb
equal deleted inserted replaced
6316:d2b70e10f106 6317:70f4e9e52eb1
   120 bool FiosIsHiddenFile(const struct dirent *ent)
   120 bool FiosIsHiddenFile(const struct dirent *ent)
   121 {
   121 {
   122 	return ent->d_name[0] == '.';
   122 	return ent->d_name[0] == '.';
   123 }
   123 }
   124 
   124 
   125 
       
   126 static void ChangeWorkingDirectory(char *exe)
       
   127 {
       
   128 	char *s = strrchr(exe, PATHSEPCHAR);
       
   129 
       
   130 	if (s != NULL) {
       
   131 		*s = '\0';
       
   132 		chdir(exe);
       
   133 		*s = PATHSEPCHAR;
       
   134 	}
       
   135 }
       
   136 
       
   137 void ShowInfo(const unsigned char *str)
   125 void ShowInfo(const unsigned char *str)
   138 {
   126 {
   139 	HAB hab;
   127 	HAB hab;
   140 	HMQ hmq;
   128 	HMQ hmq;
   141 	ULONG rc;
   129 	ULONG rc;
   174 	ChangeWorkingDirectory(argv[0]);
   162 	ChangeWorkingDirectory(argv[0]);
   175 
   163 
   176 	_random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
   164 	_random_seeds[1][1] = _random_seeds[1][0] = _random_seeds[0][1] = _random_seeds[0][0] = time(NULL);
   177 
   165 
   178 	return ttd_main(argc, argv);
   166 	return ttd_main(argc, argv);
   179 }
       
   180 
       
   181 void DetermineBasePaths()
       
   182 {
       
   183 	_paths.game_data_dir = MallocT<char>(MAX_PATH);
       
   184 	ttd_strlcpy(_paths.game_data_dir, GAME_DATA_DIR, MAX_PATH);
       
   185 #if defined(SECOND_DATA_DIR)
       
   186 	_paths.second_data_dir = MallocT<char>(MAX_PATH);
       
   187 	ttd_strlcpy(_paths.second_data_dir, SECOND_DATA_DIR, MAX_PATH);
       
   188 #endif
       
   189 
       
   190 #if defined(USE_HOMEDIR)
       
   191 	const char *homedir = getenv("HOME");
       
   192 
       
   193 	if (homedir == NULL) {
       
   194 		const struct passwd *pw = getpwuid(getuid());
       
   195 		if (pw != NULL) homedir = pw->pw_dir;
       
   196 	}
       
   197 
       
   198 	_paths.personal_dir = str_fmt("%s" PATHSEP "%s", homedir, PERSONAL_DIR);
       
   199 #else /* not defined(USE_HOMEDIR) */
       
   200 	_paths.personal_dir = MallocT<char>(MAX_PATH);
       
   201 	ttd_strlcpy(_paths.personal_dir, PERSONAL_DIR, MAX_PATH);
       
   202 
       
   203 	/* check if absolute or relative path */
       
   204 	const char *s = strchr(_paths.personal_dir, PATHSEPCHAR);
       
   205 
       
   206 	/* add absolute path */
       
   207 	if (s == NULL || _paths.personal_dir != s) {
       
   208 		getcwd(_paths.personal_dir, MAX_PATH);
       
   209 		AppendPathSeparator(_paths.personal_dir, MAX_PATH);
       
   210 		ttd_strlcat(_paths.personal_dir, PERSONAL_DIR, MAX_PATH);
       
   211 	}
       
   212 #endif /* defined(USE_HOMEDIR) */
       
   213 
       
   214 	AppendPathSeparator(_paths.personal_dir,  MAX_PATH);
       
   215 	AppendPathSeparator(_paths.game_data_dir, MAX_PATH);
       
   216 }
   167 }
   217 
   168 
   218 /**
   169 /**
   219  * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
   170  * Insert a chunk of text from the clipboard onto the textbuffer. Get TEXT clipboard
   220  * and append this up to the maximum length (either absolute or screenlength). If maxlength
   171  * and append this up to the maximum length (either absolute or screenlength). If maxlength