Skip to content

Commit a294c78

Browse files
committed
Win: zip-based library install
1 parent b123607 commit a294c78

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

LDViewMessages.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ Sep=Sep
198198
Oct=Oct
199199
Nov=Nov
200200
Dec=Dec
201+
LDrawZipInstallDirPrompt0 =Please select the directory for the LDraw parts
202+
LDrawZipInstallDirPrompt1 =library.
201203
LDrawInstallDirPrompt0 =Please select the parent directory for the LDraw parts
202204
LDrawInstallDirPrompt1 =library.
203205
LDrawDirExistsPrompt0 =LDraw directory not found. Is the LDraw parts library
@@ -624,7 +626,7 @@ LDrawInstalled =LDraw Parts Library Installed
624626
LDrawInstalledFormat0 =The LDraw parts library was successfully downloaded and
625627
LDrawInstalledFormat1 =installed in the %@ folder.
626628
InstallZipTitle =Use Zip?
627-
InstallZipMessage0 =Do you want to leave the LDraw library in a zip file
629+
InstallZipMessage0 =Do you want to leave the LDraw library in a zip file
628630
InstallZipMessage1 =instead of extracting it?
629631

630632
; ** Cocoa ModelWindow **

LDViewWindow.cpp

+48-14
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ void LDViewWindow::showLibraryUpdateWindow(bool initialInstall)
23742374
}
23752375
}
23762376

2377-
bool LDViewWindow::installLDraw(void)
2377+
bool LDViewWindow::installLDraw(const std::string& ldrawZipPath)
23782378
{
23792379
if (libraryUpdater)
23802380
{
@@ -2383,12 +2383,19 @@ bool LDViewWindow::installLDraw(void)
23832383
}
23842384
else
23852385
{
2386-
std::string ldrawParentDir = getLDrawDir();
2387-
std::string ldrawDir = ldrawParentDir;
2386+
std::string ldrawDir;
23882387
UCCHAR originalDir[MAX_PATH];
23892388

23902389
libraryUpdateFinished = false;
2391-
ldrawDir += "\\LDRAW";
2390+
if (ldrawZipPath.empty())
2391+
{
2392+
std::string ldrawParentDir = getLDrawDir();
2393+
combinePath(ldrawParentDir, "LDRAW", ldrawDir);
2394+
}
2395+
else
2396+
{
2397+
ldrawDir = getLDrawDir();
2398+
}
23922399
GetCurrentDirectory(COUNT_OF(originalDir), originalDir);
23932400
ucstring ucLDrawDir;
23942401
utf8toucstring(ucLDrawDir, ldrawDir);
@@ -2403,6 +2410,7 @@ bool LDViewWindow::installLDraw(void)
24032410
libraryUpdater = new LDLibraryUpdater;
24042411
libraryUpdateCanceled = false;
24052412
libraryUpdater->setLibraryUpdateKey(LAST_LIBRARY_UPDATE_KEY);
2413+
libraryUpdater->setLdrawZipPath(ldrawZipPath);
24062414
libraryUpdater->setLdrawDir(ldrawDir.c_str());
24072415
libraryUpdater->installLDraw();
24082416
showLibraryUpdateWindow(true);
@@ -2417,6 +2425,16 @@ bool LDViewWindow::installLDraw(void)
24172425
}
24182426
if (libraryUpdateFinished)
24192427
{
2428+
if (ldrawZipPath.empty())
2429+
{
2430+
TCUserDefaults::removeValue(LDRAWZIP_KEY, false);
2431+
}
2432+
else
2433+
{
2434+
TCUserDefaults::setPathForKey(ldrawZipPath.c_str(), LDRAWZIP_KEY, false);
2435+
}
2436+
TCUserDefaults::setPathForKey(ldrawDir.c_str(), LDRAWDIR_KEY, false);
2437+
LDLModel::setLDrawZipPath(ldrawZipPath);
24202438
LDLModel::setLDrawDir(ldrawDir.c_str());
24212439
}
24222440
return libraryUpdateFinished;
@@ -3681,7 +3699,7 @@ BOOL LDViewWindow::verifyLDrawDir(bool forceChoose)
36813699

36823700
if (!forceChoose &&
36833701
(!TCUserDefaults::longForKey(VERIFY_LDRAW_DIR_KEY, 1, false) ||
3684-
verifyLDrawDir(lDrawDir)))
3702+
(!lDrawDir.empty() && verifyLDrawDir(lDrawDir))))
36853703
{
36863704
found = TRUE;
36873705
}
@@ -3714,22 +3732,38 @@ BOOL LDViewWindow::verifyLDrawDir(bool forceChoose)
37143732
if (MessageBox(NULL, ls(_UC("WillDownloadLDraw")),
37153733
_UC("LDView"), MB_OKCANCEL | MB_ICONINFORMATION) == IDOK)
37163734
{
3717-
LDLModel::setLDrawDir("C:\\");
3718-
if (promptForLDrawDir(
3719-
ls(_UC("LDrawInstallDirPrompt"))))
3720-
{
3721-
if (installLDraw())
3722-
{
3723-
found = true;
3724-
}
3725-
}
3735+
found = findAndInstallLDraw();
37263736
}
37273737
}
37283738
#endif // !_NO_BOOST
37293739
}
37303740
return found;
37313741
}
37323742

3743+
bool LDViewWindow::findAndInstallLDraw(void)
3744+
{
3745+
LDLModel::setLDrawDir("C:\\");
3746+
if (MessageBox(NULL, ls(_UC("InstallZipMessage")), ls(_UC("InstallZipTitle")), MB_YESNO | MB_ICONQUESTION) == IDYES)
3747+
{
3748+
if (promptForLDrawDir(ls(_UC("LDrawZipInstallDirPrompt"))))
3749+
{
3750+
std::string ldrawDir = LDLModel::lDrawDir();
3751+
std::string ldrawZipPath;
3752+
combinePath(ldrawDir, "complete.zip", ldrawZipPath);
3753+
return installLDraw(ldrawZipPath);
3754+
}
3755+
}
3756+
else
3757+
{
3758+
if (promptForLDrawDir(
3759+
ls(_UC("LDrawInstallDirPrompt"))))
3760+
{
3761+
return installLDraw();
3762+
}
3763+
}
3764+
return false;
3765+
}
3766+
37333767
std::string LDViewWindow::lastOpenPath(char* pathKey)
37343768
{
37353769
if (!pathKey)

LDViewWindow.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class LDViewWindow: public CUIWindow
115115
virtual ~LDViewWindow(void);
116116
static BOOL promptForLDrawDir(CUCSTR prompt = NULL);
117117

118+
bool findAndInstallLDraw(void);
118119
virtual void dealloc(void);
119120
virtual WNDCLASSEX getWindowClass(void);
120121
virtual bool handleDpiChange(void);
@@ -151,7 +152,7 @@ class LDViewWindow: public CUIWindow
151152
virtual void showLibraryUpdateWindow(bool initialInstall);
152153
void checkForLibraryUpdates();
153154
virtual void doLibraryUpdateFinished(int finishType);
154-
bool installLDraw();
155+
bool installLDraw(const std::string& ldrawZipPath = "");
155156
#endif // _NO_BOOST
156157
virtual BOOL doDialogCommand(HWND hDlg, int controlId, int notifyCode,
157158
HWND controlHWnd);

0 commit comments

Comments
 (0)