mirror of
https://github.com/leozide/leocad.git
synced 2026-07-27 19:56:49 +00:00
Load color config from library.
This commit is contained in:
@@ -70,6 +70,8 @@ bool lcApplication::LoadPiecesLibrary(const char* LibPath, const char* SysLibPat
|
||||
if (m_Library->Load(SysLibPath))
|
||||
return true;
|
||||
|
||||
lcLoadDefaultColors();
|
||||
|
||||
#ifdef LC_WINDOWS
|
||||
SystemDoMessageBox("Cannot load pieces library.\n"
|
||||
"Make sure that you have the PIECES.IDX file in the same "
|
||||
@@ -130,8 +132,6 @@ bool lcApplication::Initialize(int argc, char* argv[], const char* SysLibPath)
|
||||
int ImageEnd = 0;
|
||||
char* ImageName = NULL;
|
||||
|
||||
lcLoadDefaultColors();
|
||||
|
||||
// File to open.
|
||||
char* ProjectName = NULL;
|
||||
|
||||
|
||||
@@ -195,12 +195,14 @@ static void GetToken(char*& Ptr, char* Token)
|
||||
*Token = 0;
|
||||
}
|
||||
|
||||
static void LoadColorFile(lcFile& File)
|
||||
bool lcLoadColorFile(lcFile& File)
|
||||
{
|
||||
char Line[1024], Token[1024];
|
||||
ObjArray<lcColor>& Colors = gColorList;
|
||||
lcColor Color, MainColor, EdgeColor;
|
||||
|
||||
Colors.RemoveAll();
|
||||
|
||||
strcpy(gColorGroups[0].Name, "Solid Colors");
|
||||
strcpy(gColorGroups[1].Name, "Translucent Colors");
|
||||
strcpy(gColorGroups[2].Name, "Special Colors");
|
||||
@@ -387,6 +389,8 @@ static void LoadColorFile(lcFile& File)
|
||||
|
||||
gEdgeColor = Colors.GetSize();
|
||||
Colors.Add(EdgeColor);
|
||||
|
||||
return Colors.GetSize() > 2;
|
||||
}
|
||||
|
||||
void lcLoadDefaultColors()
|
||||
@@ -394,7 +398,7 @@ void lcLoadDefaultColors()
|
||||
lcMemFile File;
|
||||
File.WriteBuffer(sDefaultColorConfig, sizeof(sDefaultColorConfig));
|
||||
File.Seek(0, SEEK_SET);
|
||||
LoadColorFile(File);
|
||||
lcLoadColorFile(File);
|
||||
}
|
||||
|
||||
int lcGetColorIndex(lcuint32 ColorCode)
|
||||
|
||||
@@ -38,6 +38,7 @@ extern int gEdgeColor;
|
||||
extern int gDefaultColor;
|
||||
|
||||
void lcLoadDefaultColors();
|
||||
bool lcLoadColorFile(lcFile& File);
|
||||
int lcGetColorIndex(lcuint32 ColorCode);
|
||||
|
||||
inline lcuint32 lcGetColorCodeFromExtendedColor(int Color)
|
||||
|
||||
+19
-3
@@ -54,9 +54,25 @@ bool lcPiecesLibrary::Load(const char* SearchPath)
|
||||
strcpy(mLibraryPath, LibraryPath);
|
||||
strcat(LibraryPath, "complete.zip");
|
||||
|
||||
if (!OpenArchive(LibraryPath))
|
||||
if (!OpenDirectory(mLibraryPath))
|
||||
return false;
|
||||
if (OpenArchive(LibraryPath))
|
||||
{
|
||||
lcMemFile ColorFile;
|
||||
|
||||
if (!mZipFile->ExtractFile("ldraw/ldconfig.ldr", ColorFile) || !lcLoadColorFile(ColorFile))
|
||||
lcLoadDefaultColors();
|
||||
}
|
||||
else if (OpenDirectory(mLibraryPath))
|
||||
{
|
||||
char FileName[LC_MAXPATH];
|
||||
lcDiskFile ColorFile;
|
||||
|
||||
sprintf(FileName, "%sldconfig.ldr", mLibraryPath);
|
||||
|
||||
if (!ColorFile.Open(FileName, "rt") || !lcLoadColorFile(ColorFile))
|
||||
lcLoadDefaultColors();
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
const char* FileName = Sys_ProfileLoadString("Settings", "Categories", "");
|
||||
if (!FileName[0] || !LoadCategories(FileName))
|
||||
|
||||
@@ -535,6 +535,19 @@ bool lcZipFile::ReadCentralDir()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool lcZipFile::ExtractFile(const char* FileName, lcMemFile& File, lcuint32 MaxLength)
|
||||
{
|
||||
for (int FileIdx = 0; FileIdx < mFiles.GetSize(); FileIdx++)
|
||||
{
|
||||
lcZipFileInfo& FileInfo = mFiles[FileIdx];
|
||||
|
||||
if (!strcmp(FileInfo.file_name, FileName))
|
||||
return ExtractFile(FileIdx, File, MaxLength);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool lcZipFile::ExtractFile(int FileIndex, lcMemFile& File, lcuint32 MaxLength)
|
||||
{
|
||||
lcuint32 SizeVar;
|
||||
|
||||
@@ -48,6 +48,7 @@ public:
|
||||
|
||||
bool Open(const char* FilePath);
|
||||
bool ExtractFile(int FileIndex, lcMemFile& File, lcuint32 MaxLength = 0xffffffff);
|
||||
bool ExtractFile(const char* FileName, lcMemFile& File, lcuint32 MaxLength = 0xffffffff);
|
||||
|
||||
ObjArray<lcZipFileInfo> mFiles;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user