Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char userpath[4096];
- char logfilename[4096];
- // OS specific (Windows)
- int FolderExists(const char * file)
- {
- DWORD returnvalue;
- WCHAR temp[512];
- MultiByteToWideChar(0, 0, file, 5, temp, 50);
- LPCWSTR widefile = temp;
- returnvalue = GetFileAttributesW(widefile);
- if (returnvalue == ((DWORD) - 1))
- return FALSE;
- else
- return TRUE;
- }
- // OS specific (Windows)
- void MakeADirectory(char * dir)
- {
- CreateDirectoryA(dir, NULL);
- /*printf("Now creating: ");
- printf(dir);
- printf("\n");*/
- return;
- }
- void InitLog()
- {
- // Find the user's profile directory
- char * tempfilename;
- FILE *fp;
- // OS Specific (Windows)
- // ---
- size_t len;
- _dupenv_s(&tempfilename, &len, "USERPROFILE");
- if (!tempfilename)
- {
- printf("Cannot find %USERPROFILE% environment variable. Now exiting.\n");
- exit(1);
- }
- // ---
- strcpy_s (logfilename, 4096, tempfilename);
- free(tempfilename);
- // Make sure the whole path to the log file exists
- strcat_s (logfilename, 4096, "\\My Documents");
- if (!FolderExists(logfilename))
- {
- // My Documents is missing!
- MakeADirectory(logfilename);
- }
- strcat_s (logfilename, 4096, "\\My Games");
- if (!FolderExists(logfilename))
- {
- // My Documents\My Games is missing!
- MakeADirectory(logfilename);
- }
- strcat_s (logfilename, 4096, "\\Dusk Software");
- if (!FolderExists(logfilename))
- {
- // My Documents\My Games\Dusk Software is missing!
- MakeADirectory(logfilename);
- }
- strcpy_s (userpath, 4096, logfilename);
- strcat_s (logfilename, 4096, "\\LOG-fydos-adventure-game.txt");
- // See if the log file exists
- fopen_s(&fp, logfilename,"r");
- if (fp)
- {
- // Log file already exists
- // TODO: Check file size of log, trim it down if it is too big!
- }
- else
- {
- // Log file doesn't exist yet
- if (fopen_s(&fp, logfilename, "a") != 0)
- {
- printf("Cannot open log file. Be sure that this game has write rights. Now exiting.\n");
- exit(1);
- }
- }
- fclose(fp);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement