summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/defines.h5
-rw-r--r--common/file.cpp19
-rw-r--r--common/file.h25
-rw-r--r--common/keyboard.cpp2
-rw-r--r--common/libman.cpp409
-rw-r--r--common/libman.h81
-rwxr-xr-xcommon/library.cpp559
-rwxr-xr-xcommon/library.h74
-rw-r--r--common/project.cpp6
-rw-r--r--common/typedefs.h14
10 files changed, 389 insertions, 805 deletions
diff --git a/common/defines.h b/common/defines.h
index e5e7e7d..d1b50a7 100644
--- a/common/defines.h
+++ b/common/defines.h
@@ -92,6 +92,11 @@ int stricmp(const char* str1, const char* str2);
#define M_PI 3.14159265
#endif
+#define LC_FOURCC(ch0, ch1, ch2, ch3) (lcuint32)((lcuint32)(lcuint8)(ch0) | ((lcuint32)(lcuint8)(ch1) << 8) | \
+ ((lcuint32)(lcuint8)(ch2) << 16) | ((lcuint32)(lcuint8)(ch3) << 24 ))
+
+#define LC_FILE_ID LC_FOURCC('L','C','D', 0)
+
#define LC_CONNECTIONS 2 // Different piece connections
#define LC_STR_VERSION "LeoCAD 0.7 Project\0\0" // char[20]
diff --git a/common/file.cpp b/common/file.cpp
index 8962401..23825ca 100644
--- a/common/file.cpp
+++ b/common/file.cpp
@@ -9,6 +9,7 @@
#include "file.h"
#include "defines.h"
#include "config.h"
+#include "str.h"
// =============================================================================
// File construction/destruction
@@ -243,6 +244,20 @@ unsigned long File::WriteDouble (const void* pBuf, unsigned long nCount)
#endif
}
+void File::ReadString(String& Value)
+{
+ lcuint32 l;
+ ReadInt(&l);
+ Read(Value.GetBuffer(l+1), l);
+ ((char*)Value)[l] = 0;
+}
+
+void File::WriteString(const String& Value)
+{
+ WriteInt(Value.GetLength());
+ Write((const char*)Value, Value.GetLength());
+}
+
// =============================================================================
FileMem::FileMem()
@@ -281,7 +296,7 @@ FileDisk::~FileDisk()
/////////////////////////////////////////////////////////////////////////////
// File operations
-char* FileMem::ReadString(char* pBuf, unsigned long nMax)
+char* FileMem::ReadLine(char* pBuf, unsigned long nMax)
{
int nRead = 0;
unsigned char ch;
@@ -308,7 +323,7 @@ char* FileMem::ReadString(char* pBuf, unsigned long nMax)
return pBuf;
}
-char* FileDisk::ReadString(char* pBuf, unsigned long nMax)
+char* FileDisk::ReadLine(char* pBuf, unsigned long nMax)
{
return fgets(pBuf, nMax, m_hFile);
}
diff --git a/common/file.h b/common/file.h
index d891e9c..b662bdd 100644
--- a/common/file.h
+++ b/common/file.h
@@ -4,6 +4,9 @@
#include <stdio.h>
#include <string.h>
#include "defines.h"
+#include "config.h"
+
+class String;
class File
{
@@ -19,7 +22,7 @@ public:
virtual void SetLength(unsigned long nNewLen) = 0;
virtual unsigned long GetLength() const = 0;
- virtual char* ReadString(char* pBuf, unsigned long nMax)=0;
+ virtual char* ReadLine(char* pBuf, unsigned long nMax)=0;
virtual unsigned long Read(void* pBuf, unsigned long nCount)=0;
virtual unsigned long Write(const void* pBuf, unsigned long nCount)=0;
virtual int GetChar()=0;
@@ -36,15 +39,27 @@ public:
unsigned long WriteFloat(const void* pBuf, unsigned long nCount);
unsigned long WriteDouble(const void* pBuf, unsigned long nCount);
+ void ReadString(String& Value);
+ void ReadInt(lcint32* Value)
+ { ReadLong(Value, 1); }
+ void ReadInt(lcuint32* Value)
+ { ReadLong(Value, 1); }
+
+ void WriteString(const String& Value);
+ void WriteInt(lcint32 Value)
+ { WriteLong(&Value, 1); }
+ void WriteInt(lcuint32 Value)
+ { WriteLong(&Value, 1); }
+
virtual void Abort()=0;
virtual void Flush()=0;
virtual void Close()=0;
const char* GetFileName() const
- { return FileName; }
+ { return FileName; }
void SetFileName(const char* Name)
- { strncpy(FileName, Name, LC_MAXPATH); }
+ { strncpy(FileName, Name, LC_MAXPATH); }
protected:
char FileName[LC_MAXPATH];
@@ -64,7 +79,7 @@ public:
void SetLength(unsigned long nNewLen);
unsigned long GetLength() const;
- char* ReadString(char* pBuf, unsigned long nMax);
+ char* ReadLine(char* pBuf, unsigned long nMax);
unsigned long Read(void* pBuf, unsigned long nCount);
unsigned long Write(const void* pBuf, unsigned long nCount);
int GetChar();
@@ -100,7 +115,7 @@ public:
void SetLength(unsigned long nNewLen);
unsigned long GetLength() const;
- char* ReadString(char* pBuf, unsigned long nMax);
+ char* ReadLine(char* pBuf, unsigned long nMax);
unsigned long Read(void* pBuf, unsigned long nCount);
unsigned long Write(const void* pBuf, unsigned long nCount);
int GetChar();
diff --git a/common/keyboard.cpp b/common/keyboard.cpp
index c001af0..ceff07c 100644
--- a/common/keyboard.cpp
+++ b/common/keyboard.cpp
@@ -206,7 +206,7 @@ bool LoadKeyboardShortcuts(const char* FileName)
}
char Line[1024];
- while (f.ReadString(Line, 1024))
+ while (f.ReadLine(Line, 1024))
{
char* ptr = strchr(Line, '=');
diff --git a/common/libman.cpp b/common/libman.cpp
deleted file mode 100644
index fd5145b..0000000
--- a/common/libman.cpp
+++ /dev/null
@@ -1,409 +0,0 @@
-//
-// Handle all commands from the Pieces Library Manager
-//
-
-#include <string.h>
-#include "libman.h"
-#include "library.h"
-#include "pieceinf.h"
-#include "globals.h"
-#include "project.h"
-#include "system.h"
-
-LibraryManager::LibraryManager ()
-{
- m_nPieces = 0;
- m_pPieces = NULL;
- m_nGroups = 0;
- m_bModified = false;
- strcpy (m_strFile, "");
-
- Initialize ();
-}
-
-LibraryManager::~LibraryManager ()
-{
- free (m_pPieces);
-}
-
-bool LibraryManager::Initialize ()
-{
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
- int i;
-
- m_nPieces = pLib->GetPieceCount();
- m_pPieces = (LC_LIBDLG_PIECEINFO*) malloc (sizeof (LC_LIBDLG_PIECEINFO) * m_nPieces);
-
- for (i = 0; i < m_nPieces; i++)
- {
- m_pPieces[i].Info = pLib->GetPieceInfo (i);
- m_pPieces[i].CurrentGroups = m_pPieces[i].Info->m_nGroups;
- }
-
- m_nGroups = pLib->GetGroupCount();
- for (i = 0; i < m_nGroups; i++)
- m_strGroups[i] = pLib->GetGroup(i);
-
- return true;
-}
-
-void LibraryManager::LoadDefaults ()
-{
- strcpy (m_strFile, "");
-
- strcpy (m_strGroups[0], "Plates");
- strcpy (m_strGroups[1], "Bricks");
- strcpy (m_strGroups[2], "Tiles");
- strcpy (m_strGroups[3], "Slope Bricks");
- strcpy (m_strGroups[4], "Technic");
- strcpy (m_strGroups[5], "Space");
- strcpy (m_strGroups[6], "Train");
- strcpy (m_strGroups[7], "Other Bricks");
- strcpy (m_strGroups[8], "Accessories");
- m_nGroups = 9;
-
- for (int i = 0; i < m_nPieces; i++)
- m_pPieces[i].CurrentGroups = PiecesLibrary::GetDefaultPieceGroup (m_pPieces[i].Info->m_strName);
-}
-
-void LibraryManager::HandleCommand (int id, int param)
-{
- switch (id)
- {
- case LC_LIBDLG_FILE_RESET:
- {
- LoadDefaults ();
- m_bModified = true;
- } break;
-
- case LC_LIBDLG_FILE_OPEN:
- break;
-
- case LC_LIBDLG_FILE_SAVE:
- break;
-
- case LC_LIBDLG_FILE_SAVEAS:
- break;
-
- case LC_LIBDLG_FILE_MERGEUPDATE:
- {
- LC_FILEOPENDLG_OPTS opts;
-
- strcpy (opts.path, "");
- opts.type = LC_FILEOPENDLG_LUP;
-
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, &opts))
- return;
-
- project->GetPiecesLibrary ()->LoadUpdate (opts.filenames[0]);
-
- free (opts.filenames[0]);
- free (opts.filenames);
-
- // FIXME: update m_pPieces
- } break;
-
- case LC_LIBDLG_FILE_IMPORTPIECE:
- {
- LC_FILEOPENDLG_OPTS opts;
-
- strcpy(opts.path, Sys_ProfileLoadString ("Default", "LDraw Pieces Path", ""));
- opts.type = LC_FILEOPENDLG_DAT;
-
- if (!SystemDoDialog (LC_DLG_FILE_OPEN, &opts))
- return;
-
- for (int i = 0; i < opts.numfiles; i++)
- {
- project->GetPiecesLibrary ()->ImportLDrawPiece (opts.filenames[i]);
- free (opts.filenames[i]);
- }
-
- free (opts.filenames);
- Sys_ProfileSaveString ("Default", "LDraw Pieces Path", opts.path);
-
- // FIXME: update m_pPieces
- } break;
-
- case LC_LIBDLG_FILE_RETURN:
- break;
-
- case LC_LIBDLG_FILE_CANCEL:
- break;
-
- case LC_LIBDLG_GROUP_INSERT:
- {
- char Name[64];
- int i, Idx = (int)param;
-
- if (m_nGroups == LC_PIECESLIB_MAXGROUPS)
- {
- SystemDoMessageBox ("Cannot add more groups!", LC_MB_OK|LC_MB_ICONINFORMATION);
- return;
- }
-
- strcpy (Name, "New Group");
-
- if (!SystemDoDialog (LC_DLG_GROUP, Name))
- return;
-
- for (i = m_nGroups; i > Idx; i--)
- m_strGroups[i] = m_strGroups[i-1];
-
- m_strGroups[i] = Name;
-
- for (int j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
-
- for (i = m_nGroups; i >= Idx; i--)
- {
- lcuint32 d = (1 << i);
- if (grp & d)
- {
- grp &= ~d;
- grp |= (1 << (i+1));
- }
- }
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_nGroups++;
- m_bModified = true;
-
- } break;
-
- case LC_LIBDLG_GROUP_DELETE:
- {
- int i, j;
-
- if (SystemDoMessageBox ("Are you sure you want to delete this group ?", LC_MB_YESNO|LC_MB_ICONQUESTION) != LC_YES)
- return;
-
- for (i = param; i < (m_nGroups - 1); i++)
- m_strGroups[i] = m_strGroups[i+1];
-
- for (j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
-
- // Remove from the group
- if (grp & (1 << param))
- grp &= ~(1 << param);
-
- // Shift other groups
- for (i = param+1; i < m_nGroups; i++)
- {
- lcuint32 d = (1 << i);
-
- if (grp & d)
- {
- grp &= ~d;
- grp |= (1 << (i-1));
- }
- }
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_bModified = true;
- m_nGroups--;
- } break;
-
- case LC_LIBDLG_GROUP_EDIT:
- {
- // TODO: Make this a group edit dialog where you can choose the icon.
- char Name[64];
- int i = (int)param;
-
- strcpy (Name, m_strGroups[i]);
-
- if (!SystemDoDialog (LC_DLG_GROUP, Name))
- return;
-
- m_strGroups[i] = Name;
- m_bModified = true;
- } break;
-
- case LC_LIBDLG_GROUP_MOVEUP:
- {
- String tmp;
- int j;
-
- if (param < 1)
- return;
-
- tmp = m_strGroups[param];
- m_strGroups[param] = m_strGroups[param-1];
- m_strGroups[param-1] = tmp;
-
- for (j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
- bool g1 = (grp & (1 << param)) != 0;
- bool g2 = (grp & (1 << (param-1))) != 0;
-
- if (g1)
- grp |= (1 << (param-1));
- else
- grp &= ~(1 << (param-1));
-
- if (g2)
- grp |= (1 << param);
- else
- grp &= ~(1 << param);
-
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_bModified = true;
- } break;
-
- case LC_LIBDLG_GROUP_MOVEDOWN:
- {
- String tmp;
- int j;
-
- if (param < 1)
- return;
-
- tmp = m_strGroups[param];
- m_strGroups[param] = m_strGroups[param+1];
- m_strGroups[param+1] = tmp;
-
- for (j = 0; j < m_nPieces; j++)
- {
- lcuint32 grp = m_pPieces[j].CurrentGroups;
- bool g1 = (grp & (1 << param)) != 0;
- bool g2 = (grp & (1 << (param+1))) != 0;
-
- if (g1)
- grp |= (1 << (param+1));
- else
- grp &= ~(1 << (param+1));
-
- if (g2)
- grp |= (1 << param);
- else
- grp &= ~(1 << param);
-
- m_pPieces[j].CurrentGroups = grp;
- }
-
- m_bModified = true;
- } break;
- }
-}
-
-bool LibraryManager::DeletePieces (char** Names, int Count)
-{
- if (SystemDoMessageBox ("Are you sure you want to permanently delete the selected pieces?", LC_MB_YESNO|LC_MB_ICONQUESTION) != LC_YES)
- return false;
-
- project->GetPiecesLibrary ()->DeletePieces (Names, Count);
-
- // Delete pieces from our list
- for (int i = 0; i < Count; i++)
- {
- for (int j = 0; j < m_nPieces; j++)
- {
- if (!strcmp (Names[i], m_pPieces[j].Info->m_strName))
- {
- for (int k = j; k < m_nPieces; k++)
- {
- m_pPieces[k].Info = m_pPieces[k+1].Info;
- m_pPieces[k].CurrentGroups = m_pPieces[k+1].CurrentGroups;
- }
-
- m_nPieces--;
- break;
- }
- }
- }
-
- return true;
-}
-
-// Returns true if it's ok to continue.
-bool LibraryManager::SaveModified ()
-{
- if (m_bModified)
- {
- switch (SystemDoMessageBox ("Save changes ?", LC_MB_YESNOCANCEL|LC_MB_ICONQUESTION))
- {
- case LC_CANCEL:
- return false; // don't continue
- break;
-
- case LC_YES:
- // If so, either Save or Update, as appropriate
- if (!DoSave (false))
- return false; // don't continue
- break;
-
- case LC_NO:
- // Not saving changes
- return true;
- break;
- }
-
- // Apply changes
- Sys_ProfileSaveString ("Settings", "Groups", m_strFile);
- project->GetPiecesLibrary ()->LoadGroupConfig (m_strFile);
- }
-
- project->GetPiecesLibrary ()->CheckReload ();
-
- return true; // keep going
-}
-
-bool LibraryManager::DoSave (bool bAskName)
-{
- /*
- if (bAskName || (strlen (m_strFile) == 0))
- {
- char filename[LC_MAXPATH];
-
- // CFileDialog dlg(FALSE, ".lgf\0", NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- // "LeoCAD Group Files (*.lgf)|*.lgf|All Files (*.*)|*.*||",this);
-// FIXME: file extension
- if (!SystemDoDialog (LC_DLG_FILE_SAVE, filename))
- return false;
- strcpy (m_strFile, filename);
- }
-*/
- /*
- Sys_BeginWait ();
- FileDisk f;
- int i;
-
- if (!f.Open (m_strFile, "wb"))
- return false;
-
- f.Write (ver_str, sizeof (ver_str));
- f.Write (ver_flt, sizeof (ver_flt));
- f.WriteByte (&m_nMaxGroups);
-
- for (i = 0; i < m_nMaxGroups; i++)
- {
- f.Write (m_strGroups[i], sizeof(m_strGroups[i]));
- ar << m_nBitmaps[i];
- }
-
- m_ImageList.Write(&ar);
-
- ar << (int) m_Parts.GetSize();
- for (i = 0; i < m_Parts.GetSize(); i++)
- {
- ar.Write (m_Parts[i].info->m_strName, sizeof(m_Parts[i].info->m_strName));
- ar << m_Parts[i].group;
- }
- ar.Close();
- f.Close();
- m_bModified = FALSE;
-// m_bLoaded = TRUE;
-
- fclose (f);
- Sys_EndWait ();
- */
- return true;
-}
diff --git a/common/libman.h b/common/libman.h
deleted file mode 100644
index ac48c1b..0000000
--- a/common/libman.h
+++ /dev/null
@@ -1,81 +0,0 @@
-#ifndef _LIBMAN_H_
-#define _LIBMAN_H_
-
-#include "defines.h"
-#include "config.h"
-#include "str.h"
-#include "library.h"
-
-class PieceInfo;
-
-typedef enum
-{
- LC_LIBDLG_FILE_RESET,
- LC_LIBDLG_FILE_OPEN,
- LC_LIBDLG_FILE_SAVE,
- LC_LIBDLG_FILE_SAVEAS,
- LC_LIBDLG_FILE_MERGEUPDATE,
- LC_LIBDLG_FILE_IMPORTPIECE,
- LC_LIBDLG_FILE_RETURN,
- LC_LIBDLG_FILE_CANCEL,
- LC_LIBDLG_GROUP_INSERT,
- LC_LIBDLG_GROUP_DELETE,
- LC_LIBDLG_GROUP_EDIT,
- LC_LIBDLG_GROUP_MOVEUP,
- LC_LIBDLG_GROUP_MOVEDOWN
-} LC_LIBDLG_COMMANDS;
-
-class LibraryManager
-{
-public:
- LibraryManager ();
- virtual ~LibraryManager ();
-
- void HandleCommand (int id, int param);
- bool Initialize ();
- bool DoSave (bool bAskName);
- bool SaveModified ();
-
- // Commands
- bool DeletePieces (char** Names, int Count);
-
- // Access
- int GetGroupCount () const
- { return m_nGroups; }
- String& GetGroupName (int index)
- { return m_strGroups[index]; }
-
- int GetPieceCount () const
- { return m_nPieces; }
- void GetPieceInfo (int index, PieceInfo** Info, lcuint32* Group)
- { *Info = m_pPieces[index].Info; *Group = m_pPieces[index].CurrentGroups; }
- void SetPieceGroup (int Index, int Group, bool Add)
- {
- if (Add)
- m_pPieces[Index].CurrentGroups = Group;
- else
- m_pPieces[Index].CurrentGroups |= Group;
-
- m_bModified = true;
- }
-
-protected:
- void LoadDefaults ();
-
- typedef struct
- {
- PieceInfo* Info;
- lcuint32 CurrentGroups;
- } LC_LIBDLG_PIECEINFO;
-
- int m_nPieces;
- LC_LIBDLG_PIECEINFO* m_pPieces;
-
- int m_nGroups;
- String m_strGroups[LC_PIECESLIB_MAXGROUPS];
-
- bool m_bModified;
- char m_strFile[LC_MAXPATH];
-};
-
-#endif // _LIBMAN_H_
diff --git a/common/library.cpp b/common/library.cpp
index dfc7619..4da81b9 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -22,137 +22,114 @@ const char PiecesLibrary::TexturesBinHeader[32] = "LeoCAD texture data file\0\0\
const char PiecesLibrary::TexturesIdxHeader[32] = "LeoCAD texture index file\0\0\0\0\0\0";
const int PiecesLibrary::TexturesFileVersion = 1;
-PiecesLibrary::PiecesLibrary ()
+PiecesLibrary::PiecesLibrary()
{
- strcpy (m_LibraryPath, "");
- m_pMovedReference = NULL;
- m_nMovedCount = 0;
- m_pPieceIdx = NULL;
- m_nPieceCount = 0;
- m_pTextures = NULL;
- m_nTextureCount = 0;
- m_bNeedsReload = false;
+ strcpy(m_LibraryPath, "");
+ strcpy(m_CategoriesFile, "");
+ m_pMovedReference = NULL;
+ m_nMovedCount = 0;
+ m_pPieceIdx = NULL;
+ m_nPieceCount = 0;
+ m_pTextures = NULL;
+ m_nTextureCount = 0;
+ m_Modified = false;
+ m_CategoriesModified = false;
}
-PiecesLibrary::~PiecesLibrary ()
+PiecesLibrary::~PiecesLibrary()
{
- Unload ();
-}
-
-void PiecesLibrary::CheckReload ()
-{
- char LibraryPath[LC_MAXPATH];
-
- strcpy (LibraryPath, m_LibraryPath);
-
- if (m_bNeedsReload)
- {
- // FIXME: project will crash if we don't update the pieceinfos
-
- Unload ();
- Load (LibraryPath);
- }
+ Unload();
}
void PiecesLibrary::Unload ()
{
- strcpy (m_LibraryPath, "");
+ strcpy(m_LibraryPath, "");
- free (m_pMovedReference);
- m_pMovedReference = NULL;
- m_nMovedCount = 0;
+ free(m_pMovedReference);
+ m_pMovedReference = NULL;
+ m_nMovedCount = 0;
- delete [] m_pPieceIdx;
- m_pPieceIdx = NULL;
- m_nPieceCount = 0;
+ delete [] m_pPieceIdx;
+ m_pPieceIdx = NULL;
+ m_nPieceCount = 0;
- delete [] m_pTextures;
- m_pTextures = NULL;
- m_nTextureCount = 0;
+ delete [] m_pTextures;
+ m_pTextures = NULL;
+ m_nTextureCount = 0;
}
bool PiecesLibrary::Load (const char *libpath)
{
- FileDisk idx, bin;
- char filename[LC_MAXPATH];
- lcuint16 count, movedcount;
- lcuint32 binsize;
- Texture* pTexture;
- int i;
+ FileDisk idx, bin;
+ char filename[LC_MAXPATH];
+ lcuint16 count, movedcount;
+ lcuint32 binsize;
+ Texture* pTexture;
+ int i;
- strcpy (m_LibraryPath, libpath);
+ strcpy (m_LibraryPath, libpath);
- // Make sure that the path ends with a '/'
- i = strlen(m_LibraryPath)-1;
- if ((m_LibraryPath[i] != '\\') && (m_LibraryPath[i] != '/'))
- strcat(m_LibraryPath, "/");
+ // Make sure that the path ends with a '/'
+ i = strlen(m_LibraryPath)-1;
+ if ((m_LibraryPath[i] != '\\') && (m_LibraryPath[i] != '/'))
+ strcat(m_LibraryPath, "/");
- // Read the piece library index.
- strcpy (filename, m_LibraryPath);
- strcat (filename, "pieces.idx");
+ // Read the piece library index.
+ strcpy (filename, m_LibraryPath);
+ strcat (filename, "pieces.idx");
- if (!idx.Open (filename, "rb"))
+ if (!idx.Open (filename, "rb"))
{
console.PrintError ("Cannot open Pieces Library file: %s.\n", filename);
- return false;
+ return false;
}
- strcpy (filename, m_LibraryPath);
- strcat (filename, "pieces.bin");
+ strcpy (filename, m_LibraryPath);
+ strcat (filename, "pieces.bin");
- if (!bin.Open (filename, "rb"))
+ if (!bin.Open (filename, "rb"))
{
console.PrintError ("Cannot open Pieces Library file: %s.\n", filename);
- return false;
+ return false;
}
if (!ValidatePiecesFile (idx, bin))
return false;
- idx.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
- idx.ReadShort (&movedcount, 1);
- idx.ReadLong (&binsize, 1);
- idx.ReadShort (&count, 1);
- idx.Seek (34, SEEK_SET);
-
- // Load piece indexes
- delete [] m_pPieceIdx;
- m_pPieceIdx = new PieceInfo[count];
- m_nPieceCount = count;
-
- for (PieceInfo *pElements = m_pPieceIdx; count--; pElements++)
- pElements->LoadIndex (idx);
-
- // Load moved files reference.
- if (m_pMovedReference != NULL)
- free(m_pMovedReference);
- m_pMovedReference = (char*)malloc(18*movedcount);
- memset (m_pMovedReference, 0, 18*movedcount);
- m_nMovedCount = movedcount;
-
- for (i = 0; i < movedcount; i++)
- {
- idx.Read (&m_pMovedReference[i*18], 8);
- idx.Read (&m_pMovedReference[i*18+9], 8);
- }
-
- idx.Close();
+ idx.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
+ idx.ReadShort (&movedcount, 1);
+ idx.ReadLong (&binsize, 1);
+ idx.ReadShort (&count, 1);
+ idx.Seek (34, SEEK_SET);
+
+ // Load piece indexes
+ delete [] m_pPieceIdx;
+ m_pPieceIdx = new PieceInfo[count];
+ m_nPieceCount = count;
+
+ for (PieceInfo *pElements = m_pPieceIdx; count--; pElements++)
+ pElements->LoadIndex (idx);
+
+ // Load moved files reference.
+ if (m_pMovedReference != NULL)
+ free(m_pMovedReference);
+ m_pMovedReference = (char*)malloc(18*movedcount);
+ memset (m_pMovedReference, 0, 18*movedcount);
+ m_nMovedCount = movedcount;
+
+ for (i = 0; i < movedcount; i++)
+ {
+ idx.Read (&m_pMovedReference[i*18], 8);
+ idx.Read (&m_pMovedReference[i*18+9], 8);
+ }
+
+ idx.Close();
bin.Close();
// Load groups configuration
- if (!LoadGroupConfig (Sys_ProfileLoadString ("Settings", "Groups", "")))
- {
- m_strGroups[0] = "Plates";
- m_strGroups[1] = "Bricks";
- m_strGroups[2] = "Tiles";
- m_strGroups[3] = "Slope Bricks";
- m_strGroups[4] = "Technic";
- m_strGroups[5] = "Space";
- m_strGroups[6] = "Train";
- m_strGroups[7] = "Other Bricks";
- m_strGroups[8] = "Accessories";
- m_nGroupCount = 9;
- }
+ const char* FileName = Sys_ProfileLoadString("Settings", "Categories", "");
+ if (!strlen(FileName) || !LoadCategories(FileName))
+ ResetCategories();
// Read the texture index.
strcpy(filename, m_LibraryPath);
@@ -171,13 +148,13 @@ bool PiecesLibrary::Load (const char *libpath)
return false;
}
- strcpy (filename, m_LibraryPath);
- strcat (filename, "textures.bin");
+ strcpy (filename, m_LibraryPath);
+ strcat (filename, "textures.bin");
- if (!bin.Open (filename, "rb"))
+ if (!bin.Open (filename, "rb"))
{
console.PrintError ("Cannot open Textures Library file: %s.\n", filename);
- return false;
+ return false;
}
if (!ValidateTexturesFile (idx, bin))
@@ -198,43 +175,10 @@ bool PiecesLibrary::Load (const char *libpath)
idx.Close();
bin.Close();
- // TODO: Load categories.
-
- const int NumCategories = 34;
- const char* DefaultCategories[] =
- {
- "Animal", "Antenna", "Arm", "Bar", "Baseplate", "Belville", "Boat", "Bracket", "Brick", "Car",
- "Cone", "Container", "Crane", "Cylinder", "Door", "Flag", "Hinge", "Hose", "Magnet", "Minifig",
- "Minifig Accessory", "Plane", "Plant", "Plate", "Propellor", "Rock", "Round", "Scala",
- "Slope", "Space", "Support", "Technic", "Wheel", "Windscreen"
- };
-
-
- for (i = 0; i < NumCategories; i++)
- {
- PiecesLibraryCategory Cat;
-
- Cat.Name = DefaultCategories[i];
- Cat.Keywords = DefaultCategories[i];
-
- m_Categories.Add(Cat);
- }
-
SystemUpdateCategories(false);
- m_bNeedsReload = false;
-
- return true;
-}
-
-bool PiecesLibrary::LoadGroupConfig (const char* Filename)
-{
- // FIXME:
- return false;
-
-
- strcpy (m_GroupsFile, Filename);
-
+ m_CategoriesModified = false;
+ m_Modified = false;
return true;
}
@@ -243,12 +187,12 @@ bool PiecesLibrary::LoadGroupConfig (const char* Filename)
bool PiecesLibrary::ValidatePiecesFile (File& IdxFile, File& BinFile) const
{
lcuint32 binsize, IdxPos = IdxFile.GetPosition(), BinPos = BinFile.GetPosition();
- lcuint16 count, movedcount;
+ lcuint16 count, movedcount;
lcuint8 version;
char header[32];
- IdxFile.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
- IdxFile.ReadShort (&movedcount, 1);
+ IdxFile.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
+ IdxFile.ReadShort (&movedcount, 1);
IdxFile.ReadLong (&binsize, 1);
IdxFile.ReadShort (&count, 1);
IdxFile.Seek (0, SEEK_SET);
@@ -291,7 +235,7 @@ bool PiecesLibrary::ValidatePiecesFile (File& IdxFile, File& BinFile) const
bool PiecesLibrary::ValidateTexturesFile (File& IdxFile, File& BinFile) const
{
lcuint32 binsize, IdxPos = IdxFile.GetPosition(), BinPos = BinFile.GetPosition();
- lcuint16 count;
+ lcuint16 count;
lcuint8 version;
char header[32];
@@ -340,57 +284,211 @@ bool PiecesLibrary::ValidateTexturesFile (File& IdxFile, File& BinFile) const
// Remember to make 'name' uppercase.
PieceInfo* PiecesLibrary::FindPieceInfo (const char* name) const
{
- PieceInfo* pInfo;
- int i;
+ PieceInfo* pInfo;
+ int i;
- for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
- if (!strcmp (name, pInfo->m_strName))
- return pInfo;
+ for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
+ if (!strcmp (name, pInfo->m_strName))
+ return pInfo;
- for (i = 0; i < m_nMovedCount; i++)
- {
- if (!strcmp (&m_pMovedReference[i*18], name))
- {
- char* tmp = &m_pMovedReference[i*18+9];
+ for (i = 0; i < m_nMovedCount; i++)
+ {
+ if (!strcmp (&m_pMovedReference[i*18], name))
+ {
+ char* tmp = &m_pMovedReference[i*18+9];
- for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
- if (!strcmp (tmp, pInfo->m_strName))
- return pInfo;
+ for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
+ if (!strcmp (tmp, pInfo->m_strName))
+ return pInfo;
- break; // something went wrong.
- }
- }
+ break; // something went wrong.
+ }
+ }
- return NULL;
+ return NULL;
}
-PieceInfo* PiecesLibrary::GetPieceInfo (int index) const
+PieceInfo* PiecesLibrary::GetPieceInfo(int index) const
{
- return &m_pPieceIdx[index];
+ return &m_pPieceIdx[index];
}
-int PiecesLibrary::GetPieceIndex (PieceInfo *pInfo) const
+int PiecesLibrary::GetPieceIndex(PieceInfo *pInfo) const
{
- return (((char*)pInfo - (char*)m_pPieceIdx) / sizeof (PieceInfo));
+ return (((char*)pInfo - (char*)m_pPieceIdx) / sizeof (PieceInfo));
}
-Texture* PiecesLibrary::FindTexture (const char* name) const
+Texture* PiecesLibrary::FindTexture(const char* name) const
{
- for (int i = 0; i < m_nTextureCount; i++)
- if (!strcmp (name, m_pTextures[i].m_strName))
- return &m_pTextures[i];
+ for (int i = 0; i < m_nTextureCount; i++)
+ if (!strcmp (name, m_pTextures[i].m_strName))
+ return &m_pTextures[i];
- return NULL;
+ return NULL;
}
Texture* PiecesLibrary::GetTexture (int index) const
{
- return &m_pTextures[index];
+ return &m_pTextures[index];
+}
+
+// =============================================================================
+// Category functions.
+
+void PiecesLibrary::ResetCategories()
+{
+ const int NumCategories = 34;
+ const char* DefaultCategories[] =
+ {
+ "Animal", "Antenna", "Arm", "Bar", "Baseplate", "Belville", "Boat", "Bracket", "Brick", "Car",
+ "Cone", "Container", "Crane", "Cylinder", "Door", "Flag", "Hinge", "Hose", "Magnet", "Minifig",
+ "Minifig Accessory", "Plane", "Plant", "Plate", "Propellor", "Rock", "Round", "Scala",
+ "Slope", "Space", "Support", "Technic", "Wheel", "Windscreen"
+ };
+
+ m_Categories.RemoveAll();
+ for (int i = 0; i < NumCategories; i++)
+ {
+ PiecesLibraryCategory Cat;
+
+ Cat.Name = DefaultCategories[i];
+ Cat.Keywords = DefaultCategories[i];
+
+ m_Categories.Add(Cat);
+ }
+
+ strcpy(m_CategoriesFile, "");
+ Sys_ProfileSaveString("Settings", "Categories", m_CategoriesFile);
+ m_CategoriesModified = false;
+}
+
+bool PiecesLibrary::LoadCategories(const char* FileName)
+{
+ char Path[LC_MAXPATH];
+
+ if (FileName)
+ {
+ strcpy(Path, FileName);
+ }
+ else
+ {
+ LC_FILEOPENDLG_OPTS opts;
+
+ opts.type = LC_FILEOPENDLG_LCF;
+ strcpy(opts.path, m_CategoriesFile);
+
+ if (!SystemDoDialog(LC_DLG_FILE_OPEN, &opts))
+ return false;
+
+ strcpy(Path, (char*)opts.filenames);
+
+ free(opts.filenames);
+ }
+
+ // Load the file.
+ FileDisk File;
+
+ if (!File.Open(Path, "rb"))
+ return false;
+
+ lcuint32 i;
+
+ File.ReadInt(&i);
+ if (i != LC_FILE_ID)
+ return false;
+
+ File.ReadInt(&i);
+ if (i != LC_CATEGORY_FILE_ID)
+ return false;
+
+ File.ReadInt(&i);
+ if (i != LC_CATEGORY_FILE_VERSION)
+ return false;
+
+ File.ReadInt(&i);
+ while (i--)
+ {
+ PiecesLibraryCategory Cat;
+
+ File.ReadString(Cat.Name);
+ File.ReadString(Cat.Keywords);
+
+ m_Categories.Add(Cat);
+ }
+
+ strcpy(m_CategoriesFile, Path);
+ Sys_ProfileSaveString("Settings", "Categories", m_CategoriesFile);
+ m_CategoriesModified = false;
+
+ return true;
+}
+
+// Returns true if it's ok to continue.
+bool PiecesLibrary::SaveCategories()
+{
+ if (m_CategoriesModified)
+ {
+ switch (SystemDoMessageBox("Save category changes ?", LC_MB_YESNOCANCEL|LC_MB_ICONQUESTION))
+ {
+ case LC_CANCEL:
+ return false;
+
+ case LC_YES:
+ if (!DoSaveCategories(false))
+ return false;
+ break;
+
+ case LC_NO:
+ return true;
+ break;
+ }
+ }
+
+ return true;
+}
+
+bool PiecesLibrary::DoSaveCategories(bool AskName)
+{
+ // Get the file name.
+ if (AskName || (strlen(m_CategoriesFile) == 0))
+ {
+ LC_FILESAVEDLG_OPTS opts;
+
+ opts.type = LC_FILESAVEDLG_LCF;
+ strcpy(opts.path, m_CategoriesFile);
+
+ if (!SystemDoDialog(LC_DLG_FILE_SAVE, &opts))
+ return false;
+
+ strcpy(m_CategoriesFile, opts.path);
+ }
+
+ // Save the file.
+ FileDisk File;
+
+ if (!File.Open(m_CategoriesFile, "wb"))
+ return false;
+
+ File.WriteInt(LC_FILE_ID);
+ File.WriteInt(LC_CATEGORY_FILE_ID);
+ File.WriteInt(LC_CATEGORY_FILE_VERSION);
+
+ File.WriteInt(m_Categories.GetSize());
+ for (int i = 0; i < m_Categories.GetSize(); i++)
+ {
+ File.WriteString(m_Categories[i].Name);
+ File.WriteString(m_Categories[i].Keywords);
+ }
+
+ Sys_ProfileSaveString("Settings", "Categories", m_CategoriesFile);
+ m_CategoriesModified = false;
+
+ return true;
}
// =============================================================================
-void PiecesLibrary::GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces)
+void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces)
{
bool m_bSubParts = false;
@@ -400,7 +498,9 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& S
String Keywords = m_Categories[CategoryIndex].Keywords;
Keywords.MakeLower();
- bool SearchResults = (m_Categories[CategoryIndex].Name == "Search Results");
+ // Don't group entries in the search results category.
+ if (m_Categories[CategoryIndex].Name == "Search Results")
+ GroupPieces = false;
for (int i = 0; i < m_nPieceCount; i++)
{
@@ -441,24 +541,27 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& S
if (!Match)
continue;
+ if (!GroupPieces)
+ {
+ SinglePieces.Add(Info);
+ continue;
+ }
+
// Check if it's a patterned piece.
const char* Name = Info->m_strName;
- if (!SearchResults)
+ while (*Name)
{
- while (*Name)
- {
- if (!*Name || *Name < '0' || *Name > '9')
- break;
+ if (!*Name || *Name < '0' || *Name > '9')
+ break;
- if (*Name == 'P')
- break;
+ if (*Name == 'P')
+ break;
- Name++;
- }
+ Name++;
}
- if (*Name == 'P' && !SearchResults)
+ if (*Name == 'P')
{
PieceInfo* Parent;
@@ -522,6 +625,8 @@ void PiecesLibrary::SetCategory(int Index, const String& Name, const String& Key
m_Categories[Index].Keywords = Keywords;
SystemUpdateCategories(true);
+
+ m_CategoriesModified = true;
}
void PiecesLibrary::AddCategory(const String& Name, const String& Keywords)
@@ -534,94 +639,22 @@ void PiecesLibrary::AddCategory(const String& Name, const String& Keywords)
m_Categories.Add(Cat);
SystemUpdateCategories(true);
+
+ m_CategoriesModified = true;
}
void PiecesLibrary::RemoveCategory(int Index)
{
m_Categories.RemoveIndex(Index);
-}
-
-unsigned long PiecesLibrary::GetDefaultPieceGroup (const char* name)
-{
- char tmp[9];
- strncpy(tmp, name, 9);
-// tmp[8] = 0;
-
- if (strstr(tmp,"Baseplate") || strstr(tmp,"Plate") ||
- strstr(tmp,"Platform"))
- return 0x001;
- if (strstr(tmp,"Brick") || strstr(tmp,"Cylin") ||
- strstr(tmp,"Cone"))
- return 0x002;
-
- if (strstr(tmp,"Tile"))
- return 0x004;
-
- if (strstr(tmp,"Slope"))
- return 0x008;
-
- if (strstr(tmp,"Technic") || strstr(tmp,"Crane") ||
- strstr(tmp,"Wheel") || strstr(tmp,"Tyre") ||
- strstr(tmp,"Electric"))
- return 0x010;
-
- // space & plane
- if (strstr(tmp,"Space") || strstr(tmp,"Plane") ||
- strstr(tmp,"Windscr") || strstr(tmp,"~2421") ||
- strstr(tmp,"Wing") || strstr(tmp,"Wedge") ||
- strstr(tmp,"Propellor") || strstr(tmp,"Rotor") ||
- strstr(tmp,"Rack") || strstr(tmp,"Tail") ||
- strstr(tmp,"Cockpit"))
- return 0x020;
-
- if (strstr(tmp,"Train"))
- return 0x040;
-
- // other parts
- if (strstr(tmp,"Arch") || strstr(tmp,"Panel") ||
- strstr(tmp,"Car") || strstr(tmp,"Window") ||
- strstr(tmp,"Freestyle") || strstr(tmp,"Support")||
- strstr(tmp,"Fence") || strstr(tmp,"Gate") ||
- strstr(tmp,"Garage") || strstr(tmp,"Stairs") ||
- strstr(tmp,"Bracket") || strstr(tmp,"Hinge") ||
- strstr(tmp,"Homemaker") || strstr(tmp,"Rock") ||
- strstr(tmp,"Cupboard") || strstr(tmp,"Storage")||
- strstr(tmp,"Scala") || strstr(tmp,"Boat") ||
- strstr(tmp,"Trailer") || strstr(tmp,"Box") ||
- strstr(tmp,"Turntab") || strstr(tmp,"Winch") ||
- strstr(tmp,"Door") || strstr(tmp,"Magnet") ||
- strstr(tmp,"Staircase") || strstr(tmp,"Glass") ||
- strstr(tmp,"Container"))
- return 0x080;
-
- // accessories
- if (strstr(tmp,"Minifig") || strstr(tmp,"Antenna")||
- strstr(tmp,"Ladder") || strstr(tmp,"Jack") ||
- strstr(tmp,"Exhaust") || strstr(tmp,"Lever") ||
- strstr(tmp,"Roadsign") || strstr(tmp,"Town") ||
- strstr(tmp,"Leaves") || strstr(tmp,"Horse") ||
- strstr(tmp,"Tree") || strstr(tmp,"Flower") ||
- strstr(tmp,"Plant") || strstr(tmp,"Pannier")||
- strstr(tmp,"Conveyor") || strstr(tmp,"Tractor")||
- strstr(tmp,"Grab") || strstr(tmp,"Roller") ||
- strstr(tmp,"Stretch") || strstr(tmp,"Tap ") ||
- strstr(tmp,"Forklift") || strstr(tmp,"Flag") ||
- strstr(tmp,"Belville") || strstr(tmp,"Light &")||
- strstr(tmp,"Hose") || strstr(tmp,"Arm P") ||
- strstr(tmp,"Brush") || strstr(tmp,"Castle") ||
- strstr(tmp,"Tipper") || strstr(tmp,"Bar") ||
- strstr(tmp,"Animal"))
- return 0x100;
-
- return 1;
+ m_CategoriesModified = true;
}
// =============================================================================
// Pieces handling stuff
// Remove pieces from the library
-bool PiecesLibrary::DeletePieces (char** names, int numpieces)
+bool PiecesLibrary::DeletePieces (PtrArray<PieceInfo>& Pieces)
{
FileDisk newbin, newidx, oldbin, oldidx;
char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200];
@@ -676,11 +709,11 @@ bool PiecesLibrary::DeletePieces (char** names, int numpieces)
name[8] = 0;
oldidx.Read(&name, 8);
- for (i = 0; i < numpieces; i++)
- if (strcmp(name, names[i]) == 0)
+ for (i = 0; i < Pieces.GetSize(); i++)
+ if (strcmp(name, Pieces[i]->m_strName) == 0)
break;
- if (i != numpieces)
+ if (i != Pieces.GetSize())
{
oldidx.Seek(64+12+1+4+4+4, SEEK_CUR);
deleted++;
@@ -727,7 +760,7 @@ bool PiecesLibrary::DeletePieces (char** names, int numpieces)
newidx.Close();
newbin.Close();
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -974,7 +1007,7 @@ bool PiecesLibrary::LoadUpdate (const char* update)
newbin.Close();
up.Close();
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -1092,7 +1125,7 @@ bool PiecesLibrary::DeleteTextures (char** Names, int NumTextures)
count -= deleted;
newidx.WriteShort (&count, 1);
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -1275,7 +1308,7 @@ bool PiecesLibrary::ImportTexture (const char* Name)
count -= deleted;
newidx.WriteShort (&count, 1);
- m_bNeedsReload = true;
+ m_Modified = true;
return true;
}
@@ -2538,7 +2571,7 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
newidx.WriteByte(&bt, 1);
- i = PiecesLibrary::GetDefaultPieceGroup(piece->description);
+ i = 0;//PiecesLibrary::GetDefaultPieceGroup(piece->description);
newidx.WriteLong(&i, 1);
newidx.WriteLong(&binoff, 1);
diff --git a/common/library.h b/common/library.h
index 0300e04..a8ba118 100755
--- a/common/library.h
+++ b/common/library.h
@@ -9,7 +9,8 @@ class File;
class Texture;
class PieceInfo;
-#define LC_PIECESLIB_MAXGROUPS 32
+#define LC_CATEGORY_FILE_ID LC_FOURCC('C', 'A', 'T', 0)
+#define LC_CATEGORY_FILE_VERSION 0x0100
typedef struct
{
@@ -20,28 +21,26 @@ typedef struct
class PiecesLibrary
{
public:
- PiecesLibrary ();
- ~PiecesLibrary ();
-
- const char* GetLibraryPath() const
- { return m_LibraryPath; }
- int GetPieceCount () const
- { return m_nPieceCount; }
- int GetTextureCount () const
- { return m_nTextureCount; }
- int GetGroupCount () const
- { return m_nGroupCount; }
- String& GetGroup (int i)
- { return m_strGroups[i]; }
- bool NeedsReload () const
- { return m_bNeedsReload; }
+ PiecesLibrary();
+ ~PiecesLibrary();
+
+ const char* GetLibraryPath() const
+ { return m_LibraryPath; }
+ int GetPieceCount () const
+ { return m_nPieceCount; }
+ int GetTextureCount () const
+ { return m_nTextureCount; }
// Categories.
- void GetCategoryEntries(int CategoryIndex, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces);
+ void GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces);
void GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces);
void SetCategory(int Index, const String& Name, const String& Keywords);
void AddCategory(const String& Name, const String& Keywords);
void RemoveCategory(int Index);
+ void ResetCategories();
+ bool SaveCategories();
+ bool DoSaveCategories(bool AskName);
+ bool LoadCategories(const char* FileName);
const char* GetCategoryName(int Index) const
{ return m_Categories[Index].Name; }
@@ -61,32 +60,28 @@ public:
return -1;
}
- void CheckReload ();
- bool Load (const char* libpath);
- void Unload ();
- bool LoadGroupConfig (const char* Filename);
+ bool Load(const char* libpath);
+ void Unload();
// Search for pieces.
- PieceInfo* FindPieceInfo (const char* name) const;
- PieceInfo* GetPieceInfo (int index) const;
- int GetPieceIndex (PieceInfo *pInfo) const;
- Texture* FindTexture (const char* name) const;
- Texture* GetTexture (int index) const;
+ PieceInfo* FindPieceInfo(const char* name) const;
+ PieceInfo* GetPieceInfo(int index) const;
+ int GetPieceIndex(PieceInfo *pInfo) const;
+ Texture* FindTexture(const char* name) const;
+ Texture* GetTexture(int index) const;
// File operations.
- bool DeletePieces (char** names, int numpieces);
- bool LoadUpdate (const char* update);
- bool DeleteTextures (char** Names, int NumTextures);
- bool ImportTexture (const char* Name);
- bool ImportLDrawPiece (const char* Filename);
-
- static unsigned long GetDefaultPieceGroup (const char* name);
+ bool DeletePieces(PtrArray<PieceInfo>& Pieces);
+ bool LoadUpdate(const char* update);
+ bool DeleteTextures(char** Names, int NumTextures);
+ bool ImportTexture(const char* Name);
+ bool ImportLDrawPiece(const char* Filename);
protected:
- char m_LibraryPath[LC_MAXPATH]; // path to the library files
+ char m_LibraryPath[LC_MAXPATH]; // path to the library files
int m_nMovedCount; // number of moved pieces
- char* m_pMovedReference; // moved pieces list
+ char* m_pMovedReference; // moved pieces list
int m_nPieceCount; // number of pieces
PieceInfo* m_pPieceIdx; // pieces array
int m_nTextureCount; // number of textures
@@ -95,12 +90,9 @@ protected:
// Categories.
ObjArray<PiecesLibraryCategory> m_Categories;
- // Groups stuff
- int m_nGroupCount;
- String m_strGroups[LC_PIECESLIB_MAXGROUPS];
- char m_GroupsFile[LC_MAXPATH];
-
- bool m_bNeedsReload; // if the library files were changed and they need to be reloaded
+ bool m_Modified;
+ bool m_CategoriesModified;
+ char m_CategoriesFile[LC_MAXPATH];
bool ValidatePiecesFile (File& IdxFile, File& BinFile) const;
bool ValidateTexturesFile (File& IdxFile, File& BinFile) const;
diff --git a/common/project.cpp b/common/project.cpp
index 9f60bb8..af5cf72 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -1228,7 +1228,7 @@ void Project::FileReadMPD(File& MPD, PtrArray<File>& FileArray) const
FileMem* CurFile = NULL;
char Buf[1024];
- while (MPD.ReadString(Buf, 1024))
+ while (MPD.ReadLine(Buf, 1024))
{
String Line(Buf);
@@ -1279,7 +1279,7 @@ void Project::FileReadLDraw(File* file, Matrix* prevmat, int* nOk, int DefColor,
lcuint32 Offset = file->GetPosition();
file->Seek(0, SEEK_SET);
- while (file->ReadString(buf, 1024))
+ while (file->ReadLine(buf, 1024))
{
strupr(buf);
if (strstr(buf, "STEP"))
@@ -4728,6 +4728,8 @@ void Project::HandleCommand(LC_COMMANDS id, unsigned long nParam)
FileMem file;
FileSave(&file, true);
+ // TODO: save piece IDs and reload.
+
if (SystemDoDialog(LC_DLG_LIBRARY, NULL))
{
/*
diff --git a/common/typedefs.h b/common/typedefs.h
index 51c1283..0d147c6 100644
--- a/common/typedefs.h
+++ b/common/typedefs.h
@@ -287,6 +287,7 @@ typedef enum {
LC_DLG_FILE_SAVE_PROJECT,
LC_DLG_FILE_MERGE_PROJECT,
LC_DLG_FILE_OPEN,
+ LC_DLG_FILE_SAVE,
LC_DLG_PICTURE_SAVE,
LC_DLG_HTML,
LC_DLG_POVRAY,
@@ -308,7 +309,7 @@ typedef enum {
typedef enum
{
LC_FILEOPENDLG_DAT,
- LC_FILEOPENDLG_LGF,
+ LC_FILEOPENDLG_LCF,
LC_FILEOPENDLG_LUP
} LC_FILEOPENDLG_TYPES;
@@ -320,6 +321,17 @@ typedef struct
char** filenames;
} LC_FILEOPENDLG_OPTS;
+typedef enum
+{
+ LC_FILESAVEDLG_LCF,
+} LC_FILESAVEDLG_TYPES;
+
+typedef struct
+{
+ int type;
+ char path[LC_MAXPATH];
+} LC_FILESAVEDLG_OPTS;
+
typedef struct
{
bool render;