@@ -57,7 +57,6 @@ namespace luapack
57
57
static IFileSystem *filesystem = nullptr ;
58
58
59
59
static std::unordered_set<std::string> whitelist_extensions = { " lua" , " txt" , " dat" };
60
- static std::unordered_set<std::string> whitelist_pathid = { " lsv" , " lua" , " data" };
61
60
62
61
class GModDataPackProxy : public Detouring ::ClassProxy<GModDataPack, GModDataPackProxy>
63
62
{
@@ -126,30 +125,20 @@ static bool IsPathAllowed( std::string &filename )
126
125
return whitelist_extensions.find ( ext ) != whitelist_extensions.end ( );
127
126
}
128
127
129
- inline bool IsPathIDAllowed ( std::string &pathid )
130
- {
131
- std::transform ( pathid.begin ( ), pathid.end ( ), pathid.begin ( ), [] ( uint8_t c )
132
- {
133
- return static_cast <char >( std::tolower ( c ) );
134
- } );
135
- return whitelist_pathid.find ( pathid ) != whitelist_pathid.end ( );
136
- }
137
-
138
128
LUA_FUNCTION_STATIC ( Rename )
139
129
{
140
130
LUA->CheckType ( 1 , GarrysMod::Lua::Type::STRING );
141
131
LUA->CheckType ( 2 , GarrysMod::Lua::Type::STRING );
142
- LUA->CheckType ( 3 , GarrysMod::Lua::Type::STRING );
143
132
144
- std::string fname = LUA->GetString ( 1 ), fnew = LUA->GetString ( 2 ), pathid = LUA-> GetString ( 3 ) ;
133
+ std::string fname = LUA->GetString ( 1 ), fnew = LUA->GetString ( 2 );
145
134
146
- if ( !IsPathAllowed ( fname ) || !IsPathAllowed ( fnew ) || ! IsPathIDAllowed ( pathid ) )
135
+ if ( !IsPathAllowed ( fname ) || !IsPathAllowed ( fnew ) )
147
136
{
148
137
LUA->PushBool ( false );
149
138
return 1 ;
150
139
}
151
140
152
- LUA->PushBool ( filesystem->RenameFile ( fname.c_str ( ), fnew.c_str ( ), pathid. c_str ( ) ) );
141
+ LUA->PushBool ( filesystem->RenameFile ( fname.c_str ( ), fnew.c_str ( ), " DATA " ) );
153
142
return 1 ;
154
143
}
155
144
@@ -159,13 +148,41 @@ static void Initialize( GarrysMod::Lua::ILuaBase *LUA )
159
148
if ( filesystem == nullptr )
160
149
LUA->ThrowError ( " failed to initialize IFileSystem" );
161
150
151
+ if ( filesystem->FileExists ( " lua/includes/init.lua" , " MOD" ) )
152
+ {
153
+ if ( filesystem->FileExists ( " lua/includes/_init.lua" , " MOD" ) )
154
+ {
155
+ Msg ( " [gmsv_luapack_internal] 'lua/includes/_init.lua' already exists, deleting it!\n " );
156
+ filesystem->RemoveFile ( " lua/includes/_init.lua" , " MOD" );
157
+ }
158
+
159
+ if ( filesystem->RenameFile ( " lua/includes/init.lua" , " lua/includes/_init.lua" , " MOD" ) )
160
+ Msg ( " [gmsv_luapack_internal] Renamed 'lua/includes/init.lua' to 'lua/includes/_init.lua'!\n " );
161
+ else
162
+ Warning ( " [gmsv_luapack_internal] Failed to rename 'lua/includes/init.lua' to 'lua/includes/_init.lua'!\n " );
163
+ }
164
+
165
+ if ( filesystem->FileExists ( " lua/send.txt" , " MOD" ) )
166
+ {
167
+ if ( filesystem->FileExists ( " lua/_send.txt" , " MOD" ) )
168
+ {
169
+ Msg ( " [gmsv_luapack_internal] 'lua/_send.txt' already exists, deleting it!\n " );
170
+ filesystem->RemoveFile ( " lua/_send.txt" , " MOD" );
171
+ }
172
+
173
+ if ( filesystem->RenameFile ( " lua/send.txt" , " lua/_send.txt" , " MOD" ) )
174
+ Msg ( " [gmsv_luapack_internal] Renamed 'lua/send.txt' to 'lua/_send.txt'!\n " );
175
+ else
176
+ Warning ( " [gmsv_luapack_internal] Failed to rename 'lua/send.txt' to 'lua/_send.txt'!\n " );
177
+ }
178
+
162
179
GModDataPackProxy::Singleton.Initialize ( LUA );
163
180
164
181
LUA->GetField ( GarrysMod::Lua::INDEX_GLOBAL, " luapack" );
165
182
if ( !LUA->IsType ( -1 , GarrysMod::Lua::Type::TABLE ) )
166
183
{
167
- GModDataPackProxy::Singleton.Deinitialize (LUA);
168
- LUA->ThrowError (" luapack table not found" );
184
+ GModDataPackProxy::Singleton.Deinitialize ( LUA );
185
+ LUA->ThrowError ( " luapack table not found" );
169
186
}
170
187
171
188
LUA->PushCFunction ( Rename );
0 commit comments