Commit 988c78ae authored by Gargaj's avatar Gargaj
Browse files

move file operations to misc

parent 21170a8b
......@@ -321,7 +321,7 @@ if (APPLE)
${CMAKE_SOURCE_DIR}/src/platform_glfw/Renderer.cpp
${CMAKE_SOURCE_DIR}/src/platform_common/FFT.cpp
${CMAKE_SOURCE_DIR}/src/platform_x11/MIDI.cpp
${CMAKE_SOURCE_DIR}/src/platform_x11/Misc.cpp
${CMAKE_SOURCE_DIR}/src/platform_osx/Misc.cpp
${CMAKE_SOURCE_DIR}/src/platform_x11/Timer.cpp
${CMAKE_SOURCE_DIR}/src/platform_osx/SetupDialog.cpp
${CMAKE_SOURCE_DIR}/src/platform_osx/Clipboard.cpp
......
......@@ -5,4 +5,6 @@ namespace Misc
void InitKeymaps();
void GetKeymapName( char * sz );
bool ExecuteCommand( char * cmd, char * param );
bool FileExists(const char * path);
const char * GetDefaultFontPath();
}
\ No newline at end of file
......@@ -137,34 +137,7 @@ int main(int argc, char *argv[])
SHADEREDITOR_OPTIONS editorOptions;
editorOptions.nFontSize = 16;
#ifdef _WIN32
editorOptions.sFontPath = "c:\\Windows\\Fonts\\cour.ttf";
#elif __APPLE__
editorOptions.sFontPath = "/Library/Fonts/Courier New.ttf";
#else
// Linux case
// TODO: use fonts.conf(5) or X resources or something like that
const char* fontPaths[] = {
"/usr/share/fonts/TTF/DejaVuSansMono.ttf",
"/usr/share/fonts/TTF/FreeMono.ttf",
"/usr/share/fonts/TTF/LiberationMono-Regular.ttf",
"/usr/share/fonts/TTF/VeraMono.ttf",
"/usr/share/fonts/corefonts/cour.ttf",
"/usr/share/fonts/truetype/msttcorefonts/cour.ttf",
NULL
};
editorOptions.sFontPath = "";
for (int i = 0; fontPaths[i]; ++i)
{
if (access(fontPaths[i], R_OK) != -1)
{
editorOptions.sFontPath = fontPaths[i];
break;
}
}
// aiee - no font found, but don't report yet, it might still get changed
// though config.json
#endif
editorOptions.sFontPath = Misc::GetDefaultFontPath();
editorOptions.nOpacity = 0xC0;
editorOptions.bUseSpacesForTabs = true;
editorOptions.nTabSize = 2;
......@@ -209,18 +182,10 @@ int main(int argc, char *argv[])
if (options.get<jsonxx::Object>("font").has<jsonxx::String>("file"))
{
std::string fontpath = options.get<jsonxx::Object>("font").get<jsonxx::String>("file");
// TODO: port this to other platforms
#if !defined(_WIN32) && !defined(__APPLE__)
if (access(fontpath.c_str(), R_OK) != -1)
editorOptions.sFontPath = fontpath;
else
if (Misc::FileExists(fontpath.c_str()))
{
printf("Couldn't open the font file '%s'.\n", fontpath.c_str());
return -1;
editorOptions.sFontPath = fontpath;
}
#else
editorOptions.sFontPath = fontpath;
#endif
}
else if (!editorOptions.sFontPath.size()) // coudn't find a default font
{
......
// Dummy Keymap functions that don't actually map anything,
// just to fix the SDL build.
#include <string.h>
#include "../Misc.h"
void Misc::InitKeymaps() {
return;
}
void Misc::GetKeymapName(char* sz) {
strncpy(sz,"<native>",7);
}
bool Misc::ExecuteCommand( char * cmd, char * param )
{
return false;
}
bool Misc::FileExists(const char * path)
{
return access(path, R_OK) != -1;
}
const char * Misc::GetDefaultFontPath()
{
// Linux case
// TODO: use fonts.conf(5) or X resources or something like that
const char* fontPaths[] =
{
"/Library/Fonts/Courier New.ttf",
NULL
};
for (int i = 0; fontPaths[i]; ++i)
{
if (FileExists(fontPaths[i]))
{
return fontPaths[i];
}
}
return NULL;
}
\ No newline at end of file
......@@ -49,4 +49,24 @@ namespace Misc
HINSTANCE hI = ShellExecute( NULL, NULL, cmd, param, NULL, SW_SHOW );
return (int)hI >= 32;
}
bool FileExists(const char * path)
{
return GetFileAttributesA(path) != INVALID_FILE_ATTRIBUTES;
}
const char * GetDefaultFontPath()
{
const char* fontPaths[] =
{
"c:\\Windows\\Fonts\\cour.ttf",
NULL
};
for (int i = 0; fontPaths[i]; ++i)
{
if (FileExists(fontPaths[i]))
{
return fontPaths[i];
}
}
return NULL;
}
}
\ No newline at end of file
......@@ -14,5 +14,34 @@ void Misc::GetKeymapName(char* sz) {
bool Misc::ExecuteCommand( char * cmd, char * param )
{
return false;
return false;
}
bool Misc::FileExists(const char * path)
{
return access(path, R_OK) != -1;
}
const char * Misc::GetDefaultFontPath()
{
// Linux case
// TODO: use fonts.conf(5) or X resources or something like that
const char* fontPaths[] =
{
"/usr/share/fonts/TTF/DejaVuSansMono.ttf",
"/usr/share/fonts/TTF/FreeMono.ttf",
"/usr/share/fonts/TTF/LiberationMono-Regular.ttf",
"/usr/share/fonts/TTF/VeraMono.ttf",
"/usr/share/fonts/corefonts/cour.ttf",
"/usr/share/fonts/truetype/msttcorefonts/cour.ttf",
NULL
};
for (int i = 0; fontPaths[i]; ++i)
{
if (FileExists(fontPaths[i]))
{
return fontPaths[i];
}
}
return NULL;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment