Initial Windows implementation of built-in library path. Part of #125

felipesanches-svg
Marius Kintel 2013-05-21 17:45:24 -04:00
parent f8622005f8
commit e2772c70b8
8 changed files with 52 additions and 15 deletions

View File

@ -384,7 +384,14 @@ macx {
src/EventFilter.h \
src/CocoaUtils.h
SOURCES += src/AppleEvents.cc
OBJECTIVE_SOURCES += src/CocoaUtils.mm
OBJECTIVE_SOURCES += src/CocoaUtils.mm \
src/PlatformUtils.mm
}
unix:!macx {
SOURCES += src/PlatformUtils-posix.cc
}
win32* {
SOURCES += src/PlatformUtils-win32.cc
}
isEmpty(PREFIX):PREFIX = /usr/local

View File

@ -1,13 +1,10 @@
#ifndef COCOAUTILS_H_
#define COCOAUTILS_H_
#include <string>
class CocoaUtils
{
public:
static void endApplication();
static std::string documentsPath();
};
#endif

View File

@ -1,6 +1,5 @@
#include "CocoaUtils.h"
#import <Foundation/Foundation.h>
#include <stdio.h>
void CocoaUtils::endApplication()
{
@ -9,7 +8,3 @@ void CocoaUtils::endApplication()
object:nil];
}
std::string CocoaUtils::documentsPath()
{
return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]);
}

View File

@ -0,0 +1,7 @@
#include "PlatformUtils.h"
std::string PlatformUtils::documentsPath()
{
// FIXME: Implement
return "";
}

View File

@ -0,0 +1,15 @@
#include "PlatformUtils.h"
#include <windows.h>
#include <shlobj.h>
std::string PlatformUtils::documentsPath()
{
std::string retval;
CHAR my_documents[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_MYDOCUMENTS, NULL,
SHGFP_TYPE_CURRENT, my_documents);
if (result != S_OK) retval = "";
else retval = my_documents;
return retval;
}

12
src/PlatformUtils.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef PLATFORMUTILS_H_
#define PLATFORMUTILS_H_
#include <string>
namespace PlatformUtils {
std::string documentsPath();
}
#endif

7
src/PlatformUtils.mm Normal file
View File

@ -0,0 +1,7 @@
#include "PlatformUtils.h"
#import <Foundation/Foundation.h>
std::string PlatformUtils::documentsPath()
{
return std::string([[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] UTF8String]);
}

View File

@ -3,9 +3,7 @@
#include <boost/foreach.hpp>
#include "boosty.h"
#include <boost/algorithm/string.hpp>
#ifdef __APPLE__
#include "CocoaUtils.h"
#endif
#include "PlatformUtils.h"
namespace fs = boost::filesystem;
@ -44,9 +42,8 @@ void parser_init(const std::string &applicationpath)
}
}
// FIXME: Add ~/.openscad/libraries
#if defined(__APPLE__) && !defined(OPENSCAD_TESTING)
fs::path docdir(CocoaUtils::documentsPath());
#ifndef OPENSCAD_TESTING
fs::path docdir(PlatformUtils::documentsPath());
add_librarydir(boosty::stringy(docdir / "OpenSCAD" / "libraries"));
#endif