From d1cfc8d5b2cd25782617c2bdfecb72aae7fab9fb Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 5 Jan 2000 15:33:27 +0000 Subject: Update the minifig wizard with the new pieces Added a function to read the update files cVS: ---------------------------------------------------------------------- git-svn-id: http://svn.leocad.org/trunk@49 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- common/defines.h | 5 ++ common/globals.cpp | 19 +++-- common/globals.h | 5 +- common/library.cpp | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++- common/library.h | 1 + win/Figdlg.cpp | 11 ++- win/Libdlg.cpp | 244 +---------------------------------------------------- 7 files changed, 273 insertions(+), 256 deletions(-) diff --git a/common/defines.h b/common/defines.h index 59676ae..8db3d25 100644 --- a/common/defines.h +++ b/common/defines.h @@ -176,5 +176,10 @@ typedef enum { LC_PIECE, LC_CAMERA, LC_CAMERA_TARGET, #define LC_UPDATE_OBJECT 0x40 #define LC_UPDATE_TYPE 0x80 +// Piece library update +#define LC_UPDATE_DELETE 0x00 +#define LC_UPDATE_DESCRIPTION 0x01 +#define LC_UPDATE_DRAWINFO 0x02 +#define LC_UPDATE_NEWPIECE 0x04 #endif // _DEFINES_H_ diff --git a/common/globals.cpp b/common/globals.cpp index 97acc63..e36af79 100644 --- a/common/globals.cpp +++ b/common/globals.cpp @@ -167,14 +167,17 @@ MFW_PIECEINFO mfwpieceinfo[] = { { "973P49", "Forestman Blue Collar", MF_TORSO }, { "973P48", "Forestman Maroon Collar", MF_TORSO }, { "973P50", "Forestman Black Collar", MF_TORSO }, - { "3841", "Pickaxe", MF_TOOL } + { "3841", "Pickaxe", MF_TOOL }, + { "973P21", "Five Button Fire Fighter", MF_TORSO }, + { "973P22", "Red Shirt and Suit", MF_TORSO }, + { "973P34", "Open Jacket over Striped Vest", MF_TORSO }, + { "973P46", "Forestman and Purse", MF_TORSO }, + { "973P101", "SW Rebel Pilot", MF_TORSO }, + { "4498", "Arrow Quiver", MF_NECK }, + { "4499", "Bow with Arrow", MF_TOOL }, + { "3852", "Hairbrush", MF_TOOL }, + { "30152", "Magnifying Glass", MF_TOOL } }; // { "770", "Shield Ovoid", MF_TOOL }, -// 2447.DAT Minifig Helmet Visor - - - - - - +// 2447 Minifig Helmet Visor diff --git a/common/globals.h b/common/globals.h index 08152d4..c35cf19 100644 --- a/common/globals.h +++ b/common/globals.h @@ -12,8 +12,5 @@ extern unsigned char ColorArray[31][4]; extern const char* colornames[LC_MAXCOLORS]; extern const char* altcolornames[LC_MAXCOLORS]; -#define MFW_PIECES 76 +#define MFW_PIECES 85 extern MFW_PIECEINFO mfwpieceinfo[]; - - - diff --git a/common/library.cpp b/common/library.cpp index 5bfa287..fe79d4a 100755 --- a/common/library.cpp +++ b/common/library.cpp @@ -76,7 +76,7 @@ static unsigned long GetDefaultPieceGroup(char* name) strstr(tmp,"Roadsign") || strstr(tmp,"Town") || strstr(tmp,"Leaves") || strstr(tmp,"Horse") || strstr(tmp,"Tree") || strstr(tmp,"Flower") || - strstr(tmp,"Plant") || + strstr(tmp,"Plant") || strstr(tmp,"Pannier")|| strstr(tmp,"Conveyor") || strstr(tmp,"Tractor")|| strstr(tmp,"Grab") || strstr(tmp,"Roller") || strstr(tmp,"Stretch") || strstr(tmp,"Tap ") || @@ -1457,4 +1457,246 @@ bool DeletePiece(char** names, int numpieces) // ======================================================== // Load update +bool LoadUpdate(const char* update) +{ + FileDisk newbin, newidx, oldbin, oldidx, up; + char file1[LC_MAXPATH], file2[LC_MAXPATH], tmp[200]; + unsigned short changes, moved, count, i, j, newcount = 0; + unsigned long cs, group, binoff; + unsigned char bt; + void* membuf; + + typedef struct + { + char name[9]; + BYTE type; + DWORD offset; + } LC_UPDATE_INFO; + LC_UPDATE_INFO* upinfo; + + strcpy(file1, project->GetLibraryPath()); + strcat(file1, "pieces-b.old"); + remove(file1); + strcpy(file2, project->GetLibraryPath()); + strcat(file2, "pieces.bin"); + rename(file2, file1); + + if ((!oldbin.Open(file1, "rb")) || + (!newbin.Open(file2, "wb"))) + return false; + + strcpy(file1, project->GetLibraryPath()); + strcat(file1, "pieces-i.old"); + remove(file1); + strcpy(file2, project->GetLibraryPath()); + strcat(file2, "pieces.idx"); + rename(file2, file1); + + if ((!oldidx.Open(file1, "rb")) || + (!newidx.Open(file2, "wb"))) + return false; + + if (!up.Open(update, "rb")) + return false; + + up.Seek(32, SEEK_SET); + up.ReadByte(&bt, 1); + if (bt != 2) + return false; // wrong version + + up.ReadByte(&bt, 1); // update number + + up.Seek(-2, SEEK_END); + up.ReadShort(&changes, 1); + up.Seek(34, SEEK_SET); + oldidx.Seek(-2, SEEK_END); + oldidx.ReadShort(&count, 1); + oldidx.Seek(0, SEEK_SET); + oldidx.Read(tmp, 34); + newidx.Write(tmp, 33); // skip update byte + newidx.WriteByte(&bt, 1); + oldbin.Read(tmp, 32); + newbin.Write(tmp, 32); + + upinfo = (LC_UPDATE_INFO*)malloc(sizeof(LC_UPDATE_INFO)*changes); + memset(upinfo, 0, sizeof(LC_UPDATE_INFO)*changes); + + for (i = 0; i < changes; i++) + { + 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)) + up.Seek(64+4, SEEK_CUR); + + if ((upinfo[i].type & LC_UPDATE_DRAWINFO) || + (upinfo[i].type & LC_UPDATE_NEWPIECE)) + { + up.Seek(12+1, SEEK_CUR); + up.ReadLong(&cs, 1); + up.Seek(cs, SEEK_CUR); + } + } + +// CProgressDlg dlg(_T("Updating Library")); +// dlg.Create(this); +// dlg.SetRange (0, count); + + for (i = 0; i < count; i++) + { + char name[9]; + name[8] = 0; + oldidx.Read (&name, 8); + +// dlg.StepIt(); +// if(dlg.CheckCancelButton()) +// if(AfxMessageBox(IDS_CANCEL_PROMPT, MB_YESNO) == IDYES) +// { +// free(upinfo); +// return TRUE; +// } + + for (j = 0; j < changes; j++) + if (strcmp(name, upinfo[j].name) == 0) + { + 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); + + // description + if (upinfo[j].type & LC_UPDATE_DESCRIPTION) + { + up.Read(&tmp, 64); + up.Read(&group, 4); + oldidx.Seek(64, SEEK_CUR); + } + else + oldidx.Read(&tmp, 64); + newidx.Write(tmp, 64); +// dlg.SetStatus(tmp); + + // bounding box & flags + if (upinfo[j].type & LC_UPDATE_DRAWINFO) + { + up.Read(&tmp, 12+1); + oldidx.Seek(12+1, SEEK_CUR); + } + else + oldidx.Read(&tmp, 12+1); + newidx.Write(tmp, 12+1); + + // group + if (upinfo[j].type & LC_UPDATE_DESCRIPTION) + oldidx.Seek(4, SEEK_CUR); + else + oldidx.Read(&group, 4); + newidx.Write(&group, 4); + + binoff = newbin.GetLength(); + newidx.WriteLong(&binoff, 1); + + if (upinfo[j].type & LC_UPDATE_DRAWINFO) + { + up.ReadLong(&cs, 1); + oldidx.Seek(4+4, SEEK_CUR); + + membuf = malloc(cs); + up.Read(membuf, cs); + newbin.Write(membuf, cs); + free(membuf); + } + else + { + oldidx.ReadLong(&binoff, 1); + oldidx.ReadLong(&cs, 1); + + membuf = malloc(cs); + oldbin.Seek(binoff, SEEK_SET); + oldbin.Read(membuf, cs); + newbin.Write(membuf, cs); + free(membuf); + } + newidx.WriteLong(&cs, 1); + break; + } + + // not changed, just copy + if (j == changes) + { + newcount++; + newidx.Write(name, 8); + oldidx.Read(tmp, 64+12+1+4); + newidx.Write(tmp, 64+12+1+4); + binoff = newbin.GetLength(); + newidx.WriteLong(&binoff, 1); + oldidx.ReadLong(&binoff, 1); + oldidx.ReadLong(&cs, 1); + newidx.WriteLong(&cs, 1); + +// tmp[64] = 0; +// dlg.SetStatus(tmp); + + membuf = malloc(cs); + oldbin.Seek(binoff, SEEK_SET); + oldbin.Read(membuf, cs); + newbin.Write(membuf, cs); + free(membuf); + } + } + + // now add new pieces + for (j = 0; j < changes; j++) + if (upinfo[j].type == LC_UPDATE_NEWPIECE) + { + newcount++; + newidx.Write(upinfo[j].name, 8); + up.Seek(upinfo[j].offset, SEEK_SET); + up.Read(&tmp, 64+12); + newidx.Write(tmp, 64+12); + up.Read(&group, 4); + up.Read(&bt, 1); + newidx.Write(&bt, 1); + newidx.Write(&group, 4); + binoff = newbin.GetLength(); + newidx.WriteLong(&binoff, 1); + + up.ReadLong(&cs, 1); + membuf = malloc(cs); + up.Read(membuf, cs); + newbin.Write(membuf, cs); + up.WriteLong(&cs, 1); + newidx.WriteLong(&cs, 1); + free (membuf); + } + + up.Seek(-(2+2), SEEK_END); + up.ReadShort(&moved, 1); + cs = 2+moved*16; + up.Seek(-(LONG)(cs), SEEK_CUR); + membuf = malloc(cs); + up.Read(membuf, cs); + newidx.Write(membuf, cs); + free (membuf); + + binoff = newbin.GetLength(); + newidx.WriteLong(&binoff, 1); + newidx.WriteShort(&newcount, 1); + + free(upinfo); + oldidx.Close(); + oldbin.Close(); + newidx.Close(); + newbin.Close(); + up.Close(); + + return true; +} diff --git a/common/library.h b/common/library.h index 2ed834c..77d142e 100755 --- a/common/library.h +++ b/common/library.h @@ -48,5 +48,6 @@ bool ReadLDrawPiece(const char* filename, LC_LDRAW_PIECE* piece); bool SaveLDrawPiece(LC_LDRAW_PIECE* piece); void FreeLDrawPiece(LC_LDRAW_PIECE* piece); bool DeletePiece(char** names, int numpieces); +bool LoadUpdate(const char* update); #endif // _MISC_H_ diff --git a/win/Figdlg.cpp b/win/Figdlg.cpp index b209b4e..f819fca 100644 --- a/win/Figdlg.cpp +++ b/win/Figdlg.cpp @@ -131,7 +131,7 @@ BOOL CMinifigDlg::OnInitDialog() ((CComboBox*)GetDlgItem(i))->SetCurSel(0); ((CComboBox*)GetDlgItem(IDC_MF_HAT))->SetCurSel(6); ((CComboBox*)GetDlgItem(IDC_MF_HEAD))->SetCurSel(4); - ((CComboBox*)GetDlgItem(IDC_MF_TORSO))->SetCurSel(15); + ((CComboBox*)GetDlgItem(IDC_MF_TORSO))->SetCurSel(18); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE @@ -170,6 +170,9 @@ void CMinifigDlg::OnPieceSelEndOK(UINT nID) { m_pMFWnd->m_pFig->pos[0][2] = 3.92f; m_pMFWnd->m_pFig->pos[1][2] = 3.92f; + + if (strcmp (pInfo->m_strName,"4498") == 0) + m_pMFWnd->m_pFig->rot[3][2] = 180.0f; } else { @@ -237,6 +240,12 @@ void CMinifigDlg::OnPieceSelEndOK(UINT nID) { z = 1.24f; y = -0.34f; } if (strcmp (pInfo->m_strName,"3841") == 0) { z = 2.24f; y = -1.34f; rz = 180; } + if (strcmp (pInfo->m_strName,"4499") == 0) + { rz = 10; z = 1.52f; } + if (strcmp (pInfo->m_strName,"3852") == 0) + { rz = -90; x = 0.90f; y = -0.8f; z = 1.84f; } + if (strcmp (pInfo->m_strName,"30152") == 0) + { z = 3.06f; y = -2.16f; } if (nID == IDC_MF_TOOLR) x = -x; diff --git a/win/Libdlg.cpp b/win/Libdlg.cpp index cf5e0b1..23974b1 100644 --- a/win/Libdlg.cpp +++ b/win/Libdlg.cpp @@ -292,252 +292,12 @@ BOOL CLibraryDlg::OnCommand(WPARAM wParam, LPARAM lParam) if (filedlg.DoModal() != IDOK) return TRUE; - CFile up; - BYTE bt; - if (!up.Open (filedlg.GetPathName(), CFile::modeRead | CFile::typeBinary)) - return TRUE; - - up.Seek(32, CFile::begin); - up.Read(&bt, 1); - if (bt != 2) - { - AfxMessageBox("Wrong version !", MB_ICONWARNING|MB_OK); - return TRUE; - } - - -/* - up.Read(&bt, 1); // update number - - CWaitCursor wc; - char p[260]; - GetModuleFileName (AfxGetInstanceHandle(), (char*)&p, 260); - if (char* ptr = strrchr (p,'\\')) *ptr = 0; - CString app = p; - app += "\\"; - - DeleteFile(app + "PIECES-B.OLD"); - DeleteFile(app + "PIECES-I.OLD"); - MoveFile(app + "PIECES.BIN", app + "PIECES-B.OLD"); - MoveFile(app + "PIECES.IDX", app + "PIECES-I.OLD"); - - CFile oldbin,oldidx,newbin,newidx; - if ((!oldbin.Open (app + "PIECES-B.OLD", CFile::modeRead | CFile::typeBinary)) || - (!oldidx.Open (app + "PIECES-I.OLD", CFile::modeRead | CFile::typeBinary)) || - (!newbin.Open (app + "PIECES.BIN", CFile::modeCreate | CFile::modeWrite | CFile::typeBinary)) || - (!newidx.Open (app + "PIECES.IDX", CFile::modeCreate | CFile::modeWrite | CFile::typeBinary))) - { - AfxMessageBox("Cannot open file.", MB_OK|MB_ICONERROR); - return TRUE; - } - - char tmp[200]; - WORD changes, count, newcount = 0, i, j; - up.Seek(-(LONG)sizeof(changes), CFile::end); - up.Read(&changes, sizeof(changes)); - up.Seek(34, CFile::begin); - - oldidx.Seek (-(LONG)(sizeof(count)), CFile::end); - oldidx.Read (&count, sizeof(count)); - oldidx.Seek (0, CFile::begin); - oldidx.Read(tmp, 33); - newidx.Write(tmp, 33); - oldbin.Read(tmp, 33); - newbin.Write(tmp, 33); - - typedef struct { - char name[9]; - BYTE type; - DWORD offset; - } UPDATE_INFO; - - #define UPDATE_DELETE 0x00 - #define UPDATE_DESCRIPTION 0x01 - #define UPDATE_DRAWINFO 0x02 - #define UPDATE_NEWPIECE 0x04 - - UPDATE_INFO* upinfo = (UPDATE_INFO*)malloc(sizeof(UPDATE_INFO)*changes); - memset(upinfo, 0, sizeof(UPDATE_INFO)*changes); - - DWORD nextoff, binoff, cs; - for (i = 0; i < changes; i++) - { - up.Read(&upinfo[i].name, 8); - up.Read(&upinfo[i].type, 1); - upinfo[i].offset = up.GetPosition(); - - if ((upinfo[i].type & UPDATE_DESCRIPTION) || - (upinfo[i].type & UPDATE_NEWPIECE)) - up.Seek(64, CFile::current); - - if ((upinfo[i].type & UPDATE_DRAWINFO) || - (upinfo[i].type & UPDATE_NEWPIECE)) - { - up.Seek(sizeof(short[6]), CFile::current); - up.Read(&cs, sizeof(cs)); - up.Seek(cs, CFile::current); - } - } - - CProgressDlg dlg(_T("Updating Library")); - dlg.Create(this); - dlg.SetRange (0, count); - - void* membuf; - for (i = 0; i < count; i++) - { - char name[9]; - name[8] = 0; - oldidx.Read (&name, 8); - - dlg.StepIt(); - if(dlg.CheckCancelButton()) - if(AfxMessageBox(IDS_CANCEL_PROMPT, MB_YESNO) == IDYES) - { - free(upinfo); - return TRUE; - } - - for (j = 0; j < changes; j++) - if (strcmp(name, upinfo[j].name) == 0) - { - if (upinfo[j].type == UPDATE_DELETE) - { - oldidx.Seek(64+sizeof(short[6])+sizeof(DWORD), CFile::current); - break; - } - newcount++; - up.Seek(upinfo[j].offset, CFile::begin); - newidx.Write(name, 8); - - if (upinfo[j].type & UPDATE_DESCRIPTION) - { - up.Read(&tmp, 64); - oldidx.Seek(64, CFile::current); - } - else - oldidx.Read(&tmp, 64); - newidx.Write(tmp, 64); - dlg.SetStatus(tmp); - - if (upinfo[j].type & UPDATE_DRAWINFO) - { - up.Read(&tmp, sizeof(short[6])); - oldidx.Seek(sizeof(short[6]), CFile::current); - } - else - oldidx.Read(&tmp, sizeof(short[6])); - newidx.Write(tmp, sizeof(short[6])); - binoff = newbin.GetLength(); - newidx.Write(&binoff, sizeof(binoff)); - - if (upinfo[j].type & UPDATE_DRAWINFO) - { - up.Read(&cs, sizeof(cs)); - oldidx.Seek(sizeof(binoff), CFile::current); - - membuf = malloc(cs); - up.Read(membuf, cs); - newbin.Write(membuf, cs); - free (membuf); - } - else - { - oldidx.Read(&binoff, sizeof(binoff)); - - if (i == count-1) - nextoff = oldbin.GetLength(); - else - { - oldidx.Seek(72+sizeof(short[6]), CFile::current); - oldidx.Read(&nextoff, sizeof(nextoff)); - oldidx.Seek(-(LONG)(72+sizeof(short[6])+sizeof(DWORD)), CFile::current); - } - - membuf = malloc (nextoff - binoff); - oldbin.Seek(binoff, CFile::begin); - oldbin.Read(membuf, nextoff - binoff); - newbin.Write(membuf, nextoff - binoff); - free (membuf); - } - break; - } - - // not changed, just copy - if (j == changes) - { - newcount++; - newidx.Write(name, 8); - oldidx.Read(tmp, 64+sizeof(short[6])); - newidx.Write(tmp, 64+sizeof(short[6])); - binoff = newbin.GetLength(); - newidx.Write(&binoff, sizeof(binoff)); - oldidx.Read(&binoff, sizeof(binoff)); - - tmp[64] = 0; - dlg.SetStatus(tmp); - - if (i == count-1) - nextoff = oldbin.GetLength(); - else - { - oldidx.Seek(72+sizeof(short[6]), CFile::current); - oldidx.Read(&nextoff, sizeof(nextoff)); - oldidx.Seek(-(LONG)(72+sizeof(short[6])+sizeof(DWORD)), CFile::current); - } - - membuf = malloc (nextoff - binoff); - oldbin.Seek(binoff, CFile::begin); - oldbin.Read(membuf, nextoff - binoff); - newbin.Write(membuf, nextoff - binoff); - free (membuf); - } - } - - // now add new pieces - for (j = 0; j < changes; j++) - if (upinfo[j].type == UPDATE_NEWPIECE) - { - newcount++; - newidx.Write(upinfo[j].name, 8); - up.Seek(upinfo[j].offset, CFile::begin); - up.Read(&tmp, 64+sizeof(short[6])); - newidx.Write(tmp, 64+sizeof(short[6])); - binoff = newbin.GetLength(); - newidx.Write(&binoff, sizeof(binoff)); - - up.Read(&cs, sizeof(cs)); - membuf = malloc(cs); - up.Read(membuf, cs); - newbin.Write(membuf, cs); - free (membuf); - } - - WORD moved; - up.Seek(-(LONG)(sizeof(WORD)*2), CFile::end); - up.Read(&moved, sizeof(WORD)); - cs = sizeof(WORD)+moved*16; - up.Seek(-(LONG)(cs), CFile::current); - membuf = malloc(cs); - up.Read(membuf, cs); - newidx.Write(membuf, cs); - free (membuf); - - nextoff = newbin.GetLength(); - newidx.Write(&nextoff, sizeof(DWORD)); - newidx.Write(&newcount, sizeof(WORD)); - - free(upinfo); - oldidx.Close(); - oldbin.Close(); - newidx.Close(); - newbin.Close(); - up.Close(); + LoadUpdate(filedlg.GetPathName()); // update m_Parts UpdateList(); m_bReload = TRUE; -*/ + return TRUE; } -- cgit v1.2.3