Skip to content

Commit

Permalink
str::Format() => str::FormatTemp()
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Oct 23, 2023
1 parent 229d32b commit 6da70b7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/Tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ static void MobiSaveImage(const char* filePathBase, size_t imgNo, ByteSlice img)
}
const char* ext = GfxFileExtFromData(img);
CrashAlwaysIf(!ext);
char* path = str::Format("%s_img_%d%s", filePathBase, (int)imgNo, ext);
TempStr path = str::FormatTemp("%s_img_%d%s", filePathBase, (int)imgNo, ext);
file::WriteFile(path, img);
str::Free(path);
}

static void MobiSaveImages(const char* filePathBase, MobiDoc* mb) {
Expand Down
10 changes: 5 additions & 5 deletions src/Uninstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ static bool UninstallerOnWmCommand(WPARAM wp) {
#define kInstallerWindowClassName L"SUMATRA_PDF_INSTALLER_FRAME"

static void CreateUninstallerWindow() {
AutoFreeWstr title = str::Format(_TR("SumatraPDF %s Uninstaller"), CURR_VERSION_STR);
TempStr title = str::FormatTemp(_TRA("SumatraPDF %s Uninstaller"), CURR_VERSION_STRA);
int x = CW_USEDEFAULT;
int y = CW_USEDEFAULT;
int dx = GetInstallerWinDx();
int dy = kInstallerWinDy;
HMODULE h = GetModuleHandleW(nullptr);
DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_CLIPCHILDREN;
auto winCls = kInstallerWindowClassName;
gHwndFrame = CreateWindowW(winCls, title.Get(), dwStyle, x, y, dx, dy, nullptr, nullptr, h, nullptr);
gHwndFrame = CreateWindowW(winCls, ToWStrTemp(title), dwStyle, x, y, dx, dy, nullptr, nullptr, h, nullptr);

DpiScale(gHwndFrame, dx, dy);
HwndResizeClientSize(gHwndFrame, dx, dy);
Expand All @@ -189,8 +189,8 @@ static void CreateUninstallerWindow() {

static void ShowUsage() {
// Note: translation services aren't initialized at this point, so English only
char* caption = str::JoinTemp(kAppName, " Uninstaller Usage");
AutoFreeStr msg = str::Format(
TempStr caption = str::JoinTemp(kAppName, " Uninstaller Usage");
TempStr msg = str::FormatTemp(
"uninstall.exe [/s][/d <path>]\n\
\n\
/s\tuninstalls %s silently (without user interaction).\n\
Expand Down Expand Up @@ -408,7 +408,7 @@ static void InitSelfDelete() {
return;
}
logf("Created self-delete batch script '%s'\n", scriptPath);
AutoFreeStr cmdLine = str::Format("cmd.exe /C \"%s\"", scriptPath);
TempStr cmdLine = str::FormatTemp("cmd.exe /C \"%s\"", scriptPath);
DWORD flags = CREATE_NO_WINDOW;
LaunchProcess(cmdLine, nullptr, flags);
}
Expand Down
6 changes: 3 additions & 3 deletions src/UpdateCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ void UpdateSelfTo(const char* path) {
// had time to exit so that we can overwrite it
::Sleep(gCli->sleepMs);

const char* srcPath = GetExePathTemp();
TempStr srcPath = GetExePathTemp();
bool ok = file::Copy(path, srcPath, false);
// TODO: maybe retry if copy fails under the theory that the file
// might be temporarily locked
Expand All @@ -489,6 +489,6 @@ void UpdateSelfTo(const char* path) {
}
logf("UpdateSelfTo: copied self to file\n");

AutoFreeStr args = str::Format(R"(-sleep-ms 500 -delete-file "%s")", srcPath);
CreateProcessHelper(path, args.Get());
TempStr args = str::FormatTemp(R"(-sleep-ms 500 -delete-file "%s")", srcPath);
CreateProcessHelper(path, args);
}
5 changes: 3 additions & 2 deletions src/tools/plugin-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ LRESULT CALLBACK PluginParentWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
if (WM_CREATE == msg) {
// run SumatraPDF.exe with the -plugin command line argument
PluginStartData* data = (PluginStartData*)((CREATESTRUCT*)lp)->lpCreateParams;
AutoFreeStr cmdLine(str::Format("-plugin %d \"%s\"", hwnd, data->filePath));
auto path = data->filePath;
TempStr cmdLine = str::FormatTemp("-plugin %d \"%s\"", hwnd, path);
if (data->fileOriginUrl) {
cmdLine.Set(str::Format("-plugin \"%s\" %d \"%s\"", data->fileOriginUrl, hwnd, data->filePath));
cmdLine = str::FormatTemp("-plugin \"%s\" %d \"%s\"", data->fileOriginUrl, hwnd, path);
}
ShellExecute(hwnd, L"open", ToWStrTemp(data->sumatraPath), ToWStrTemp(cmdLine), nullptr, SW_SHOW);
} else if (WM_SIZE == msg) {
Expand Down
3 changes: 2 additions & 1 deletion src/uia/PageProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ HRESULT STDMETHODCALLTYPE SumatraUIAutomationPageProvider::GetPropertyValue(PROP

if (propertyId == UIA_NamePropertyId) {
pRetVal->vt = VT_BSTR;
pRetVal->bstrVal = SysAllocString(AutoFreeWstr(str::Format(L"Page %d", pageNum)));
TempStr s = str::FormatTemp("Page %d", pageNum);
pRetVal->bstrVal = SysAllocString(ToWStrTemp(s));
return S_OK;
} else if (propertyId == UIA_IsValuePatternAvailablePropertyId) {
pRetVal->vt = VT_BOOL;
Expand Down
9 changes: 5 additions & 4 deletions src/utils/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,10 +710,11 @@ int GetZoneIdentifier(const char* filePath) {
}

bool SetZoneIdentifier(const char* filePath, int zoneId) {
char* path = str::JoinTemp(filePath, ":Zone.Identifier");
AutoFreeWstr id(str::Format(L"%d", zoneId));
WCHAR* pathW = ToWStrTemp(path);
return WritePrivateProfileStringW(L"ZoneTransfer", L"ZoneId", id, pathW);
TempStr path = str::JoinTemp(filePath, ":Zone.Identifier");
TempStr id = str::FormatTemp("%d", zoneId);
TempWStr idw = ToWStrTemp(id);
TempWStr pathW = ToWStrTemp(path);
return WritePrivateProfileStringW(L"ZoneTransfer", L"ZoneId", idw, pathW);
}

bool DeleteZoneIdentifier(const char* filePath) {
Expand Down

0 comments on commit 6da70b7

Please sign in to comment.