@@ -4998,11 +4998,12 @@ bool MultiReplace::resolveLuaSyntax(std::string& inputString, const LuaVariables
4998
4998
int MultiReplace::safeLoadFileSandbox (lua_State* L) {
4999
4999
// Return signature: (bool success, table or errorMessage)
5000
5000
5001
- // 1) Get the file path argument
5001
+ // Get the file path argument
5002
5002
const char * path = luaL_checkstring (L, 1 );
5003
5003
5004
- // 2) Read raw bytes from disk
5005
- std::ifstream in (path, std::ios::binary);
5004
+ // UTF-8 → Wide → filesystem::path → ifstream
5005
+ std::wstring wpath = Encoding::utf8ToWString (path);
5006
+ std::ifstream in (std::filesystem::path (wpath), std::ios::binary);
5006
5007
if (!in) {
5007
5008
lua_pushboolean (L, false );
5008
5009
lua_pushfstring (L, " Cannot open file: %s" , path);
@@ -5012,10 +5013,10 @@ int MultiReplace::safeLoadFileSandbox(lua_State* L) {
5012
5013
std::istreambuf_iterator<char >());
5013
5014
in.close ();
5014
5015
5015
- // 3) Detect UTF-8 vs ANSI
5016
+ // Detect UTF-8 vs ANSI
5016
5017
bool rawIsUtf8 = Encoding::isValidUtf8 (raw);
5017
5018
5018
- // 4) Convert to a true UTF-8 buffer if needed
5019
+ // Convert to a true UTF-8 buffer if needed
5019
5020
std::string utf8_buf;
5020
5021
if (rawIsUtf8) {
5021
5022
utf8_buf = std::move (raw);
@@ -5032,7 +5033,7 @@ int MultiReplace::safeLoadFileSandbox(lua_State* L) {
5032
5033
WideCharToMultiByte (CP_UTF8, 0 , wide.data (), wlen, &utf8_buf[0 ], u8len, nullptr , nullptr );
5033
5034
}
5034
5035
5035
- // 5) Strip UTF-8 BOM if present
5036
+ // Strip UTF-8 BOM if present
5036
5037
if (utf8_buf.size () >= 3 &&
5037
5038
static_cast <unsigned char >(utf8_buf[0 ]) == 0xEF &&
5038
5039
static_cast <unsigned char >(utf8_buf[1 ]) == 0xBB &&
@@ -5041,22 +5042,22 @@ int MultiReplace::safeLoadFileSandbox(lua_State* L) {
5041
5042
utf8_buf.erase (0 , 3 );
5042
5043
}
5043
5044
5044
- // 6) Load the UTF-8 chunk into Lua
5045
+ // Load the UTF-8 chunk into Lua
5045
5046
if (luaL_loadbuffer (L, utf8_buf.data (), utf8_buf.size (), path) != LUA_OK) {
5046
5047
lua_pushboolean (L, false );
5047
5048
lua_pushstring (L, lua_tostring (L, -1 )); // error message
5048
5049
return 2 ;
5049
5050
}
5050
5051
5051
- // 7) Run the chunk: expect it to return a table of entries
5052
+ // Run the chunk: expect it to return a table of entries
5052
5053
if (lua_pcall (L, 0 , 1 , 0 ) != LUA_OK) {
5053
5054
lua_pushboolean (L, false );
5054
5055
lua_pushstring (L, lua_tostring (L, -1 ));
5055
5056
return 2 ;
5056
5057
}
5057
5058
// Stack now: [ table ]
5058
5059
5059
- // 8) Prepend a 'true' for the success flag
5060
+ // Prepend a 'true' for the success flag
5060
5061
lua_pushboolean (L, true );
5061
5062
lua_insert (L, -2 ); // now stack: [ true, table ]
5062
5063
@@ -9367,7 +9368,7 @@ std::wstring MultiReplace::promptSaveListToCsv() {
9367
9368
}
9368
9369
9369
9370
bool MultiReplace::saveListToCsvSilent (const std::wstring& filePath, const std::vector<ReplaceItemData>& list) {
9370
- std::ofstream outFile (filePath, std::ios::binary);
9371
+ std::ofstream outFile (std::filesystem::path ( filePath) , std::ios::binary);
9371
9372
9372
9373
if (!outFile.is_open ()) {
9373
9374
return false ;
@@ -9377,7 +9378,7 @@ bool MultiReplace::saveListToCsvSilent(const std::wstring& filePath, const std::
9377
9378
outFile.write (" \xEF\xBB\xBF " , 3 );
9378
9379
9379
9380
// Convert and Write CSV header
9380
- std::string utf8Header = Encoding::wstringToUtf8 (L" Selected,Find,Replace,WholeWord,MatchCase,UseVariables,Regex, Extended,Comments\n " );
9381
+ std::string utf8Header = Encoding::wstringToUtf8 (L" Selected,Find,Replace,WholeWord,MatchCase,UseVariables,Extended,Regex ,Comments\n " );
9381
9382
outFile << utf8Header;
9382
9383
9383
9384
// Write list items to CSV file
@@ -9470,7 +9471,7 @@ int MultiReplace::checkForUnsavedChanges() {
9470
9471
9471
9472
void MultiReplace::loadListFromCsvSilent (const std::wstring& filePath, std::vector<ReplaceItemData>& list) {
9472
9473
// Open the CSV file
9473
- std::ifstream inFile (filePath, std::ios::binary);
9474
+ std::ifstream inFile (std::filesystem::path ( filePath) , std::ios::binary);
9474
9475
if (!inFile.is_open ()) {
9475
9476
std::wstring shortenedFilePathW = getShortenedFilePath (filePath, 500 );
9476
9477
throw CsvLoadException (Encoding::wstringToUtf8 (LM.get (L" status_unable_to_open_file" , { shortenedFilePathW })));
0 commit comments