From c1625af84b0c50c218447e3dbd9cd8beef5e7fef Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Tue, 2 Mar 2021 20:07:49 -0600 Subject: [PATCH] find_directory instead of hardcoded paths --- TODO.txt | 1 - src/App.cpp | 3 --- src/App.h | 2 -- src/Feed.cpp | 8 ++++++-- src/FeedController.cpp | 7 ++++++- src/FeedEditWindow.cpp | 12 ++++++++---- src/Preferences.cpp | 32 ++++++++++++++++---------------- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/TODO.txt b/TODO.txt index 033901f..faf84ee 100644 --- a/TODO.txt +++ b/TODO.txt @@ -12,7 +12,6 @@ Important improvements: so. * _Huge_ problem, but I haven't had luck figuring it out yet… * Move from BLists to BObjectLists where possible -* No hardcoded paths * General input sanitization * File error-handling * e.g., Utils.cpp's userFileError diff --git a/src/App.cpp b/src/App.cpp index 6dd95d0..ccb620f 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -212,9 +212,6 @@ App::_OpenSourceFile(BMessage* refMessage) } -const char* configPath = "/boot/home/config/settings/Pogger/"; - - int main(int argc, char** argv) { diff --git a/src/App.h b/src/App.h index 3a45cab..cd927b9 100644 --- a/src/App.h +++ b/src/App.h @@ -45,8 +45,6 @@ private: int main(int argc, char** argv); -extern const char* configPath; - #endif // APP_H diff --git a/src/Feed.cpp b/src/Feed.cpp index dc6331d..1679be0 100644 --- a/src/Feed.cpp +++ b/src/Feed.cpp @@ -26,9 +26,13 @@ Feed::Feed(BUrl xml) : Feed() { SetXmlUrl(xml); - BString cache("/boot/home/config/cache/Pogger/"); + + BPath cache; + find_directory(B_USER_CACHE_DIRECTORY, &cache); + cache.Append("Pogger"); + cache.Append(urlToFilename(xmlUrl)); - SetCachePath(cache); + SetCachePath(cache.Path()); } diff --git a/src/FeedController.cpp b/src/FeedController.cpp index 49b9231..aeb2703 100644 --- a/src/FeedController.cpp +++ b/src/FeedController.cpp @@ -90,7 +90,12 @@ FeedController::MessageReceived(BMessage* msg) BList FeedController::SubscribedFeeds() { - BDirectory subDir("/boot/home/config/settings/Pogger/Subscriptions"); + BPath subPath; + find_directory(B_USER_SETTINGS_DIRECTORY, &subPath); + subPath.Append("Pogger"); + subPath.Append("Subscriptions"); + + BDirectory subDir(subPath.Path()); BEntry feedEntry; BList feeds; diff --git a/src/FeedEditWindow.cpp b/src/FeedEditWindow.cpp index dcd6505..34e554b 100644 --- a/src/FeedEditWindow.cpp +++ b/src/FeedEditWindow.cpp @@ -121,11 +121,15 @@ FeedEditWindow::_InitInterface() .End(); } - +#include void FeedEditWindow::_SaveFeed() { - BString subLocation("/boot/home/config/settings/Pogger/Subscriptions/"); + BPath subPath; + find_directory(B_USER_SETTINGS_DIRECTORY, &subPath); + subPath.Append("Pogger"); + subPath.Append("Subscriptions"); + BString title(fFeedNameText->Text()); const char* urlString = fFeedUrlText->Text(); BString filename; @@ -133,10 +137,10 @@ FeedEditWindow::_SaveFeed() filename = BString(urlString); else filename = BString(title); - subLocation.Append(filename); + subPath.Append(filename); if (fFeed->GetCachePath().IsEmpty()) - fFeed->SetCachePath(subLocation); + fFeed->SetCachePath(BString(subPath.Path())); if (!title.IsEmpty()) fFeed->SetTitle(title.String()); diff --git a/src/Preferences.cpp b/src/Preferences.cpp index e349f27..818a8eb 100644 --- a/src/Preferences.cpp +++ b/src/Preferences.cpp @@ -22,10 +22,11 @@ Preferences::Preferences(Preferences* pref) { void Preferences::Load() { - BString configDir("/boot/home/config/settings/Pogger/"); + BPath cfgPath; + find_directory(B_USER_SETTINGS_DIRECTORY, &cfgPath); + cfgPath.Append("Pogger"); + BString filename = BString(cfgPath.Path()).Append("/Settings"); - BString filename = BString(configDir); - filename.Append("Settings"); BFile file(filename.String(), B_READ_ONLY); status_t result = file.InitCheck(); @@ -53,23 +54,22 @@ Preferences::Load() void Preferences::Save() { - BString configDir = BString("/boot/home/config/settings/Pogger/"); + BPath cfgPath; + find_directory(B_USER_SETTINGS_DIRECTORY, &cfgPath); + cfgPath.Append("Pogger"); + BEntry cfgEntry = BEntry(cfgPath.Path()); + BDirectory cfgDir; - BPath* cfgPath = new BPath(configDir.String(), NULL, true); - BEntry* cfgEntry = new BEntry(cfgPath->Path()); - BDirectory* cfgDir = new BDirectory; - - cfgDir->CreateDirectory(cfgPath->Path(), NULL); + cfgDir.CreateDirectory(cfgPath.Path(), NULL); - if (cfgEntry->Exists() == false) - cfgDir->CreateDirectory(cfgPath->Path(), NULL); + if (cfgEntry.Exists() == false) + cfgDir.CreateDirectory(cfgPath.Path(), NULL); BMessage storage; - BString filename = BString(configDir).Append("/Settings"); + BString filename = BString(cfgPath.Path()).Append("/Settings"); - BFile* file = new BFile(filename.String(), B_WRITE_ONLY | B_CREATE_FILE - | B_ERASE_FILE); - status_t result = file->InitCheck(); + BFile file(filename.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); + status_t result = file.InitCheck(); storage.AddString("entryDir", fEntryDir.String()); storage.AddString("openWith", fOpenWith.String()); @@ -83,7 +83,7 @@ Preferences::Save() storage.AddRect("feedEditWindow", fFeedEditRect); storage.AddInt32("tabSelection", fTabSelection); - storage.Flatten(file); + storage.Flatten(&file); }