Skip to content

Commit

Permalink
go back to opening settings file with default .txt editor (notepad mo…
Browse files Browse the repository at this point in the history
…st likely) (fixes #2762)
  • Loading branch information
kjk committed Nov 16, 2023
1 parent f5568c6 commit c885a19
Show file tree
Hide file tree
Showing 28 changed files with 102 additions and 101 deletions.
12 changes: 6 additions & 6 deletions src/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ static int cmpFloat(const void* a, const void* b) {
return *(float*)a < *(float*)b ? -1 : *(float*)a > *(float*)b ? 1 : 0;
}

char* GetSettingsFileNameTemp() {
TempStr GetSettingsFileNameTemp() {
return str::DupTemp("SumatraPDF-settings.txt");
}

char* GetSettingsPathTemp() {
TempStr GetSettingsPathTemp() {
return AppGenDataFilenameTemp(GetSettingsFileNameTemp());
}

Expand All @@ -88,7 +88,7 @@ bool LoadSettings() {
auto timeStart = TimeGet();

GlobalPrefs* gprefs = nullptr;
char* settingsPath = GetSettingsPathTemp();
TempStr settingsPath = GetSettingsPathTemp();
{
ByteSlice prefsData = file::ReadFile(settingsPath);

Expand Down Expand Up @@ -247,7 +247,7 @@ bool SaveSettings() {
str::ReplaceWithCopy(&gGlobalPrefs->defaultDisplayMode, DisplayModeToString(gGlobalPrefs->defaultDisplayModeEnum));
ZoomToString(&gGlobalPrefs->defaultZoom, gGlobalPrefs->defaultZoomFloat, nullptr);

char* path = GetSettingsPathTemp();
TempStr path = GetSettingsPathTemp();
ReportIf(!path);
if (!path) {
return false;
Expand Down Expand Up @@ -281,7 +281,7 @@ bool SaveSettings() {
// refresh the preferences when a different SumatraPDF process saves them
// or if they are edited by the user using a text editor
bool ReloadSettings() {
char* settingsPath = GetSettingsPathTemp();
TempStr settingsPath = GetSettingsPathTemp();
if (!file::Exists(settingsPath)) {
return false;
}
Expand Down Expand Up @@ -359,7 +359,7 @@ void RegisterSettingsForFileChanges() {
}

CrashIf(gWatchedSettingsFile); // only call me once
char* path = GetSettingsPathTemp();
TempStr path = GetSettingsPathTemp();
gWatchedSettingsFile = FileWatcherSubscribe(path, schedulePrefsReload);
}

Expand Down
4 changes: 2 additions & 2 deletions src/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ enum {
WIN_STATE_MINIMIZED,
};

char* GetSettingsPathTemp();
char* GetSettingsFileNameTemp();
TempStr GetSettingsPathTemp();
TempStr GetSettingsFileNameTemp();

bool LoadSettings();
bool SaveSettings();
Expand Down
24 changes: 6 additions & 18 deletions src/AppTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
created by an installer (and should be updated through an installer) */
bool HasBeenInstalled() {
// see GetDefaultInstallationDir() in Installer.cpp
char* regPathUninst = str::JoinTemp("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\", kAppName);
char* installedPath = LoggedReadRegStr2Temp(regPathUninst, "InstallLocation");
TempStr regPathUninst = str::JoinTemp("Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\", kAppName);
TempStr installedPath = LoggedReadRegStr2Temp(regPathUninst, "InstallLocation");
if (!installedPath) {
return false;
}

char* exePath = GetExePathTemp();
TempStr exePath = GetExePathTemp();
if (exePath) {
return false;
}
Expand Down Expand Up @@ -64,8 +64,8 @@ bool IsRunningInPortableMode() {
return false;
}

char* exePath = GetExePathTemp();
char* programFilesDir = GetSpecialFolderTemp(CSIDL_PROGRAM_FILES);
TempStr exePath = GetExePathTemp();
TempStr programFilesDir = GetSpecialFolderTemp(CSIDL_PROGRAM_FILES);
// if we can't get a path, assume we're not running from "Program Files"
if (!exePath || !programFilesDir) {
sCacheIsPortable = 1;
Expand Down Expand Up @@ -115,7 +115,7 @@ TempStr AppGenDataFilenameTemp(const char* fileName) {
return path::GetPathOfFileInAppDirTemp(fileName);
}

char* path = GetSpecialFolderTemp(CSIDL_LOCAL_APPDATA, true);
TempStr path = GetSpecialFolderTemp(CSIDL_LOCAL_APPDATA, true);
if (!path) {
return nullptr;
}
Expand Down Expand Up @@ -404,18 +404,6 @@ char* BuildOpenFileCmd(const char* pattern, const char* path, int line, int col)
return cmdline.StealData();
}

void OpenFileWithTextEditor(const char* path) {
Vec<TextEditor*> editors;
DetectTextEditors(editors);
const char* cmd = editors[0]->openFileCmd;

char* cmdLine = BuildOpenFileCmd(cmd, path, 1, 1);
logf("OpenFileWithTextEditor: '%s'\n", cmdLine);
char* appDir = GetExeDirTemp();
AutoCloseHandle process(LaunchProcess(cmdLine, appDir));
str::Free(cmdLine);
}

#define UWM_DELAYED_SET_FOCUS (WM_APP + 1)

// selects all text in an edit box if it's selected either
Expand Down
1 change: 0 additions & 1 deletion src/AppTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ TempStr AppGenDataFilenameTemp(const char* fileName);
void SetAppDataPath(const char* path);

void DetectTextEditors(Vec<TextEditor*>&);
void OpenFileWithTextEditor(const char* path);
char* BuildOpenFileCmd(const char* pattern, const char* path, int line, int col);

bool ExtendedEditWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
Expand Down
8 changes: 4 additions & 4 deletions src/CommandPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ static bool AllowCommand(const CommandPaletteBuildCtx& ctx, i32 cmdId) {
return true;
}

static char* ConvertPathForDisplayTemp(const char* s) {
const char* name = path::GetBaseNameTemp(s);
char* dir = path::GetDirTemp(s);
char* res = str::JoinTemp(name, " (", dir);
static TempStr ConvertPathForDisplayTemp(const char* s) {
TempStr name = path::GetBaseNameTemp(s);
TempStr dir = path::GetDirTemp(s);
TempStr res = str::JoinTemp(name, " (", dir);
res = str::JoinTemp(res, ")");
return res;
}
Expand Down
2 changes: 1 addition & 1 deletion src/CrashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void InstallCrashHandler(const char* crashDumpPath, const char* crashFilePath, c
gCrashHandlerAllocator = new HeapAllocator();
gSymbolsUrl = BuildSymbolsUrl();

char* path = GetSettingsPathTemp();
TempStr path = GetSettingsPathTemp();
// can be empty on first run but that's fine because then we know it has default values
ByteSlice prefsData = file::ReadFile(path);
if (!prefsData.empty()) {
Expand Down
12 changes: 6 additions & 6 deletions src/EngineImages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,8 @@ TempStr EngineImageDir::GetPageLabeTemp(int pageNo) const {
}

const char* path = pageFileNames.at(pageNo - 1);
const char* fileName = path::GetBaseNameTemp(path);
char* ext = path::GetExtTemp(fileName);
TempStr fileName = path::GetBaseNameTemp(path);
TempStr ext = path::GetExtTemp(fileName);
if (!ext) {
return str::DupTemp(fileName);
}
Expand All @@ -886,7 +886,7 @@ int EngineImageDir::GetPageByLabel(const char* label) const {
size_t nLabel = str::Len(label);
for (int i = 0; i < pageFileNames.Size(); i++) {
char* pagePath = pageFileNames[i];
const char* fileName = path::GetBaseNameTemp(pagePath);
TempStr fileName = path::GetBaseNameTemp(pagePath);
char* ext = path::GetExtTemp(fileName);
if (!str::StartsWith(fileName, label)) {
continue;
Expand Down Expand Up @@ -930,8 +930,8 @@ bool EngineImageDir::SaveFileAs(const char* dstPath) {
return false;
}
for (char* pathOld : pageFileNames) {
const char* fileName = path::GetBaseNameTemp(pathOld);
char* pathNew = path::JoinTemp(dstPath, fileName);
TempStr fileName = path::GetBaseNameTemp(pathOld);
TempStr pathNew = path::JoinTemp(dstPath, fileName);
ok = ok && file::Copy(pathNew, pathOld, true);
}
return ok;
Expand Down Expand Up @@ -1257,7 +1257,7 @@ bool EngineCbx::FinishLoading() {
TocItem* curr = nullptr;
for (int i = 0; i < pageCount; i++) {
const char* fname = files[i]->name;
const char* baseName = path::GetBaseNameTemp(fname);
TempStr baseName = path::GetBaseNameTemp(fname);
TocItem* ti = new TocItem(nullptr, baseName, i + 1);
if (root == nullptr) {
root = ti;
Expand Down
2 changes: 1 addition & 1 deletion src/EngineMulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ TocItem* CreateWrapperItem(EngineBase* engine) {
tocFileRoot = CloneTocItemRecur(tocTree->root, false);
}
int nPages = engine->PageCount();
const char* title = path::GetBaseNameTemp(engine->FilePath());
TempStr title = path::GetBaseNameTemp(engine->FilePath());
TocItem* tocWrapper = new TocItem(tocFileRoot, title, 0);
tocWrapper->isOpenDefault = true;
tocWrapper->child = tocFileRoot;
Expand Down
4 changes: 2 additions & 2 deletions src/EnginePs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ static EngineBase* ps2pdf(const char* path) {
gswin32c.Get(), tmpFile.Get(), shortPath.Get());

{
const char* fileName = path::GetBaseNameTemp(__FILE__);
TempStr fileName = path::GetBaseNameTemp(__FILE__);
char* gswin = gswin32c.Get();
const char* tmpFileName = path::GetBaseNameTemp(tmpFile.Get());
TempStr tmpFileName = path::GetBaseNameTemp(tmpFile.Get());
logf("- %s:%d: using '%s' for creating '%%TEMP%%\\%s'\n", fileName, __LINE__, gswin, tmpFileName);
}

Expand Down
4 changes: 2 additions & 2 deletions src/ExternalViewers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ static bool DetectExternalViewer(ExternalViewerInfo* ev) {

static int const csidls[] = {CSIDL_PROGRAM_FILES, CSIDL_PROGRAM_FILESX86, CSIDL_WINDOWS, CSIDL_SYSTEM};
for (int csidl : csidls) {
char* dir = GetSpecialFolderTemp(csidl);
char* path = path::JoinTemp(dir, partialPath);
TempStr dir = GetSpecialFolderTemp(csidl);
TempStr path = path::JoinTemp(dir, partialPath);
if (file::Exists(path)) {
ev->exeFullPath = str::Dup(path);
return true;
Expand Down
8 changes: 4 additions & 4 deletions src/Favorites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static TempStr FavCompactReadableNameTemp(FileState* fav, Favorite* fn, bool isC
if (isCurrent) {
return str::FormatTemp("%s : %s", _TRA("Current file"), rn);
}
const char* fp = path::GetBaseNameTemp(fav->filePath);
TempStr fp = path::GetBaseNameTemp(fav->filePath);
return str::FormatTemp("%s : %s", fp, rn);
}

Expand Down Expand Up @@ -346,8 +346,8 @@ static bool SortByBaseFileName(const char* s1, const char* s2) {
if (str::IsEmpty(s2)) {
return false;
}
const char* base1 = path::GetBaseNameTemp(s1);
const char* base2 = path::GetBaseNameTemp(s2);
TempStr base1 = path::GetBaseNameTemp(s1);
TempStr base2 = path::GetBaseNameTemp(s2);
int n = str::CmpNatural(base1, base2);
return n < 0;
}
Expand Down Expand Up @@ -578,7 +578,7 @@ static FavTreeItem* MakeFavTopLevelItem(FileState* fav, bool isExpanded) {
text = FavCompactReadableNameTemp(fav, fn);
} else {
char* fp = fav->filePath;
text = (TempStr)path::GetBaseNameTemp(fp);
text = path::GetBaseNameTemp(fp);
}
res->text = str::Dup(text);
return res;
Expand Down
2 changes: 1 addition & 1 deletion src/FileHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ FileState* FileHistory::FindByPath(const char* filePath) const {
FileState* FileHistory::FindByName(const char* filePath, size_t* idxOut) const {
int idxExact = -1;
int idxFileNameMatch = -1;
const char* fileName = path::GetBaseNameTemp(filePath);
TempStr fileName = path::GetBaseNameTemp(filePath);
int n = states->isize();
for (int i = 0; i < n; i++) {
FileState* fs = states->at(i);
Expand Down
2 changes: 1 addition & 1 deletion src/HomePage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ void DrawHomePage(MainWindow* win, HDC hdc, const FileHistory& fileHistory, COLO
rect.x -= iconSpace;
}
char* path = state->filePath;
const char* fileName = path::GetBaseNameTemp(path);
TempStr fileName = path::GetBaseNameTemp(path);
UINT fmt = DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX | (isRtl ? DT_RIGHT : DT_LEFT);
HdcDrawText(hdc, fileName, rect, fmt, fontText);

Expand Down
18 changes: 9 additions & 9 deletions src/Installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ static bool ExtractFiles(lzma::SimpleArchive* archive, const char* destDir) {

static bool CopySelfToDir(const char* destDir) {
logf("CopySelfToDir(%s)\n", destDir);
char* exePath = GetExePathTemp();
char* dstPath = path::JoinTemp(destDir, kExeName);
TempStr exePath = GetExePathTemp();
TempStr dstPath = path::JoinTemp(destDir, kExeName);
bool failIfExists = false;
bool ok = file::Copy(dstPath, exePath, failIfExists);
// strip zone identifier (if exists) to avoid windows
Expand All @@ -158,18 +158,18 @@ static void CopySettingsFile() {
// copy the settings from old directory

// seen a crash when running elevated
char* srcDir = GetSpecialFolderTemp(CSIDL_APPDATA, false);
TempStr srcDir = GetSpecialFolderTemp(CSIDL_APPDATA, false);
if (str::IsEmpty(srcDir)) {
return;
}
char* dstDir = GetSpecialFolderTemp(CSIDL_LOCAL_APPDATA, false);
TempStr dstDir = GetSpecialFolderTemp(CSIDL_LOCAL_APPDATA, false);
if (str::IsEmpty(dstDir)) {
return;
}

const char* prefsFileName = GetSettingsFileNameTemp();
char* srcPath = path::JoinTemp(srcDir, kAppName, prefsFileName);
char* dstPath = path::JoinTemp(dstDir, kAppName, prefsFileName);
TempStr prefsFileName = GetSettingsFileNameTemp();
TempStr srcPath = path::JoinTemp(srcDir, kAppName, prefsFileName);
TempStr dstPath = path::JoinTemp(dstDir, kAppName, prefsFileName);

// don't over-write
bool failIfExists = true;
Expand Down Expand Up @@ -582,8 +582,8 @@ static char* GetDefaultInstallationDir(bool forAllUsers, bool ignorePrev) {

char* dir;
char* dirPrevInstall = gWnd->prevInstall.installationDir;
char* dirAll = GetSpecialFolderTemp(CSIDL_PROGRAM_FILES, false);
char* dirUser = GetSpecialFolderTemp(CSIDL_LOCAL_APPDATA, false);
TempStr dirAll = GetSpecialFolderTemp(CSIDL_PROGRAM_FILES, false);
TempStr dirUser = GetSpecialFolderTemp(CSIDL_LOCAL_APPDATA, false);

if (dirPrevInstall && !ignorePrev) {
logf(" using %s from previous install\n", dirPrevInstall);
Expand Down
14 changes: 7 additions & 7 deletions src/InstallerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ char* GetExistingInstallationDir() {
return str::Dup(gCachedExistingInstallationDir);
}
log("GetExistingInstallationDir()\n");
char* regPathUninst = GetRegPathUninstTemp(kAppName);
char* dir = LoggedReadRegStr2Temp(regPathUninst, "InstallLocation");
TempStr regPathUninst = GetRegPathUninstTemp(kAppName);
TempStr dir = LoggedReadRegStr2Temp(regPathUninst, "InstallLocation");
if (!dir) {
return nullptr;
}
Expand Down Expand Up @@ -162,22 +162,22 @@ char* GetInstallDirTemp() {
}

char* GetInstallationFilePathTemp(const char* name) {
char* res = path::JoinTemp(gCli->installDir, name);
TempStr res = path::JoinTemp(gCli->installDir, name);
logf("GetInstallationFilePath(%s) = > %s\n", name, res);
return res;
}

TempStr GetInstalledExePathTemp() {
char* dir = GetInstallDirTemp();
TempStr dir = GetInstallDirTemp();
return path::JoinTemp(dir, kExeName);
}

TempStr GetShortcutPathTemp(int csidl) {
char* dir = GetSpecialFolderTemp(csidl, false);
TempStr dir = GetSpecialFolderTemp(csidl, false);
if (!dir) {
return {};
}
char* lnkName = str::JoinTemp(kAppName, ".lnk");
TempStr lnkName = str::JoinTemp(kAppName, ".lnk");
return path::JoinTemp(dir, lnkName);
}

Expand Down Expand Up @@ -482,7 +482,7 @@ static const char* readableProcessNames[] = {
static const char* ReadableProcName(const char* procPath) {
readableProcessNames[0] = kExeName;
readableProcessNames[1] = kAppName;
const char* procName = path::GetBaseNameTemp(procPath);
TempStr procName = path::GetBaseNameTemp(procPath);
for (size_t i = 0; i < dimof(readableProcessNames); i += 2) {
if (str::EqI(procName, readableProcessNames[i])) {
return readableProcessNames[i + 1];
Expand Down
2 changes: 1 addition & 1 deletion src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ static void AddFileMenuItem(HMENU menuFile, const char* filePath, int index) {
return;
}

TempStr menuString = (TempStr)path::GetBaseNameTemp(filePath);
TempStr menuString = path::GetBaseNameTemp(filePath);

// If the name is too long, save only the ends glued together
// E.g. 'Very Long PDF Name (3).pdf' -> 'Very Long...e (3).pdf'
Expand Down
2 changes: 1 addition & 1 deletion src/SearchAndDDE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ bool OnInverseSearch(MainWindow* win, int x, int y) {
if (!file::Exists(srcfilepath)) {
// if the source file is missing, check if it's been moved to the same place as
// the PDF document (which happens if all files are moved together)
char* altsrcpath = path::GetDirTemp(tab->filePath);
TempStr altsrcpath = path::GetDirTemp(tab->filePath);
altsrcpath = path::JoinTemp(altsrcpath, path::GetBaseNameTemp(srcfilepath));
if (!str::Eq(altsrcpath, srcfilepath) && file::Exists(altsrcpath)) {
srcfilepath.SetCopy(altsrcpath);
Expand Down
Loading

0 comments on commit c885a19

Please sign in to comment.