From affca15f8b1bac6520e6837cab74b0ebe4382426 Mon Sep 17 00:00:00 2001 From: plfiorini Date: Sun, 9 May 2010 09:38:30 +0000 Subject: [PATCH] Added utility functions to get account paths. --- application/CayaUtils.cpp | 37 +++++++++++++++++++++++++++++ application/CayaUtils.h | 4 ++++ application/ProtocolSettings.cpp | 40 +++++++------------------------- 3 files changed, 50 insertions(+), 31 deletions(-) diff --git a/application/CayaUtils.cpp b/application/CayaUtils.cpp index 620d654..3fcae90 100644 --- a/application/CayaUtils.cpp +++ b/application/CayaUtils.cpp @@ -9,6 +9,9 @@ #include #include +#include +#include +#include #include "private/IconUtils.h" @@ -55,6 +58,40 @@ CayaResources() return res; } + +const char* +CayaAccountsPath() +{ + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) + return NULL; + + path.Append("Caya/Protocols"); + if (create_directory(path.Path(), 0755) != B_OK) + return NULL; + + return path.Path(); +} + + +const char* +CayaAccountPath(const char* signature) +{ + if (!signature) + return NULL; + + BPath path(CayaAccountsPath()); + if (path.InitCheck() != B_OK) + return NULL; + + path.Append(signature); + if (create_directory(path.Path(), 0755) != B_OK) + return NULL; + + return path.Path(); +} + + extern "C" { status_t diff --git a/application/CayaUtils.h b/application/CayaUtils.h index acd0638..fa41b01 100644 --- a/application/CayaUtils.h +++ b/application/CayaUtils.h @@ -13,8 +13,12 @@ #include "CayaConstants.h" const char* CayaStatusToString(CayaStatus status); + BResources* CayaResources(); +const char* CayaAccountsPath(); +const char* CayaAccountPath(const char* signature); + extern "C" status_t our_image(image_info& image); #endif // _CAYA_UTILS_H diff --git a/application/ProtocolSettings.cpp b/application/ProtocolSettings.cpp index 9fa7d90..65d1f25 100644 --- a/application/ProtocolSettings.cpp +++ b/application/ProtocolSettings.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -34,6 +33,7 @@ #include "CayaProtocol.h" #include "CayaResources.h" +#include "CayaUtils.h" #include "ProtocolManager.h" #include "ProtocolSettings.h" @@ -75,13 +75,8 @@ ProtocolSettings::Accounts() const { List list; - BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) - return list; - - path.Append("Caya/Protocols"); - path.Append(fProtocol->GetSignature()); - if (create_directory(path.Path(), 0755) != B_OK) + BPath path(CayaAccountPath(fProtocol->GetSignature())); + if (path.InitCheck() != B_OK) return list; BDirectory dir(path.Path()); @@ -365,15 +360,10 @@ ProtocolSettings::Delete(const char* account) status_t ret = B_ERROR; // Find user's settings path - BPath path; - if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) + BPath path(CayaAccountPath(fProtocol->GetSignature())); + if ((ret = path.InitCheck()) != B_OK) return ret; - // Create path - path.Append("Caya/Protocols"); - path.Append(fProtocol->GetSignature()); - if ((ret = create_directory(path.Path(), 0755)) != B_OK) - return ret; path.Append(account); // Delete settings file @@ -427,14 +417,8 @@ ProtocolSettings::_Load(const char* account, BMessage** settings) status_t ret = B_ERROR; // Find user's settings path - BPath path; - if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) - return ret; - - // Create path - path.Append("Caya/Protocols"); - path.Append(fProtocol->GetSignature()); - if ((ret = create_directory(path.Path(), 0755)) != B_OK) + BPath path(CayaAccountPath(fProtocol->GetSignature())); + if ((ret = path.InitCheck()) != B_OK) return ret; // Load settings file @@ -456,14 +440,8 @@ ProtocolSettings::_Save(const char* account, BMessage* settings) status_t ret = B_ERROR; // Find user's settings path - BPath path; - if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) - return ret; - - // Create path - path.Append("Caya/Protocols"); - path.Append(fProtocol->GetSignature()); - if ((ret = create_directory(path.Path(), 0755)) != B_OK) + BPath path(CayaAccountPath(fProtocol->GetSignature())); + if ((ret = path.InitCheck()) != B_OK) return ret; // Load settings file