Skip to content

Commit

Permalink
GetPathOfFileInAppDir() => GetPathOfFileInAppDirTemp()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Oct 23, 2023
1 parent 8a832e7 commit 0de5672
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/AppTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ TempStr AppGenDataFilenameTemp(const char* fileName) {

if (IsRunningInPortableMode()) {
/* Use the same path as the binary */
AutoFreeStr res = path::GetPathOfFileInAppDir(fileName);
return str::DupTemp(res);
return path::GetPathOfFileInAppDirTemp(fileName);
}

char* path = GetSpecialFolderTemp(CSIDL_LOCAL_APPDATA, true);
Expand Down
2 changes: 1 addition & 1 deletion src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void InitializePolicies(bool restrict) {
// allow to restrict SumatraPDF's functionality from an INI file in the
// same directory as SumatraPDF.exe (see ../docs/sumatrapdfrestrict.ini)
// (if the file isn't there, everything is allowed)
AutoFreeStr restrictPath(path::GetPathOfFileInAppDir(kRestrictionsFileName));
TempStr restrictPath = path::GetPathOfFileInAppDirTemp(kRestrictionsFileName);
if (!file::Exists(restrictPath)) {
gPolicyRestrictions = Perm::All;
Split(gAllowedLinkProtocols, DEFAULT_LINK_PROTOCOLS, ",");
Expand Down
2 changes: 1 addition & 1 deletion src/ifilter/SearchFilterDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {

STDAPI DllRegisterServer() {
log("DllRegisterServer\n");
AutoFreeStr dllPath = path::GetPathOfFileInAppDir((const char*)nullptr);
TempStr dllPath = path::GetPathOfFileInAppDirTemp((const char*)nullptr);
if (!dllPath) {
return HRESULT_FROM_WIN32(GetLastError());
}
Expand Down
4 changes: 2 additions & 2 deletions src/previewer/PdfPreviewDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
}

STDAPI DllRegisterServer() {
AutoFreeStr dllPath = path::GetPathOfFileInAppDir((const char*)nullptr);
TempStr dllPath = path::GetPathOfFileInAppDirTemp((const char*)nullptr);
if (!dllPath) {
return HRESULT_FROM_WIN32(GetLastError());
}
logf("DllRegisterServer: dllPath=%s\n", dllPath.Get());
logf("DllRegisterServer: dllPath=%s\n", dllPath);

// for compat with SumatraPDF 3.3 and lower
// in 3.4 we call this code from the installer
Expand Down
5 changes: 3 additions & 2 deletions src/tools/plugin-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ LRESULT CALLBACK PluginParentWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)

WCHAR* GetSumatraExePath() {
// run SumatraPDF.exe either from plugin-test.exe's or the current directory
char* path = path::GetPathOfFileInAppDir("SumatraPDF.exe");
if (!file::Exists(path))
TempStr path = path::GetPathOfFileInAppDirTemp("SumatraPDF.exe");
if (!file::Exists(path)) {
return str::Dup(L"SumatraPDF.exe");
}
return ToWstr(path);
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,18 @@ char* GetTempFilePath(const char* filePrefix) {
// returns a path to the application module's directory
// with either the given fileName or the module's name
// (module is the EXE or DLL in which path::GetPathOfFileInAppDir resides)
char* GetPathOfFileInAppDir(const char* fileName) {
TempStr GetPathOfFileInAppDirTemp(const char* fileName) {
WCHAR modulePath[MAX_PATH]{};
GetModuleFileNameW(GetInstance(), modulePath, dimof(modulePath));
modulePath[dimof(modulePath) - 1] = '\0';
if (!fileName) {
return ToUtf8(modulePath);
return ToUtf8Temp(modulePath);
}
WCHAR* moduleDir = path::GetDirTemp(modulePath);
WCHAR* fileNameW = ToWStrTemp(fileName);
WCHAR* path = path::JoinTemp(moduleDir, fileNameW);
path = path::Normalize(path);
char* res = ToUtf8(path);
TempStr res = ToUtf8Temp(path);
str::Free(path);
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool IsAbsolute(const char* path);
bool Match(const char* path, const char* filter);

char* GetTempFilePath(const char* filePrefix = nullptr);
char* GetPathOfFileInAppDir(const char* fileName = nullptr);
TempStr GetPathOfFileInAppDirTemp(const char* fileName = nullptr);
} // namespace path

namespace file {
Expand Down

0 comments on commit 0de5672

Please sign in to comment.