win32.c
changeset 2099 22f535ad9eea
parent 2091 97197b795fe6
child 2125 3098398bf7ff
equal deleted inserted replaced
2098:b17a44f55b6d 2099:22f535ad9eea
  1577 	int r;
  1577 	int r;
  1578 
  1578 
  1579 	if (_savegame_sort_order < 2) // sort by date
  1579 	if (_savegame_sort_order < 2) // sort by date
  1580 		r = da->mtime < db->mtime ? -1 : 1;
  1580 		r = da->mtime < db->mtime ? -1 : 1;
  1581 	else
  1581 	else
  1582 		r = strcasecmp(
  1582 		r = strcasecmp(da->title, db->title);
  1583 			da->title[0] != '\0' ? da->title : da->name,
       
  1584 			db->title[0] != '\0' ? db->title : db->name
       
  1585 		);
       
  1586 
  1583 
  1587 	if (_savegame_sort_order & 1) r = -r;
  1584 	if (_savegame_sort_order & 1) r = -r;
  1588 	return r;
  1585 	return r;
  1589 }
  1586 }
  1590 
  1587 
  1600 	if (_fios_save_path == NULL) {
  1597 	if (_fios_save_path == NULL) {
  1601 		_fios_save_path = malloc(MAX_PATH);
  1598 		_fios_save_path = malloc(MAX_PATH);
  1602 		strcpy(_fios_save_path, _path.save_dir);
  1599 		strcpy(_fios_save_path, _path.save_dir);
  1603 	}
  1600 	}
  1604 
  1601 
  1605 	if (_game_mode == GM_EDITOR)
  1602 	_fios_path = _fios_save_path;
  1606 		_fios_path = _fios_scn_path;
       
  1607 	else
       
  1608 		_fios_path = _fios_save_path;
       
  1609 
  1603 
  1610 	// Parent directory, only if not of the type C:\.
  1604 	// Parent directory, only if not of the type C:\.
  1611 	if (_fios_path[3] != '\0') {
  1605 	if (_fios_path[3] != '\0') {
  1612 		fios = FiosAlloc();
  1606 		fios = FiosAlloc();
  1613 		fios->type = FIOS_TYPE_PARENT;
  1607 		fios->type = FIOS_TYPE_PARENT;
  1625 					strcmp(fd.cFileName, "..") != 0) {
  1619 					strcmp(fd.cFileName, "..") != 0) {
  1626 				fios = FiosAlloc();
  1620 				fios = FiosAlloc();
  1627 				fios->type = FIOS_TYPE_DIR;
  1621 				fios->type = FIOS_TYPE_DIR;
  1628 				fios->mtime = 0;
  1622 				fios->mtime = 0;
  1629 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
  1623 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
  1630 				snprintf(fios->title, lengthof(fios->title),
  1624 				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName);
  1631 					"%s\\ (Directory)", fd.cFileName);
       
  1632 			}
  1625 			}
  1633 		} while (FindNextFile(h, &fd));
  1626 		} while (FindNextFile(h, &fd));
  1634 		FindClose(h);
  1627 		FindClose(h);
  1635 	}
  1628 	}
  1636 
  1629 
  1653 			t = strrchr(fd.cFileName, '.');
  1646 			t = strrchr(fd.cFileName, '.');
  1654 			if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD
  1647 			if (t != NULL && strcasecmp(t, ".sav") == 0) { // OpenTTD
  1655 				fios = FiosAlloc();
  1648 				fios = FiosAlloc();
  1656 				fios->type = FIOS_TYPE_FILE;
  1649 				fios->type = FIOS_TYPE_FILE;
  1657 				fios->mtime = *(uint64*)&fd.ftLastWriteTime;
  1650 				fios->mtime = *(uint64*)&fd.ftLastWriteTime;
  1658 				fios->title[0] = '\0';
       
  1659 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
  1651 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
       
  1652 
       
  1653 				*t = '\0'; // strip extension
       
  1654 				ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title));
       
  1655 
  1660 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
  1656 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
  1661 				if (t != NULL && (
  1657 				if (t != NULL && (
  1662 							strcasecmp(t, ".ss1") == 0 ||
  1658 							strcasecmp(t, ".ss1") == 0 ||
  1663 							strcasecmp(t, ".sv1") == 0 ||
  1659 							strcasecmp(t, ".sv1") == 0 ||
  1664 							strcasecmp(t, ".sv2") == 0
  1660 							strcasecmp(t, ".sv2") == 0
  1704 	FiosItem *fios;
  1700 	FiosItem *fios;
  1705 	WIN32_FIND_DATA fd;
  1701 	WIN32_FIND_DATA fd;
  1706 	HANDLE h;
  1702 	HANDLE h;
  1707 	int sort_start;
  1703 	int sort_start;
  1708 
  1704 
  1709 	if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) {
  1705 	if (_fios_scn_path == NULL) {
  1710 		if (_fios_scn_path == NULL)
  1706 		_fios_scn_path = malloc(MAX_PATH);
  1711 			_fios_scn_path = malloc(MAX_PATH);
       
  1712 		strcpy(_fios_scn_path, _path.scenario_dir);
  1707 		strcpy(_fios_scn_path, _path.scenario_dir);
  1713 	}
  1708 	}
  1714 
  1709 
  1715 	_fios_path = _fios_scn_path;
  1710 	_fios_path = _fios_scn_path;
  1716 
  1711 
  1731 					strcmp(fd.cFileName, "..") != 0) {
  1726 					strcmp(fd.cFileName, "..") != 0) {
  1732 				fios = FiosAlloc();
  1727 				fios = FiosAlloc();
  1733 				fios->type = FIOS_TYPE_DIR;
  1728 				fios->type = FIOS_TYPE_DIR;
  1734 				fios->mtime = 0;
  1729 				fios->mtime = 0;
  1735 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
  1730 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
  1736 				snprintf(fios->title, lengthof(fios->title),
  1731 				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName);
  1737 					"%s\\ (Directory)", fd.cFileName);
       
  1738 			}
  1732 			}
  1739 		} while (FindNextFile(h, &fd));
  1733 		} while (FindNextFile(h, &fd));
  1740 		FindClose(h);
  1734 		FindClose(h);
  1741 	}
  1735 	}
  1742 
  1736 
  1758 			t = strrchr(fd.cFileName, '.');
  1752 			t = strrchr(fd.cFileName, '.');
  1759 			if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD
  1753 			if (t != NULL && strcasecmp(t, ".scn") == 0) { // OpenTTD
  1760 				fios = FiosAlloc();
  1754 				fios = FiosAlloc();
  1761 				fios->type = FIOS_TYPE_SCENARIO;
  1755 				fios->type = FIOS_TYPE_SCENARIO;
  1762 				fios->mtime = *(uint64*)&fd.ftLastWriteTime;
  1756 				fios->mtime = *(uint64*)&fd.ftLastWriteTime;
  1763 				fios->title[0] = '\0';
       
  1764 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
  1757 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
       
  1758 
       
  1759 				*t  = '\0'; // strip extension
       
  1760 				ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title));
       
  1761 
  1765 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
  1762 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
  1766 					mode == SLD_NEW_GAME) {
  1763 					mode == SLD_NEW_GAME) {
  1767 				if (t != NULL && (
  1764 				if (t != NULL && (
  1768 							strcasecmp(t, ".sv0") == 0 ||
  1765 							strcasecmp(t, ".sv0") == 0 ||
  1769 							strcasecmp(t, ".ss0") == 0
  1766 							strcasecmp(t, ".ss0") == 0