fix(paths): clean code

This commit is contained in:
Ronan Abhamon 2018-05-16 16:19:18 +02:00
parent e682a3b1f5
commit babef084be
8 changed files with 38 additions and 47 deletions

View file

@ -19,8 +19,6 @@
#include <jni.h>
#include "linphone/utils/utils.h"
#include "core/platform-helpers/platform-helpers.h"
#include "paths-android.h"
@ -31,16 +29,16 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
if (!platformHelper)
return Utils::getEmptyConstRefObject<string>();
return platformHelper->getDataPath();
string SysPaths::getDataPath (PlatformHelpers *platformHelpers) {
if (!platformHelpers)
return "";
return platformHelpers->getDataPath();
}
string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
if (!platformHelper)
return Utils::getEmptyConstRefObject<string>();
return platformHelper->getConfigPath();
string SysPaths::getConfigPath (PlatformHelpers *platformHelpers) {
if (!platformHelpers)
return "";
return platformHelpers->getConfigPath();
}
LINPHONE_END_NAMESPACE

View file

@ -31,8 +31,8 @@ LINPHONE_BEGIN_NAMESPACE
class PlatformHelpers;
namespace SysPaths {
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper);
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper);
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelpers);
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelpers);
}
LINPHONE_END_NAMESPACE

View file

@ -31,8 +31,8 @@ LINPHONE_BEGIN_NAMESPACE
class PlatformHelpers;
namespace SysPaths {
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper);
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper);
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelpers);
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelpers);
}
LINPHONE_END_NAMESPACE

View file

@ -17,54 +17,50 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#import "linphone/utils/utils.h"
#import "core/platform-helpers/platform-helpers.h"
#import "logger/logger.h"
#import "paths-apple.h"
#import <Foundation/Foundation.h>
#import "logger/logger.h"
#import "paths-apple.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
std::string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
std::string SysPaths::getDataPath (PlatformHelpers *) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *writablePath = [paths objectAtIndex:0];
NSString *fullPath = [writablePath stringByAppendingString:@"/linphone/"];
if(![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
NSError *error;
lInfo() << "Data path " << fullPath.UTF8String << " does not exist, creating it.";
if (![[NSFileManager defaultManager] createDirectoryAtPath:fullPath
withIntermediateDirectories:YES
attributes:nil
error:&error]) {
lError() << "Create data path directory error: " << error.description;
withIntermediateDirectories:YES
attributes:nil
error:&error]) {
lError() << "Create data path directory error: " << error.description;
}
}
const char *ret = fullPath.UTF8String;
return ret;
return fullPath.UTF8String;
}
std::string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
std::string SysPaths::getConfigPath (PlatformHelpers *) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *configPath = [paths objectAtIndex:0];
NSString *fullPath = [configPath stringByAppendingString:@"/Preferences/linphone/"];
if(![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
NSError *error;
lInfo() << "Config path " << fullPath.UTF8String << " does not exist, creating it.";
if (![[NSFileManager defaultManager] createDirectoryAtPath:fullPath
withIntermediateDirectories:YES
attributes:nil
error:&error]) {
lError() << "Create config path directory error: " << error.description;
withIntermediateDirectories:YES
attributes:nil
error:&error]) {
lError() << "Create config path directory error: " << error.description;
}
}
const char *ret = fullPath.UTF8String;
return ret;
return fullPath.UTF8String;
}
LINPHONE_END_NAMESPACE

View file

@ -17,9 +17,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/utils/utils.h"
#include "core/platform-helpers/platform-helpers.h"
#include "logger/logger.h"
#include "paths-linux.h"
@ -41,12 +38,12 @@ static string getBaseDirectory () {
return base;
}
string SysPaths::getDataPath (PlatformHelpers *platformHelper) {
string SysPaths::getDataPath (PlatformHelpers *) {
static string dataPath = getBaseDirectory() + "/.local/share/linphone/";
return dataPath;
}
string SysPaths::getConfigPath (PlatformHelpers *platformHelper) {
string SysPaths::getConfigPath (PlatformHelpers *) {
static string configPath = getBaseDirectory() + "/.config/linphone/";
return configPath;
}

View file

@ -31,8 +31,8 @@ LINPHONE_BEGIN_NAMESPACE
class PlatformHelpers;
namespace SysPaths {
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelper);
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelper);
LINPHONE_PUBLIC std::string getDataPath (PlatformHelpers *platformHelpers);
LINPHONE_PUBLIC std::string getConfigPath (PlatformHelpers *platformHelpers);
}
LINPHONE_END_NAMESPACE

View file

@ -38,12 +38,12 @@ using namespace std;
LINPHONE_BEGIN_NAMESPACE
string Paths::getPath (Paths::Type type, PlatformHelpers *platformHelper) {
string Paths::getPath (Paths::Type type, PlatformHelpers *platformHelpers) {
switch (type) {
case Data:
return SysPaths::getDataPath(platformHelper);
return SysPaths::getDataPath(platformHelpers);
case Config:
return SysPaths::getConfigPath(platformHelper);
return SysPaths::getConfigPath(platformHelpers);
}
L_ASSERT(false);

View file

@ -35,7 +35,7 @@ namespace Paths {
Config
};
LINPHONE_PUBLIC std::string getPath (Type type, PlatformHelpers *platformHelper);
LINPHONE_PUBLIC std::string getPath (Type type, PlatformHelpers *platformHelpers);
}
LINPHONE_END_NAMESPACE