From c0db665346ca7be1f4b0862c6fd7ad8d2418601c Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 12 Sep 2014 22:47:08 +0000 Subject: [PATCH] Added option to set an extra path to scan for the LDraw library. --- common/lc_application.cpp | 75 ++++++++++++++++++++------------------- common/lc_application.h | 4 +-- leocad.pro | 10 ++++-- qt/qtmain.cpp | 10 ++++-- 4 files changed, 57 insertions(+), 42 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 5809bfa9..2e8a945c 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -64,55 +64,58 @@ void lcApplication::SetClipboard(lcFile* Clipboard) gMainWindow->UpdatePaste(mClipboard != NULL); } -bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* LibraryInstallPath, const char* LibraryCachePath) +bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* LibraryInstallPath, const char* LDrawPath, const char* LibraryCachePath) { if (mLibrary == NULL) mLibrary = new lcPiecesLibrary(); if (LibPath && LibPath[0]) + return mLibrary->Load(LibPath, LibraryCachePath); + + char* EnvPath = getenv("LEOCAD_LIB"); + + if (EnvPath && EnvPath[0]) { - if (mLibrary->Load(LibPath, LibraryCachePath)) - return true; + return mLibrary->Load(EnvPath, LibraryCachePath); } - else + + char CustomPath[LC_MAXPATH]; + strcpy(CustomPath, lcGetProfileString(LC_PROFILE_PARTS_LIBRARY)); + + if (CustomPath[0]) + return mLibrary->Load(CustomPath, LibraryCachePath); + + if (LibraryInstallPath && LibraryInstallPath[0]) { - char* EnvPath = getenv("LEOCAD_LIB"); + char LibraryPath[LC_MAXPATH]; - if (EnvPath && EnvPath[0]) + strcpy(LibraryPath, LibraryInstallPath); + + int i = strlen(LibraryPath) - 1; + if ((LibraryPath[i] != '\\') && (LibraryPath[i] != '/')) + strcat(LibraryPath, "/"); + + strcat(LibraryPath, "library.bin"); + + if (mLibrary->Load(LibraryPath, LibraryCachePath)) { - if (mLibrary->Load(EnvPath, LibraryCachePath)) - return true; + mLibrary->SetOfficialPieces(); + return true; } - else - { - char CustomPath[LC_MAXPATH]; + } - strcpy(CustomPath, lcGetProfileString(LC_PROFILE_PARTS_LIBRARY)); + if (LDrawPath && LDrawPath[0]) + { + char LibraryPath[LC_MAXPATH]; - if (CustomPath[0]) - { - if (mLibrary->Load(CustomPath, LibraryCachePath)) - return true; - } - else if (LibraryInstallPath && LibraryInstallPath[0]) - { - char LibraryPath[LC_MAXPATH]; + strcpy(LibraryPath, LDrawPath); - strcpy(LibraryPath, LibraryInstallPath); + int i = strlen(LibraryPath) - 1; + if ((LibraryPath[i] != '\\') && (LibraryPath[i] != '/')) + strcat(LibraryPath, "/"); - int i = strlen(LibraryPath) - 1; - if ((LibraryPath[i] != '\\') && (LibraryPath[i] != '/')) - strcat(LibraryPath, "/"); - - strcat(LibraryPath, "library.bin"); - - if (mLibrary->Load(LibraryPath, LibraryCachePath)) - { - mLibrary->SetOfficialPieces(); - return true; - } - } - } + if (mLibrary->Load(LibraryPath, LibraryCachePath)) + return true; } return false; @@ -150,7 +153,7 @@ void lcApplication::ParseStringArgument(int* CurArg, int argc, char* argv[], cha } } -bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstallPath, const char* LibraryCachePath) +bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstallPath, const char* LDrawPath, const char* LibraryCachePath) { char* LibPath = NULL; @@ -240,7 +243,7 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* LibraryInstal } } - if (!LoadPiecesLibrary(LibPath, LibraryInstallPath, LibraryCachePath)) + if (!LoadPiecesLibrary(LibPath, LibraryInstallPath, LDrawPath, LibraryCachePath)) { if (SaveImage) { diff --git a/common/lc_application.h b/common/lc_application.h index b11b183e..734920b8 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -38,11 +38,11 @@ public: lcApplication(); ~lcApplication(); - bool Initialize(int argc, char *argv[], const char* LibraryInstallPath, const char* LibraryCachePath); + bool Initialize(int argc, char *argv[], const char* LibraryInstallPath, const char* LDrawPath, const char* LibraryCachePath); void Shutdown(); void ShowPreferencesDialog(); - bool LoadPiecesLibrary(const char* LibPath, const char* LibraryInstallPath, const char* LibraryCachePath); + bool LoadPiecesLibrary(const char* LibPath, const char* LibraryInstallPath, const char* LDrawPath, const char* LibraryCachePath); void OpenURL(const char* URL); void RunProcess(const char* ExecutablePath, const lcArray& Arguments); diff --git a/leocad.pro b/leocad.pro index 4aee7126..6908b340 100644 --- a/leocad.pro +++ b/leocad.pro @@ -48,7 +48,6 @@ unix:!macx { isEmpty(DESKTOP_DIR):DESKTOP_DIR = $$INSTALL_PREFIX/share/applications isEmpty(MIME_DIR):MIME_DIR = $$INSTALL_PREFIX/share/mime/packages isEmpty(MIME_ICON_DIR):MIME_ICON_DIR = $$INSTALL_PREFIX/share/icons/hicolor/scalable/mimetypes - isEmpty(DISABLE_UPDATE_CHECK):DISABLE_UPDATE_CHECK = 0 target.path = $$BIN_DIR docs.path = $$DOCS_DIR @@ -67,7 +66,14 @@ unix:!macx { INSTALLS += target docs man desktop icon mime mime_icon DEFINES += LC_INSTALL_PREFIX=\\\"$$INSTALL_PREFIX\\\" - DEFINES += LC_DISABLE_UPDATE_CHECK=$$DISABLE_UPDATE_CHECK + + !isEmpty(DISABLE_UPDATE_CHECK) { + DEFINES += LC_DISABLE_UPDATE_CHECK=$$DISABLE_UPDATE_CHECK + } + + !isEmpty(LDRAW_LIBRARY_PATH) { + DEFINES += LC_LDRAW_LIBRARY_PATH=\\\"$$LDRAW_LIBRARY_PATH\\\" + } } macx { diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index 271d9178..6894e0f8 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -152,7 +152,13 @@ int main(int argc, char *argv[]) QByteArray pathArray = bundlePath.absolutePath().toLocal8Bit(); const char* libPath = pathArray.data(); #else - const char* libPath = LC_INSTALL_PREFIX"/share/leocad/"; + const char* libPath = LC_INSTALL_PREFIX "/share/leocad/"; +#endif + +#ifdef LC_LDRAW_LIBRARY_PATH + const char* LDrawPath = LC_LDRAW_LIBRARY_PATH; +#else + const char* LDrawPath = NULL; #endif #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) @@ -165,7 +171,7 @@ int main(int argc, char *argv[]) QDir dir; dir.mkpath(cachePath); - if (!g_App->Initialize(argc, argv, libPath, cachePath.toLocal8Bit().data())) + if (!g_App->Initialize(argc, argv, libPath, LDrawPath, cachePath.toLocal8Bit().data())) return 1; lcQMainWindow w;