summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2011-06-10 22:48:49 +0000
committerleo2011-06-10 22:48:49 +0000
commitace85d99c8a924686c6dbcdc13e91dbd8078462d (patch)
treed4d40844eb8edf0636bbd6dc0a26cba62c0920e5
parent052c3f118feda994abfa0929c3bd2939d59fa0f8 (diff)
Added support for piece names longer than 8 characters.
git-svn-id: http://svn.leocad.org/branches/leocad-0.75@970 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rw-r--r--common/file.h5
-rwxr-xr-xcommon/library.cpp165
-rwxr-xr-xcommon/library.h11
-rw-r--r--common/minifig.cpp2
-rw-r--r--common/piece.cpp14
-rw-r--r--common/pieceinf.cpp5
-rw-r--r--common/pieceinf.h4
7 files changed, 137 insertions, 69 deletions
diff --git a/common/file.h b/common/file.h
index b662bdd..cb583cd 100644
--- a/common/file.h
+++ b/common/file.h
@@ -90,6 +90,11 @@ public:
void Close();
bool Open(const char *filename, const char *mode);
+ void* GetBuffer() const
+ {
+ return m_pBuffer;
+ }
+
protected:
// MemFile specific:
unsigned long m_nGrowBytes;
diff --git a/common/library.cpp b/common/library.cpp
index f1f06cf..f3226ca 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -18,7 +18,7 @@
const char PiecesLibrary::PiecesBinHeader[32] = "LeoCAD piece library data file\0";
const char PiecesLibrary::PiecesIdxHeader[32] = "LeoCAD piece library index file";
-const int PiecesLibrary::PiecesFileVersion = 3;
+const int PiecesLibrary::PiecesFileVersion = 4;
const char PiecesLibrary::TexturesBinHeader[32] = "LeoCAD texture data file\0\0\0\0\0\0\0";
const char PiecesLibrary::TexturesIdxHeader[32] = "LeoCAD texture index file\0\0\0\0\0\0";
const int PiecesLibrary::TexturesFileVersion = 1;
@@ -114,14 +114,14 @@ bool PiecesLibrary::Load (const char *libpath)
// Load moved files reference.
if (m_pMovedReference != NULL)
free(m_pMovedReference);
- m_pMovedReference = (char*)malloc(18*movedcount);
- memset (m_pMovedReference, 0, 18*movedcount);
+ m_pMovedReference = (char*)malloc(LC_PIECE_NAME_LEN*2*movedcount);
+ memset (m_pMovedReference, 0, LC_PIECE_NAME_LEN*2*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.Read (&m_pMovedReference[i*LC_PIECE_NAME_LEN*2], LC_PIECE_NAME_LEN);
+ idx.Read (&m_pMovedReference[i*LC_PIECE_NAME_LEN*2+LC_PIECE_NAME_LEN], LC_PIECE_NAME_LEN);
}
idx.Close();
@@ -185,11 +185,11 @@ bool PiecesLibrary::Load (const char *libpath)
}
// Make sure the pieces library files are valid
-bool PiecesLibrary::ValidatePiecesFile (File& IdxFile, File& BinFile) const
+bool PiecesLibrary::ValidatePiecesFile(FileDisk& IdxFile, FileDisk& BinFile) const
{
lcuint32 binsize, IdxPos = IdxFile.GetPosition(), BinPos = BinFile.GetPosition();
lcuint16 count, movedcount;
- lcuint8 version;
+ lcuint8 version, update;
char header[32];
IdxFile.Seek (-(long)(2*sizeof(count)+sizeof(binsize)), SEEK_END);
@@ -199,6 +199,7 @@ bool PiecesLibrary::ValidatePiecesFile (File& IdxFile, File& BinFile) const
IdxFile.Seek (0, SEEK_SET);
IdxFile.Read (header, 32);
IdxFile.ReadByte (&version, 1);
+ IdxFile.ReadByte (&update, 1);
IdxFile.Seek (IdxPos, SEEK_SET);
if (memcmp (header, PiecesIdxHeader, 32) != 0)
@@ -207,6 +208,57 @@ bool PiecesLibrary::ValidatePiecesFile (File& IdxFile, File& BinFile) const
return false;
}
+ if (version == 3 && PiecesFileVersion == 4)
+ {
+ FileMem NewIdx;
+ char tmp[256];
+
+ version = 4;
+ NewIdx.Write(header, 32);
+ NewIdx.WriteByte(&version, 1);
+ NewIdx.WriteByte(&update, 1);
+
+ IdxFile.Seek(34, SEEK_SET);
+
+ for (int i = 0; i < count; i++)
+ {
+ char name[LC_PIECE_NAME_LEN];
+ memset(name, 0, LC_PIECE_NAME_LEN);
+
+ IdxFile.Read(name, 8);
+ IdxFile.Read(tmp, 64+12+1+4+4+4);
+
+ NewIdx.Write(name, LC_PIECE_NAME_LEN);
+ NewIdx.Write(tmp, 64+12+1+4+4+4);
+ }
+
+ for (int i = 0; i < movedcount * 2; i++)
+ {
+ char name[LC_PIECE_NAME_LEN];
+ memset(name, 0, LC_PIECE_NAME_LEN);
+
+ IdxFile.Read(name, 8);
+ NewIdx.Write(name, LC_PIECE_NAME_LEN);
+ }
+
+ NewIdx.WriteShort(&movedcount, 1);
+ NewIdx.WriteLong(&binsize, 1);
+ NewIdx.WriteShort(&count, 1);
+
+ char FileName[LC_MAXPATH];
+ strcpy(FileName, IdxFile.GetFileName());
+ IdxFile.Close();
+
+ if (!IdxFile.Open(FileName, "wb"))
+ return false;
+
+ IdxFile.Write(NewIdx.GetBuffer(), NewIdx.GetLength());
+ IdxFile.Close();
+
+ IdxFile.Open(FileName, "rb");
+ IdxFile.Seek(IdxPos, SEEK_SET);
+ }
+
if (version != PiecesFileVersion)
{
console.PrintError ("Wrong version of the Pieces Library files.\n");
@@ -294,9 +346,9 @@ PieceInfo* PiecesLibrary::FindPieceInfo (const char* name) const
for (i = 0; i < m_nMovedCount; i++)
{
- if (!strcmp (&m_pMovedReference[i*18], name))
+ if (!strcmp (&m_pMovedReference[i*LC_PIECE_NAME_LEN*2], name))
{
- char* tmp = &m_pMovedReference[i*18+9];
+ char* tmp = &m_pMovedReference[i*LC_PIECE_NAME_LEN*2+LC_PIECE_NAME_LEN];
for (i = 0, pInfo = m_pPieceIdx; i < m_nPieceCount; i++, pInfo++)
if (!strcmp (tmp, pInfo->m_strName))
@@ -597,7 +649,7 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrA
PieceInfo* Parent;
// Find the parent of this patterned piece.
- char ParentName[9];
+ char ParentName[LC_PIECE_NAME_LEN];
strcpy(ParentName, Info->m_strName);
*strchr(ParentName, 'P') = '\0';
@@ -635,7 +687,7 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrA
void PiecesLibrary::GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces) const
{
- char Name[9];
+ char Name[LC_PIECE_NAME_LEN];
strcpy(Name, Parent->m_strName);
strcat(Name, "P");
@@ -735,10 +787,10 @@ bool PiecesLibrary::DeletePieces (PtrArray<PieceInfo>& Pieces)
// if (AfxMessageBox(IDS_CANCEL_PROMPT, MB_YESNO) == IDYES)
// break;
- char name[9];
+ char name[LC_PIECE_NAME_LEN];
int i;
- name[8] = 0;
- oldidx.Read(&name, 8);
+
+ oldidx.Read(&name, LC_PIECE_NAME_LEN);
for (i = 0; i < Pieces.GetSize(); i++)
if (strcmp(name, Pieces[i]->m_strName) == 0)
@@ -751,7 +803,7 @@ bool PiecesLibrary::DeletePieces (PtrArray<PieceInfo>& Pieces)
continue;
}
- newidx.Write(name, 8);
+ newidx.Write(name, LC_PIECE_NAME_LEN);
oldidx.Read(tmp, 64+12+1+4);
newidx.Write(tmp, 64+12+1+4);
@@ -806,12 +858,12 @@ bool PiecesLibrary::LoadUpdate (const char* update)
lcuint8 bt;
void* membuf;
- typedef struct
+ struct LC_UPDATE_INFO
{
- char name[9];
- lcuint8 type;
- lcuint32 offset;
- } LC_UPDATE_INFO;
+ char Name[LC_PIECE_NAME_LEN];
+ lcuint8 Type;
+ lcuint32 Offset;
+ };
LC_UPDATE_INFO* upinfo;
strcpy(file1, m_LibraryPath);
@@ -864,16 +916,16 @@ bool PiecesLibrary::LoadUpdate (const char* update)
for (i = 0; i < changes; i++)
{
- up.Read(&upinfo[i].name, 8);
- up.Read(&upinfo[i].type, 1);
- upinfo[i].offset = up.GetPosition();
+ up.Read(&upinfo[i].Name, 8);
+ up.Read(&upinfo[i].Type, 1);
+ upinfo[i].Offset = up.GetPosition();
- if ((upinfo[i].type & LC_UPDATE_DESCRIPTION) ||
- (upinfo[i].type & LC_UPDATE_NEWPIECE))
+ if ((upinfo[i].Type & LC_UPDATE_DESCRIPTION) ||
+ (upinfo[i].Type & LC_UPDATE_NEWPIECE))
up.Seek(64+4, SEEK_CUR);
- if ((upinfo[i].type & LC_UPDATE_DRAWINFO) ||
- (upinfo[i].type & LC_UPDATE_NEWPIECE))
+ if ((upinfo[i].Type & LC_UPDATE_DRAWINFO) ||
+ (upinfo[i].Type & LC_UPDATE_NEWPIECE))
{
up.Seek(12+1, SEEK_CUR);
up.ReadLong(&cs, 1);
@@ -887,9 +939,8 @@ bool PiecesLibrary::LoadUpdate (const char* update)
for (i = 0; i < count; i++)
{
- char name[9];
- name[8] = 0;
- oldidx.Read (&name, 8);
+ char Name[LC_PIECE_NAME_LEN];
+ oldidx.Read(&Name, LC_PIECE_NAME_LEN);
// dlg.StepIt();
// if(dlg.CheckCancelButton())
@@ -900,20 +951,22 @@ bool PiecesLibrary::LoadUpdate (const char* update)
// }
for (j = 0; j < changes; j++)
- if (strcmp(name, upinfo[j].name) == 0)
{
- if (upinfo[j].type == LC_UPDATE_DELETE)
+ if (strcmp(Name, upinfo[j].Name))
+ continue;
+
+ if (upinfo[j].Type == LC_UPDATE_DELETE)
{
oldidx.Seek(64+12+1+4+4+4, SEEK_CUR);
break;
}
newcount++;
- up.Seek(upinfo[j].offset, SEEK_SET);
- newidx.Write(name, 8);
+ up.Seek(upinfo[j].Offset, SEEK_SET);
+ newidx.Write(Name, LC_PIECE_NAME_LEN);
// description
- if (upinfo[j].type & LC_UPDATE_DESCRIPTION)
+ if (upinfo[j].Type & LC_UPDATE_DESCRIPTION)
{
up.Read(&tmp, 64);
up.Read(&group, 4);
@@ -925,7 +978,7 @@ bool PiecesLibrary::LoadUpdate (const char* update)
// dlg.SetStatus(tmp);
// bounding box & flags
- if (upinfo[j].type & LC_UPDATE_DRAWINFO)
+ if (upinfo[j].Type & LC_UPDATE_DRAWINFO)
{
up.Read(&tmp, 12+1);
oldidx.Seek(12+1, SEEK_CUR);
@@ -935,7 +988,7 @@ bool PiecesLibrary::LoadUpdate (const char* update)
newidx.Write(tmp, 12+1);
// group
- if (upinfo[j].type & LC_UPDATE_DESCRIPTION)
+ if (upinfo[j].Type & LC_UPDATE_DESCRIPTION)
oldidx.Seek(4, SEEK_CUR);
else
oldidx.Read(&group, 4);
@@ -944,7 +997,7 @@ bool PiecesLibrary::LoadUpdate (const char* update)
binoff = newbin.GetLength();
newidx.WriteLong(&binoff, 1);
- if (upinfo[j].type & LC_UPDATE_DRAWINFO)
+ if (upinfo[j].Type & LC_UPDATE_DRAWINFO)
{
up.ReadLong(&cs, 1);
oldidx.Seek(4+4, SEEK_CUR);
@@ -973,7 +1026,7 @@ bool PiecesLibrary::LoadUpdate (const char* update)
if (j == changes)
{
newcount++;
- newidx.Write(name, 8);
+ newidx.Write(Name, LC_PIECE_NAME_LEN);
oldidx.Read(tmp, 64+12+1+4);
newidx.Write(tmp, 64+12+1+4);
binoff = newbin.GetLength();
@@ -995,11 +1048,11 @@ bool PiecesLibrary::LoadUpdate (const char* update)
// now add new pieces
for (j = 0; j < changes; j++)
- if (upinfo[j].type == LC_UPDATE_NEWPIECE)
+ if (upinfo[j].Type == LC_UPDATE_NEWPIECE)
{
newcount++;
- newidx.Write(upinfo[j].name, 8);
- up.Seek(upinfo[j].offset, SEEK_SET);
+ newidx.Write(upinfo[j].Name, LC_PIECE_NAME_LEN);
+ up.Seek(upinfo[j].Offset, SEEK_SET);
up.Read(&tmp, 64+12);
newidx.Write(tmp, 64+12);
up.Read(&group, 4);
@@ -1051,7 +1104,7 @@ bool PiecesLibrary::DeleteTextures (char** Names, int NumTextures)
char file1[LC_MAXPATH], file2[LC_MAXPATH];
FileDisk newbin, newidx, oldbin, oldidx;
lcuint32 binsize, offset = 0;
- lcuint16 count, deleted = 0, i, j;
+ lcuint16 count, deleted = 0, i, j;
lcuint8 version, bt;
// Backup files
@@ -1212,7 +1265,7 @@ bool PiecesLibrary::ImportTexture (const char* Name)
strcpy(NewTexName, p);
if (FindTexture (NewTexName) != NULL)
- Sys_MessageBox ("Texture already exists in the library !");
+ Sys_MessageBox ("Texture already exists in the library !");
// Write the headers
newidx.Write (TexturesIdxHeader, sizeof (TexturesIdxHeader));
@@ -2221,6 +2274,8 @@ bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece)
ptr = tmp;
else
ptr++;
+
+ memset(piece->name, 0, sizeof(piece->name));
strcpy(piece->name, ptr);
strupr(piece->name);
@@ -2258,7 +2313,7 @@ bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece)
{
for (j = 0; j < lf->type; j++)
{
- int i;
+ int i;
for (i = unique-1; i != -1; i--)
if (FloatPointsClose(&verts[i*3], &lf->points[j*3]))
break;
@@ -2308,7 +2363,7 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
unsigned long i, j, cs, binoff = 0, delta;
void* membuf;
short scale, sb[6];
- PiecesLibrary *pLib = lcGetPiecesLibrary();
+ PiecesLibrary *pLib = lcGetPiecesLibrary();
strcpy(file1, pLib->GetLibraryPath());
strcat(file1, "pieces-b.old");
@@ -2339,15 +2394,15 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
for (j = 0; j < count; j++)
{
- char name[9];
- name[8] = 0;
- oldidx.Read(name, 8);
+ char name[LC_PIECE_NAME_LEN];
+ oldidx.Read(name, LC_PIECE_NAME_LEN);
+
if (strcmp(name, piece->name) == 0)
{
oldidx.Seek(64+12+1+4, SEEK_CUR);
oldidx.ReadLong(&binoff, 1);
oldidx.ReadLong(&delta, 1);
- oldidx.Seek(-(8+64+12+1+4+4+4), SEEK_CUR);
+ oldidx.Seek(-(LC_PIECE_NAME_LEN+64+12+1+4+4+4), SEEK_CUR);
delta += binoff;
break;
}
@@ -2576,7 +2631,7 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
}
// Now write the index
- newidx.Write(piece->name, 8);
+ newidx.Write(piece->name, LC_PIECE_NAME_LEN);
newidx.Write(piece->description, 64);
for (i = 0; i < 6; i++)
@@ -2613,15 +2668,15 @@ bool SaveLDrawPiece(LC_LDRAW_PIECE* piece)
if (j != count)
{
unsigned long d = newbin.GetPosition() - delta;
- oldidx.Seek (8+64+12+1+4+4+4, SEEK_CUR);
+ oldidx.Seek (LC_PIECE_NAME_LEN+64+12+1+4+4+4, SEEK_CUR);
for (j++; j < count; j++)
{
unsigned long dw;
- char buf[8+64+12+1+4];
- oldidx.Read(buf, 8+64+12+1+4);
+ char buf[LC_PIECE_NAME_LEN+64+12+1+4];
+ oldidx.Read(buf, LC_PIECE_NAME_LEN+64+12+1+4);
oldidx.ReadLong(&dw, 1);
dw += d;
- newidx.Write(buf, 8+64+12+1+4);
+ newidx.Write(buf, LC_PIECE_NAME_LEN+64+12+1+4);
newidx.WriteLong(&dw, 1);
oldidx.ReadLong(&dw, 1);
newidx.WriteLong(&dw, 1);
diff --git a/common/library.h b/common/library.h
index fdd1f2f..bf4247a 100755
--- a/common/library.h
+++ b/common/library.h
@@ -6,6 +6,7 @@
#include "array.h"
class File;
+class FileDisk;
class Texture;
class PieceInfo;
@@ -98,8 +99,8 @@ protected:
bool m_CategoriesModified;
char m_CategoriesFile[LC_MAXPATH];
- bool ValidatePiecesFile (File& IdxFile, File& BinFile) const;
- bool ValidateTexturesFile (File& IdxFile, File& BinFile) const;
+ bool ValidatePiecesFile(FileDisk& IdxFile, FileDisk& BinFile) const;
+ bool ValidateTexturesFile(File& IdxFile, File& BinFile) const;
// File headers
static const char PiecesBinHeader[32];
@@ -148,7 +149,7 @@ typedef struct texture_s
texture_s* next;
} texture_t;
-typedef struct
+struct LC_LDRAW_PIECE
{
float* verts;
unsigned int verts_count;
@@ -156,9 +157,9 @@ typedef struct
connection_t* connections;
group_t* groups;
texture_t* textures;
- char name[9];
+ char name[LC_MAXPATH];
char description[65];
-} LC_LDRAW_PIECE;
+};
bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece);
bool SaveLDrawPiece(LC_LDRAW_PIECE* piece);
diff --git a/common/minifig.cpp b/common/minifig.cpp
index 9736333..a95d886 100644
--- a/common/minifig.cpp
+++ b/common/minifig.cpp
@@ -1233,7 +1233,7 @@ void MinifigWizard::GetMinifigNames (char ***names, int *count)
void MinifigWizard::SaveMinifig (const char* name)
{
- char tmp[16];
+ char tmp[LC_PIECE_NAME_LEN];
int i, j;
// check if the name is already being used
diff --git a/common/piece.cpp b/common/piece.cpp
index 5431d00..8569d2a 100644
--- a/common/piece.cpp
+++ b/common/piece.cpp
@@ -15,7 +15,7 @@
#include "algebra.h"
#include "lc_application.h"
-#define LC_PIECE_SAVE_VERSION 9 // LeoCAD 0.73
+#define LC_PIECE_SAVE_VERSION 10 // LeoCAD 0.75.2
static LC_OBJECT_KEY_INFO piece_key_info[LC_PK_COUNT] =
{
@@ -252,8 +252,14 @@ bool Piece::FileLoad (File& file, char* name)
}
// Common to all versions.
- file.Read (name, 9);
- file.ReadByte (&m_nColor, 1);
+ if (version < 10)
+ {
+ memset(name, 0, LC_PIECE_NAME_LEN);
+ file.Read(name, 9);
+ }
+ else
+ file.Read(name, LC_PIECE_NAME_LEN);
+ file.ReadByte(&m_nColor, 1);
if (version < 5)
{
@@ -321,7 +327,7 @@ void Piece::FileSave (File& file, Group* pGroups)
Object::FileSave (file);
- file.Write(m_pPieceInfo->m_strName, 9);
+ file.Write(m_pPieceInfo->m_strName, LC_PIECE_NAME_LEN);
file.WriteByte(&m_nColor, 1);
file.WriteByte(&m_nStepShow, 1);
file.WriteByte(&m_nStepHide, 1);
diff --git a/common/pieceinf.cpp b/common/pieceinf.cpp
index f18cf74..244ecc2 100644
--- a/common/pieceinf.cpp
+++ b/common/pieceinf.cpp
@@ -217,10 +217,9 @@ void PieceInfo::LoadIndex (File& file)
m_pGroups = NULL;
m_nTextureCount = 0;
m_pTextures = NULL;
- m_nBoxList = 0;
+ m_nBoxList = 0;
- file.Read (m_strName, 8);
- m_strName[8] = '\0';
+ file.Read (m_strName, LC_PIECE_NAME_LEN);
file.Read (m_strDescription, 64);
m_strDescription[64] = '\0';
file.ReadShort (sh, 6);
diff --git a/common/pieceinf.h b/common/pieceinf.h
index 56892c8..d94bc80 100644
--- a/common/pieceinf.h
+++ b/common/pieceinf.h
@@ -18,6 +18,8 @@
#define LC_PIECE_MEDIUM 0x20 // scale = 1000 (otherwise = 100)
#define LC_PIECE_LONGDATA_RUNTIME 0x40 // If the original data is 16 bits but we expanded to 32 bits
+#define LC_PIECE_NAME_LEN 256
+
class File;
class Texture;
@@ -99,7 +101,7 @@ class PieceInfo
public:
// Attributes
- char m_strName[9];
+ char m_strName[LC_PIECE_NAME_LEN];
char m_strDescription[65];
float m_fDimensions[6];
unsigned long m_nOffset;