Add System.applicationDirectory, userDirectory, etc

This commit is contained in:
Joshua Granick
2015-03-19 12:30:01 -07:00
parent afb3a5f079
commit 0f1efafea7
4 changed files with 204 additions and 4 deletions

View File

@@ -7,11 +7,23 @@
namespace lime {
enum SystemDirectory {
APPLICATION,
APPLICATION_STORAGE,
DESKTOP,
DOCUMENTS,
USER
};
class System {
public:
static const char* GetDirectory (SystemDirectory type);
static double GetTimer ();

View File

@@ -559,7 +559,14 @@ namespace lime {
}
value lime_system_gettimer () {
value lime_system_get_directory (value type) {
return alloc_string (System::GetDirectory ((SystemDirectory)val_int (type)));
}
value lime_system_get_timer () {
return alloc_float (System::GetTimer ());
@@ -757,7 +764,8 @@ namespace lime {
DEFINE_PRIM (lime_renderer_create, 1);
DEFINE_PRIM (lime_renderer_flip, 1);
DEFINE_PRIM (lime_render_event_manager_register, 2);
DEFINE_PRIM (lime_system_gettimer, 0);
DEFINE_PRIM (lime_system_get_directory, 1);
DEFINE_PRIM (lime_system_get_timer, 0);
DEFINE_PRIM (lime_text_layout_create, 3);
DEFINE_PRIM (lime_text_layout_position, 5);
DEFINE_PRIM (lime_text_layout_set_direction, 2);

View File

@@ -5,18 +5,119 @@
#endif
#ifdef HX_WINDOWS
#include <windows.h>
#include <stdio.h>
//#include <io.h>
//#include <fcntl.h>
#endif
#include <SDL_filesystem.h>
#include <SDL_rwops.h>
#include <SDL_timer.h>
#include <string>
namespace lime {
const char* System::GetDirectory (SystemDirectory type) {
switch (type) {
case APPLICATION:
// TODO: Need to get the user's company and title or package name
// previous behavior was the company + file
return SDL_GetPrefPath ("My Company", "My Awesome SDL 2 Game");
break;
case APPLICATION_STORAGE:
return SDL_GetBasePath ();
break;
case DESKTOP: {
#if defined (HX_WINRT)
Windows::Storage::StorageFolder folder = Windows::Storage::KnownFolders::HomeGroup;
std::wstring resultW (folder->Begin ());
std::string result (resultW.begin (), resultW.end ());
return result.c_str ();
#elif defined (HX_WINDOWS)
char result[MAX_PATH] = "";
SHGetFolderPath (NULL, CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT, result);
return &result;
#else
std::string result = std::string (getenv ("HOME")) + std::string ("/Desktop");
return result.c_str ();
#endif
break;
}
case DOCUMENTS: {
#if defined (HX_WINRT)
Windows::Storage::StorageFolder folder = Windows::Storage::KnownFolders::DocumentsLibrary;
std::wstring resultW (folder->Begin ());
std::string result (resultW.begin (), resultW.end ());
return result.c_str ();
#elif defined (HX_WINDOWS)
char result[MAX_PATH] = "";
SHGetFolderPath (NULL, CSIDL_MYDOCUMENTS, NULL, SHGFP_TYPE_CURRENT, result);
return &result;
#else
std::string result = std::string (getenv ("HOME")) + std::string ("/Documents");
return result.c_str ();
#endif
break;
}
case USER: {
#if defined (HX_WINRT)
Windows::Storage::StorageFolder folder = Windows::Storage::ApplicationData::Current->RoamingFolder;
std::wstring resultW (folder->Begin ());
std::string result (resultW.begin (), resultW.end ());
return result.c_str ();
#elif defined (HX_WINDOWS)
char result[MAX_PATH] = "";
SHGetFolderPath (NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, result);
return &result;
#else
std::string result = getenv ("HOME");
return result.c_str ();
#endif
break;
}
}
return 0;
}
double System::GetTimer () {
return SDL_GetTicks ();