find_directory instead of hardcoded paths

This commit is contained in:
Jaidyn Ann 2021-03-02 20:07:49 -06:00
parent c87faea937
commit c1625af84b
7 changed files with 36 additions and 29 deletions

View File

@ -12,7 +12,6 @@ Important improvements:
so. so.
* _Huge_ problem, but I haven't had luck figuring it out yet… * _Huge_ problem, but I haven't had luck figuring it out yet…
* Move from BLists to BObjectLists where possible * Move from BLists to BObjectLists where possible
* No hardcoded paths
* General input sanitization * General input sanitization
* File error-handling * File error-handling
* e.g., Utils.cpp's userFileError * e.g., Utils.cpp's userFileError

View File

@ -212,9 +212,6 @@ App::_OpenSourceFile(BMessage* refMessage)
} }
const char* configPath = "/boot/home/config/settings/Pogger/";
int int
main(int argc, char** argv) main(int argc, char** argv)
{ {

View File

@ -45,8 +45,6 @@ private:
int main(int argc, char** argv); int main(int argc, char** argv);
extern const char* configPath;
#endif // APP_H #endif // APP_H

View File

@ -26,9 +26,13 @@ Feed::Feed(BUrl xml)
: Feed() : Feed()
{ {
SetXmlUrl(xml); 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)); cache.Append(urlToFilename(xmlUrl));
SetCachePath(cache); SetCachePath(cache.Path());
} }

View File

@ -90,7 +90,12 @@ FeedController::MessageReceived(BMessage* msg)
BList BList
FeedController::SubscribedFeeds() 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; BEntry feedEntry;
BList feeds; BList feeds;

View File

@ -121,11 +121,15 @@ FeedEditWindow::_InitInterface()
.End(); .End();
} }
#include <iostream>
void void
FeedEditWindow::_SaveFeed() 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()); BString title(fFeedNameText->Text());
const char* urlString = fFeedUrlText->Text(); const char* urlString = fFeedUrlText->Text();
BString filename; BString filename;
@ -133,10 +137,10 @@ FeedEditWindow::_SaveFeed()
filename = BString(urlString); filename = BString(urlString);
else else
filename = BString(title); filename = BString(title);
subLocation.Append(filename); subPath.Append(filename);
if (fFeed->GetCachePath().IsEmpty()) if (fFeed->GetCachePath().IsEmpty())
fFeed->SetCachePath(subLocation); fFeed->SetCachePath(BString(subPath.Path()));
if (!title.IsEmpty()) if (!title.IsEmpty())
fFeed->SetTitle(title.String()); fFeed->SetTitle(title.String());

View File

@ -22,10 +22,11 @@ Preferences::Preferences(Preferences* pref) {
void void
Preferences::Load() 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); BFile file(filename.String(), B_READ_ONLY);
status_t result = file.InitCheck(); status_t result = file.InitCheck();
@ -53,23 +54,22 @@ Preferences::Load()
void void
Preferences::Save() 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); cfgDir.CreateDirectory(cfgPath.Path(), NULL);
BEntry* cfgEntry = new BEntry(cfgPath->Path());
BDirectory* cfgDir = new BDirectory;
cfgDir->CreateDirectory(cfgPath->Path(), NULL);
if (cfgEntry->Exists() == false) if (cfgEntry.Exists() == false)
cfgDir->CreateDirectory(cfgPath->Path(), NULL); cfgDir.CreateDirectory(cfgPath.Path(), NULL);
BMessage storage; 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 BFile file(filename.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
| B_ERASE_FILE); status_t result = file.InitCheck();
status_t result = file->InitCheck();
storage.AddString("entryDir", fEntryDir.String()); storage.AddString("entryDir", fEntryDir.String());
storage.AddString("openWith", fOpenWith.String()); storage.AddString("openWith", fOpenWith.String());
@ -83,7 +83,7 @@ Preferences::Save()
storage.AddRect("feedEditWindow", fFeedEditRect); storage.AddRect("feedEditWindow", fFeedEditRect);
storage.AddInt32("tabSelection", fTabSelection); storage.AddInt32("tabSelection", fTabSelection);
storage.Flatten(file); storage.Flatten(&file);
} }