Skip to content

Commit b20f124

Browse files
committed
refactor: abstract filesystem operations with NativeFileSystem and increment build version
1 parent 57e92f9 commit b20f124

7 files changed

Lines changed: 33 additions & 14 deletions

File tree

Core/GameEngine/Source/Common/System/XferLoad.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#include "Common/GameState.h"
3434
#include "Common/Snapshot.h"
3535
#include "Common/XferLoad.h"
36+
#ifdef __APPLE__
37+
#include "Common/System/NativeFileSystem.h"
38+
#endif
3639

3740
//-------------------------------------------------------------------------------------------------
3841
//-------------------------------------------------------------------------------------------------
@@ -80,7 +83,11 @@ void XferLoad::open( AsciiString identifier )
8083
Xfer::open( identifier );
8184

8285
// open the file
86+
#ifdef __APPLE__
87+
m_fileFP = NativeFileSystem::fopen( identifier.str(), "rb" );
88+
#else
8389
m_fileFP = fopen( identifier.str(), "rb" );
90+
#endif
8491
if( m_fileFP == nullptr )
8592
{
8693

Core/GameEngine/Source/Common/System/XferSave.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
#include "Common/XferSave.h"
3333
#include "Common/Snapshot.h"
3434
#include "Common/GameMemory.h"
35+
#ifdef __APPLE__
36+
#include "Common/System/NativeFileSystem.h"
37+
#endif
3538

3639
// PRIVATE TYPES //////////////////////////////////////////////////////////////////////////////////
3740
class XferBlockData : public MemoryPoolObject
@@ -120,7 +123,11 @@ void XferSave::open( AsciiString identifier )
120123
Xfer::open( identifier );
121124

122125
// open the file
126+
#ifdef __APPLE__
127+
m_fileFP = NativeFileSystem::fopen( identifier.str(), "w+b" );
128+
#else
123129
m_fileFP = fopen( identifier.str(), "w+b" );
130+
#endif
124131
if( m_fileFP == nullptr )
125132
{
126133

GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameState.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
3131
#include "PreRTS.h"
3232
#include <filesystem>
33+
#include "Common/System/NativeFileSystem.h"
3334
#ifndef __APPLE__
3435
#include <io.h>
3536
#else
@@ -477,7 +478,7 @@ AsciiString GameState::findNextSaveFilename( UnicodeString desc )
477478
leaf.format("%s_%04d%s", adesc.str(), i, SAVE_GAME_EXTENSION);
478479

479480
AsciiString path = getFilePathInSaveDirectory(leaf);
480-
if( _access( path.str(), 0 ) == -1 )
481+
if( !NativeFileSystem::exists(path.str()) )
481482
return leaf; // note that this returns the leaf, not the full path
482483
}
483484
#else
@@ -524,7 +525,7 @@ AsciiString GameState::findNextSaveFilename( UnicodeString desc )
524525
fullPath = getFilePathInSaveDirectory(filename);
525526

526527
// if file does not exist we're all good
527-
if( _access( fullPath.str(), 0 ) == -1 )
528+
if( !NativeFileSystem::exists(fullPath.str()) )
528529
return filename;
529530

530531
// test the text filename
@@ -571,7 +572,7 @@ SaveCode GameState::saveGame( AsciiString filename, UnicodeString desc,
571572
}
572573

573574
// make absolutely sure the save directory exists
574-
CreateDirectory( getSaveDirectory().str(), nullptr );
575+
NativeFileSystem::create_directory( std::string(getSaveDirectory().str()) );
575576

576577
// construct path to file
577578
AsciiString filepath = getFilePathInSaveDirectory(filename);
@@ -1019,7 +1020,8 @@ void GameState::getSaveGameInfoFromFile( AsciiString filename, SaveGameInfo *sav
10191020

10201021
// open file for partial loading
10211022
XferLoad xferLoad;
1022-
xferLoad.open( filename );
1023+
AsciiString filepath = getFilePathInSaveDirectory(filename);
1024+
xferLoad.open( filepath );
10231025

10241026
//
10251027
// disable post processing cause we're not really doing a load of game data that
@@ -1349,7 +1351,8 @@ void GameState::iterateSaveFiles( IterateSaveFileCallback callback, void *userDa
13491351
#else
13501352
try
13511353
{
1352-
for (const auto& entry : std::filesystem::directory_iterator(getSaveDirectory().str()))
1354+
std::string safeSaveDir = NativeFileSystem::get_safe_path(getSaveDirectory().str());
1355+
for (const auto& entry : std::filesystem::directory_iterator(safeSaveDir))
13531356
{
13541357
if (entry.is_regular_file())
13551358
{

GeneralsMD/Code/GameEngine/Source/Common/System/SaveGame/GameStateMap.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "GameClient/MapUtil.h"
4242
#include "GameLogic/GameLogic.h"
4343
#include "GameNetwork/GameInfo.h"
44+
#include "Common/System/NativeFileSystem.h"
4445
#include <filesystem>
4546

4647
// GLOBALS ////////////////////////////////////////////////////////////////////////////////////////
@@ -130,7 +131,7 @@ static void embedPristineMap( AsciiString map, Xfer *xfer )
130131
// ------------------------------------------------------------------------------------------------
131132
static void embedInUseMap( AsciiString map, Xfer *xfer )
132133
{
133-
FILE *fp = fopen( map.str(), "rb" );
134+
FILE *fp = NativeFileSystem::fopen( map.str(), "rb" );
134135

135136
// sanity
136137
if( fp == nullptr )
@@ -188,7 +189,7 @@ static void extractAndSaveMap( AsciiString mapToSave, Xfer *xfer )
188189
UnsignedInt dataSize;
189190

190191
// open handle to output file
191-
FILE *fp = fopen( mapToSave.str(), "w+b" );
192+
FILE *fp = NativeFileSystem::fopen( mapToSave.str(), "w+b" );
192193
if( fp == nullptr )
193194
{
194195

@@ -520,18 +521,18 @@ void GameStateMap::clearScratchPadMaps()
520521
#else
521522
try
522523
{
523-
for (const auto& entry : std::filesystem::directory_iterator(TheGameState->getSaveDirectory().str()))
524+
std::string safeSaveDir = NativeFileSystem::get_safe_path(TheGameState->getSaveDirectory().str());
525+
for (const auto& entry : std::filesystem::directory_iterator(safeSaveDir))
524526
{
525527
if (entry.is_regular_file())
526528
{
527529
std::string path = entry.path().string();
528530
if (path.length() >= 4)
529531
{
530532
std::string ext = path.substr(path.length() - 4);
531-
// lowercase ext manually or just check for .map
532533
if (ext == ".map" || ext == ".MAP")
533534
{
534-
std::filesystem::remove(entry.path());
535+
NativeFileSystem::remove(path);
535536
}
536537
}
537538
}

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/PopupSaveLoad.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "GameClient/Shell.h"
6060
#include "GameLogic/GameLogic.h"
6161
#include "GameClient/GameWindowTransitions.h"
62+
#include "Common/System/NativeFileSystem.h"
6263

6364
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
6465
static NameKeyType buttonBackKey = NAMEKEY_INVALID;
@@ -715,7 +716,7 @@ WindowMsgHandledType SaveLoadMenuSystem( GameWindow *window, UnsignedInt msg,
715716
AsciiString filepath = TheGameState->getFilePathInSaveDirectory(selectedGameInfo->filename);
716717

717718
// delete the file
718-
DeleteFile( filepath.str() );
719+
NativeFileSystem::remove( filepath.str() );
719720

720721
// repopulate the listbox
721722
TheGameState->populateSaveGameListbox( listboxGames, currentLayoutType );

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ WindowMsgHandledType ScoreScreenSystem( GameWindow *window, UnsignedInt msg,
654654
}
655655
else
656656
{
657-
657+
startNextCampaignGame();
658658
}
659659
}
660660
else if (screenType == SCORESCREEN_INTERNET)

Platform/MacOS/Launcher/assemble_distribution.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
# - dylibbundler (brew install dylibbundler)
1515
# - create-dmg (brew install create-dmg) — optional, for premium DMG
1616

17-
VERSION="1.2.1"
18-
BUILD="5"
17+
VERSION="1.2.2"
18+
BUILD="6"
1919

2020
LAUNCHER_NAME="GeneralsLauncher"
2121
FINAL_APP_NAME="Generals Online"

0 commit comments

Comments
 (0)