win32.c
changeset 4222 951fbf19b1ad
parent 4221 bb06fe8dcce2
child 4223 0f9535dda7ed
equal deleted inserted replaced
4221:bb06fe8dcce2 4222:951fbf19b1ad
     6 #include "functions.h"
     6 #include "functions.h"
     7 #include "hal.h"
     7 #include "hal.h"
     8 #include "macros.h"
     8 #include "macros.h"
     9 #include "saveload.h"
     9 #include "saveload.h"
    10 #include "string.h"
    10 #include "string.h"
    11 #include "table/strings.h"
       
    12 #include "gfx.h"
    11 #include "gfx.h"
    13 #include "window.h"
    12 #include "window.h"
    14 #include <windows.h>
    13 #include <windows.h>
    15 #include <winnt.h>
    14 #include <winnt.h>
    16 #include <wininet.h>
    15 #include <wininet.h>
   741 	sb->st_mtime = (fd->ftLastWriteTime.dwHighDateTime * MAXDWORD+1) + fd->ftLastWriteTime.dwLowDateTime;
   740 	sb->st_mtime = (fd->ftLastWriteTime.dwHighDateTime * MAXDWORD+1) + fd->ftLastWriteTime.dwLowDateTime;
   742 	sb->st_mode  = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG;
   741 	sb->st_mode  = (fd->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)? S_IFDIR : S_IFREG;
   743 	return true;
   742 	return true;
   744 }
   743 }
   745 
   744 
   746 // Browse to
   745 bool FiosGetDiskFreeSpace(const char *path, uint32 *tot)
   747 char *FiosBrowseTo(const FiosItem *item)
       
   748 {
       
   749 	char *path = _fios_path;
       
   750 	char *s;
       
   751 
       
   752 	switch (item->type) {
       
   753 		case FIOS_TYPE_DRIVE:
       
   754 			sprintf(path, "%c:\\", item->title[0]);
       
   755 			break;
       
   756 
       
   757 		case FIOS_TYPE_PARENT:
       
   758 			s = strrchr(path, '\\');
       
   759 			if (s != path + 2) {
       
   760 				s[0] = '\0';
       
   761 			} else {
       
   762 				s[1] = '\0';
       
   763 			}
       
   764 			break;
       
   765 
       
   766 		case FIOS_TYPE_DIR:
       
   767 			if (path[3] != '\0') strcat(path, "\\");
       
   768 			strcat(path, item->name);
       
   769 			break;
       
   770 
       
   771 		case FIOS_TYPE_DIRECT:
       
   772 			sprintf(path, "%s\\", item->name);
       
   773 			s = strrchr(path, '\\');
       
   774 			if (s[1] == '\0') s[0] = '\0'; // strip trailing slash
       
   775 			break;
       
   776 
       
   777 		case FIOS_TYPE_FILE:
       
   778 		case FIOS_TYPE_OLDFILE:
       
   779 		case FIOS_TYPE_SCENARIO:
       
   780 		case FIOS_TYPE_OLD_SCENARIO: {
       
   781 			static char str_buffr[512];
       
   782 
       
   783 			sprintf(str_buffr, "%s\\%s", path, item->name);
       
   784 			return str_buffr;
       
   785 		}
       
   786 	}
       
   787 
       
   788 	return NULL;
       
   789 }
       
   790 
       
   791 /**
       
   792  * Get descriptive texts. Returns the path and free space
       
   793  * left on the device
       
   794  * @param path string describing the path
       
   795  * @param tfs total free space in megabytes, optional (can be NULL)
       
   796  * @return StringID describing the path (free space or failure)
       
   797  */
       
   798 StringID FiosGetDescText(const char **path, uint32 *tot)
       
   799 {
   746 {
   800 	UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS);  // disable 'no-disk' message box
   747 	UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS);  // disable 'no-disk' message box
       
   748 	bool retval = false;
   801 	char root[4];
   749 	char root[4];
   802 	DWORD spc, bps, nfc, tnc;
   750 	DWORD spc, bps, nfc, tnc;
   803 	StringID sid;
   751 
   804 
   752 	snprintf(root, lengthof(root), "%c:" PATHSEP, path[0]);
   805 	*path = _fios_path;
       
   806 
       
   807 	sprintf(root, "%c:\\", _fios_path[0]);
       
   808 	if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
   753 	if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
   809 		*tot = ((spc * bps) * (uint64)nfc) >> 20;
   754 		*tot = ((spc * bps) * (uint64)nfc) >> 20;
   810 		sid = STR_4005_BYTES_FREE;
   755 		retval = true;
   811 	} else {
       
   812 		sid = STR_4006_UNABLE_TO_READ_DRIVE;
       
   813 	}
   756 	}
   814 
   757 
   815 	SetErrorMode(sem); // reset previous setting
   758 	SetErrorMode(sem); // reset previous setting
   816 	return sid;
   759 	return retval;
   817 }
   760 }
   818 
   761 
   819 static int ParseCommandLine(char *line, char **argv, int max_argc)
   762 static int ParseCommandLine(char *line, char **argv, int max_argc)
   820 {
   763 {
   821 	int n = 0;
   764 	int n = 0;