[win-linux] updatesvc, online-installer: refactoring utils

This commit is contained in:
SimplestStudio
2024-09-30 07:43:55 +03:00
parent 3024dca34e
commit 90f6f8368c
3 changed files with 11 additions and 7 deletions

View File

@ -430,8 +430,8 @@ namespace NS_File
string parentPath(const string &path)
{
string::size_type delim = path.find_last_of("\\/");
return (delim == string::npos) ? "" : path.substr(0, delim);
auto delim = (path.size() > 1) ? path.find_last_of('/', path.size() - 2) : string::npos;
return (delim == string::npos) ? "" : (delim == 0) ? "/" : path.substr(0, delim);
}
string tempPath()

View File

@ -36,7 +36,7 @@
#include <Windows.h>
#include <shlwapi.h>
#include <fstream>
#include <regex>
#include <algorithm>
#include <cstdio>
//#include <Wincrypt.h>
#include <WtsApi32.h>
@ -468,17 +468,21 @@ namespace NS_File
wstring fromNativeSeparators(const wstring &path)
{
return std::regex_replace(path, std::wregex(L"\\\\"), L"/");
wstring _path(path);
std::replace(_path.begin(), _path.end(), L'\\', L'/');
return _path;
}
wstring toNativeSeparators(const wstring &path)
{
return std::regex_replace(path, std::wregex(L"\\/"), L"\\");
wstring _path(path);
std::replace(_path.begin(), _path.end(), L'/', L'\\');
return _path;
}
wstring parentPath(const wstring &path)
{
wstring::size_type delim = path.find_last_of(L"\\/");
auto delim = (path.size() > 2) ? path.find_last_of(L"\\/", path.size() - 2) : wstring::npos;
return (delim == wstring::npos) ? L"" : path.substr(0, delim);
}