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.
* _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

View File

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

View File

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

View File

@ -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());
}

View File

@ -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;

View File

@ -121,11 +121,15 @@ FeedEditWindow::_InitInterface()
.End();
}
#include <iostream>
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());

View File

@ -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);
}