Skip to content

Commit 0866496

Browse files
committed
Fix handling of unofficial parts when there is no LDraw directory
1 parent c76413c commit 0866496

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

Help.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,17 +1754,17 @@ <h3><a name="3dsExport">3D-Studio file:</a></h3>
17541754
scanned for unofficial parts.<br/>
17551755
You can type in a path, or hit the <i>Browse...</i> button. If you type in a
17561756
path that doesn't resolve to a zip file, you will get an error when you apply
1757-
your preferences changes.
1757+
your preferences changes.<br/>
1758+
If you do not also specify an LDraw Folder, LDView will create an Unofficial
1759+
directory alongside the zip file if Unofficial parts are automatically
1760+
downloaded.
17581761
</p>
17591762
<p>
17601763
<i>LDraw Folder</i><br/>
17611764
This allows you to manually select the LDraw folder.<br/>
17621765
You can type in a path, or hit the <i>Browse...</i> button. If you type in a
17631766
path that isn't an LDraw folder, you will get an error when you apply your
1764-
preferences changes.<br/>
1765-
Note that if you specify an LDraw Zip, the LDraw Folder is no longer required to
1766-
have parts and p subdirectories. It still must be valid, though, since that is
1767-
where automatically downloaded unofficial parts will be placed.
1767+
preferences changes.
17681768
</p>
17691769
<p>
17701770
<i><a name="ExtraDirs">Extra Search Folders/Directories</a></i><br/>

LDLib/LDrawModelViewer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4046,8 +4046,8 @@ void LDrawModelViewer::findFileAlertCallback(LDLFindFileAlert *alert)
40464046
// below).
40474047
std::string lfilename = alert->getFilename();
40484048
std::string url;
4049-
std::string partOutputFilename = LDLModel::lDrawDir();
4050-
std::string primOutputFilename = LDLModel::lDrawDir();
4049+
std::string partOutputFilename = LDLModel::unofficialDir();
4050+
std::string primOutputFilename = LDLModel::unofficialDir();
40514051
bool primitive = false;
40524052
bool part = false;
40534053
std::string partUrlBase = libraryUrl("library/unofficial/parts/");
@@ -4057,8 +4057,8 @@ void LDrawModelViewer::findFileAlertCallback(LDLFindFileAlert *alert)
40574057

40584058
replaceStringCharacter(partOutputFilename, '\\', '/');
40594059
replaceStringCharacter(primOutputFilename, '\\', '/');
4060-
partOutputFilename += "/Unofficial/parts/";
4061-
primOutputFilename += "/Unofficial/p/";
4060+
partOutputFilename += "/parts/";
4061+
primOutputFilename += "/p/";
40624062
convertStringToLower(lfilename);
40634063
replaceStringCharacter(lfilename, '\\', '/');
40644064
if (stringHasPrefix(lfilename, "48/"))

LDLoader/LDLModel.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,11 @@ time_t LDLModel::getLocalTimestamp(const std::string& lfilename)
495495
}
496496
if (localTimestamp == 0)
497497
{
498-
std::string base;
499-
combinePath(lDrawDir(), "Unofficial", base);
498+
std::string base = unofficialDir();
499+
if (base.empty())
500+
{
501+
return localTimestamp;
502+
}
500503
std::string path;
501504
combinePath(base, lfilename, path);
502505
localTimestamp = getFileTimestamp(path);
@@ -1199,6 +1202,23 @@ const char* LDLModel::lDrawDir(bool defaultValue /*= false*/)
11991202
}
12001203
}
12011204

1205+
// NOTE: static function.
1206+
std::string LDLModel::unofficialDir(void)
1207+
{
1208+
std::string dir(lDrawDir());
1209+
if (dir.empty() && !sm_ldrawZipPath.empty())
1210+
{
1211+
dir = directoryFromPath(sm_ldrawZipPath.c_str());
1212+
}
1213+
if (dir.empty())
1214+
{
1215+
return dir;
1216+
}
1217+
std::string result;
1218+
combinePath(dir.c_str(), "Unofficial", result);
1219+
return result;
1220+
}
1221+
12021222
void LDLModel::readComment(LDLCommentLine *commentLine)
12031223
{
12041224
std::string filename;

LDLoader/LDLModel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class LDLModel : public TCAlertSender
125125
virtual int loadMpdTexmaps(void);
126126

127127
static const char *lDrawDir(bool defaultValue = false);
128+
static std::string unofficialDir(void);
128129
static void setLDrawDir(const char *value);
129130
static const std::string& ldrawZipPath(void);
130131
static bool setLDrawZipPath(const std::string& value);

0 commit comments

Comments
 (0)