Skip to content

Commit 82f333f

Browse files
qaisjpcolistro123
andcommitted
Use std::filesystem
Co-authored-by: colistro123 <colistro123@aol.com>
1 parent 0a4859c commit 82f333f

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

amx-deps/src/CFunctions.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
*********************************************************/
1818

1919
#include "StdInc.h"
20+
#include <filesystem>
2021

2122
using namespace std;
22-
using namespace boost::filesystem;
23+
namespace fs = std::filesystem;
2324

2425
extern ILuaModuleManager10 *pModuleManager;
2526

@@ -104,11 +105,14 @@ int CFunctions::amxLoad(lua_State *luaVM) {
104105
return 1;
105106
}
106107

107-
path amxPath = path("mods/deathmatch/resources/[gamemodes]/[amx]/") / resName / amxName;
108+
char buff[256];
109+
snprintf(buff, sizeof(buff), "%s/mods/deathmatch/resources/[gamemodes]/[amx]/%s/%s", fs::current_path().string().c_str(), resName, amxName);
110+
fs::path amxPath = buff;
111+
amxPath = fs::canonical(amxPath);
108112

109113
// Load .amx
110114
AMX *amx = new AMX;
111-
int err = aux_LoadProgram(amx, amxPath.string().c_str(), NULL);
115+
int err = aux_LoadProgram(amx, buff, NULL);
112116
if(err != AMX_ERR_NONE) {
113117
delete amx;
114118
lua_pushboolean(luaVM, 0);
@@ -145,7 +149,7 @@ int CFunctions::amxLoad(lua_State *luaVM) {
145149

146150
// Save info about the amx
147151
AMXPROPS props;
148-
props.filePath = amxPath;
152+
props.filePath = amxPath.string();
149153
props.resourceName = resName;
150154
props.resourceVM = pModuleManager->GetResourceFromName(resName);
151155

amx-deps/src/StdInc.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <dlfcn.h>
99
#endif
1010

11-
#include <boost/filesystem.hpp>
12-
1311
#include <stdio.h>
1412
#include <cstdarg>
1513
#include <cstring>
@@ -45,4 +43,4 @@ extern "C"
4543
#include "util.h"
4644
#include "CFunctions.h"
4745

48-
#endif
46+
#endif

amx-deps/src/ml_base.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include "StdInc.h"
2020

21+
#include <locale.h>
22+
2123
using namespace std;
2224

2325
ILuaModuleManager10 *pModuleManager = NULL;

amx-deps/src/ml_base.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
*
55
* ml_base, External lua add-on module
66
*
7-
* Copyright © 2003-2008 MTA. All Rights Reserved.
7+
* Copyright © 2003-2008 MTA. All Rights Reserved.
88
*
9-
* Grand Theft Auto is © 2002-2003 Rockstar North
9+
* Grand Theft Auto is © 2002-2003 Rockstar North
1010
*
1111
* THE FOLLOWING SOURCES ARE PART OF THE MULTI THEFT
1212
* AUTO SOFTWARE DEVELOPMENT KIT AND ARE RELEASED AS
@@ -31,7 +31,7 @@ int AMXCallPublicFilterScript(char *fnName);
3131
int AMXCallPublicGameMode(char *fnName);
3232

3333
typedef struct {
34-
boost::filesystem::path filePath;
34+
std::string filePath;
3535
std::string resourceName;
3636
lua_State *resourceVM;
3737
} AMXPROPS;

amx-deps/src/util.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#include "StdInc.h"
22
#include "UTF8.h"
33
#include <cstdlib>
4+
#include <filesystem>
45

56
using namespace std;
6-
using namespace boost::filesystem;
7+
namespace fs = std::filesystem;
78

89
extern map < AMX *, AMXPROPS > loadedAMXs;
910

@@ -198,22 +199,22 @@ string getScriptFilePath(AMX *amx, const char *filename) {
198199
return string();
199200

200201
// First check if it exists in the resource folder
201-
path respath = loadedAMXs[amx].filePath;
202-
respath = respath.remove_leaf() / filename;
202+
fs::path respath = loadedAMXs[amx].filePath;
203+
respath = respath.remove_filename() / filename;
203204
if(exists(respath))
204205
return respath.string();
205206

206207
// Then check if it exists in the main scriptfiles folder
207-
path scriptfilespath = path("mods/deathmatch/resources/amx/scriptfiles") / filename;
208+
fs::path scriptfilespath = fs::path("mods/deathmatch/resources/amx/scriptfiles") / filename;
208209
if(exists(scriptfilespath))
209210
{
210211
return scriptfilespath.string();
211212
}
212213

213214
// Otherwise default to amx's resource folder - make sure the folder
214215
// where the file is expected exists
215-
path folder = respath;
216-
folder.remove_leaf();
216+
fs::path folder = respath;
217+
folder.remove_filename();
217218
create_directories(folder);
218219
return respath.string();
219220
}

0 commit comments

Comments
 (0)