Added utility functions to get account paths.

This commit is contained in:
plfiorini 2010-05-09 09:38:30 +00:00
parent 3127e2b049
commit affca15f8b
3 changed files with 50 additions and 31 deletions

View File

@ -9,6 +9,9 @@
#include <memory.h> #include <memory.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Directory.h>
#include <FindDirectory.h>
#include <Path.h>
#include "private/IconUtils.h" #include "private/IconUtils.h"
@ -55,6 +58,40 @@ CayaResources()
return res; 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" { extern "C" {
status_t status_t

View File

@ -13,8 +13,12 @@
#include "CayaConstants.h" #include "CayaConstants.h"
const char* CayaStatusToString(CayaStatus status); const char* CayaStatusToString(CayaStatus status);
BResources* CayaResources(); BResources* CayaResources();
const char* CayaAccountsPath();
const char* CayaAccountPath(const char* signature);
extern "C" status_t our_image(image_info& image); extern "C" status_t our_image(image_info& image);
#endif // _CAYA_UTILS_H #endif // _CAYA_UTILS_H

View File

@ -14,7 +14,6 @@
#include <CheckBox.h> #include <CheckBox.h>
#include <Directory.h> #include <Directory.h>
#include <File.h> #include <File.h>
#include <FindDirectory.h>
#include <GroupLayout.h> #include <GroupLayout.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <Menu.h> #include <Menu.h>
@ -34,6 +33,7 @@
#include "CayaProtocol.h" #include "CayaProtocol.h"
#include "CayaResources.h" #include "CayaResources.h"
#include "CayaUtils.h"
#include "ProtocolManager.h" #include "ProtocolManager.h"
#include "ProtocolSettings.h" #include "ProtocolSettings.h"
@ -75,13 +75,8 @@ ProtocolSettings::Accounts() const
{ {
List<BString> list; List<BString> list;
BPath path; BPath path(CayaAccountPath(fProtocol->GetSignature()));
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK) if (path.InitCheck() != B_OK)
return list;
path.Append("Caya/Protocols");
path.Append(fProtocol->GetSignature());
if (create_directory(path.Path(), 0755) != B_OK)
return list; return list;
BDirectory dir(path.Path()); BDirectory dir(path.Path());
@ -365,15 +360,10 @@ ProtocolSettings::Delete(const char* account)
status_t ret = B_ERROR; status_t ret = B_ERROR;
// Find user's settings path // Find user's settings path
BPath path; BPath path(CayaAccountPath(fProtocol->GetSignature()));
if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) if ((ret = path.InitCheck()) != B_OK)
return ret; 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); path.Append(account);
// Delete settings file // Delete settings file
@ -427,14 +417,8 @@ ProtocolSettings::_Load(const char* account, BMessage** settings)
status_t ret = B_ERROR; status_t ret = B_ERROR;
// Find user's settings path // Find user's settings path
BPath path; BPath path(CayaAccountPath(fProtocol->GetSignature()));
if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) 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; return ret;
// Load settings file // Load settings file
@ -456,14 +440,8 @@ ProtocolSettings::_Save(const char* account, BMessage* settings)
status_t ret = B_ERROR; status_t ret = B_ERROR;
// Find user's settings path // Find user's settings path
BPath path; BPath path(CayaAccountPath(fProtocol->GetSignature()));
if ((ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path)) != B_OK) 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; return ret;
// Load settings file // Load settings file