Path getApplicationDirectory() { return getApplicationFilename().directory(); }
void initLogFile() { // first need to establish full path, and create folder if necessary // Maemo/Meego treated as Linux as far as paths are concerned LOG("initLogFile()\n"); // n.b., at this stage logging will only go to console output, not to log file #if _WIN32 bool ok = true; WCHAR logfilename_w[MAX_PATH]; if ( SUCCEEDED( SHGetFolderPathW( NULL, CSIDL_APPDATA, NULL, 0, logfilename_w ) ) ) { { // handle unicode (e.g., for unicode user accounts) int shortpath_length_w = GetShortPathNameW(logfilename_w,0,0); LPWSTR shortpath_w = new WCHAR[shortpath_length_w]; GetShortPathNameW(logfilename_w,shortpath_w,shortpath_length_w); int shortpath_length = WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortpath_w, shortpath_length_w, 0, 0, 0, 0); WideCharToMultiByte(CP_OEMCP, WC_NO_BEST_FIT_CHARS, shortpath_w, shortpath_length_w, logfilename, MAX_PATH, 0, 0); delete [] shortpath_w; } PathAppendA(logfilename, application_name); if( access(logfilename, 0) != 0 ) { // folder doesn't seem to exist - try creating it int res = mkdir(logfilename); //int res = 1; // test if( res != 0 ) { printf("Failed to create folder for application data!\n"); MessageBoxA(NULL, "Failed to create folder for application data - storing in local folder instead.\n", "Warning", MB_OK|MB_ICONEXCLAMATION); ok = false; } } } else { printf("Failed to obtain path for application folder!\n"); MessageBoxA(NULL, "Failed to obtain path for application folder - storing in local folder instead.\n", "Warning", MB_OK|MB_ICONEXCLAMATION); ok = false; } if( ok ) { strcpy(application_path, logfilename); strcpy(oldlogfilename, logfilename); PathAppendA(logfilename, "log.txt"); PathAppendA(oldlogfilename, "log_old.txt"); } else { // just save in local directory and hope for the best! strcpy(application_path, ""); strcpy(logfilename, "log.txt"); strcpy(oldlogfilename, "log_old.txt"); } #elif defined(__ANDROID__) // create the folder if it doesn't already exist bool ok = true; if( access(application_path, 0) != 0 ) { __android_log_print(ANDROID_LOG_INFO, "Gigalomania", "try to create data folder"); int res = mkdir(application_path, S_IRWXU | S_IRWXG | S_IRWXO); if( res != 0 ) { __android_log_print(ANDROID_LOG_INFO, "Gigalomania", "failed to create data folder"); ok = false; } } if( ok ) { logfilename = getApplicationFilename("log.txt"); oldlogfilename = getApplicationFilename("log_old.txt"); } else { // just save in local directory and hope for the best! strcpy(application_path, ""); logfilename = getApplicationFilename("log.txt"); oldlogfilename = getApplicationFilename("log_old.txt"); } #elif __linux char *homedir = getenv("HOME"); //const char *subdir = "/.gigalomania"; const char *subdir = "/.config/gigalomania"; int len = strlen(homedir) + strlen(subdir); application_path = new char[len+1]; sprintf(application_path, "%s%s", homedir, subdir); // create the folder if it doesn't already exist bool ok = true; if( access(application_path, 0) != 0 ) { int res = mkdir(application_path, S_IRWXU | S_IRWXG | S_IRWXO); if( res != 0 ) { ok = false; } } if( ok ) { logfilename = getApplicationFilename("log.txt"); oldlogfilename = getApplicationFilename("log_old.txt"); } else { // just save in local directory and hope for the best! strcpy(application_path, ""); logfilename = getApplicationFilename("log.txt"); oldlogfilename = getApplicationFilename("log_old.txt"); } #else // no need to do anything #endif remove(oldlogfilename); rename(logfilename, oldlogfilename); remove(logfilename); LOG("Initialising Log File...\n"); LOG("Version %d.%d\n", majorVersion, minorVersion); #ifdef _DEBUG LOG("Running in Debug mode\n"); #else LOG("Running in Release mode\n"); #endif #if defined(_WIN32) LOG("Platform: Windows\n"); #elif defined(__ANDROID__) // must be before __linux, as Android also defines __linux LOG("Platform: Android\n"); #elif __linux LOG("Platform: Linux\n"); #elif defined(__APPLE__) && defined(__MACH__) LOG("Platform: MacOS X\n"); #elif __amigaos4__ // must be before AROS, as the AmigaOS 4 makefile defines AROS too LOG("Platform: AmigaOS 4\n"); #elif AROS LOG("Platform: AROS\n"); #elif defined(__MORPHOS__) LOG("Platform: MorphOS\n"); #else LOG("Platform: UNKNOWN\n"); #endif LOG("Application path: %s\n", application_path); LOG("logfilename: %s\n", logfilename); LOG("oldlogfilename: %s\n", oldlogfilename); }