From f11f52e36163470a530fba9060d4339e617a3001 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 5 Jan 2000 15:28:13 +0000 Subject: Added a program to create the library updates git-svn-id: http://svn.leocad.org/trunk@48 c7d43263-9d01-0410-8a33-9dba5d9f93d6 --- tools/update/update.cpp | 322 ++++++++++++++++++++++++++++++++++++++++++++++++ tools/update/update.dsp | 99 +++++++++++++++ tools/update/update.dsw | 29 +++++ tools/update/update.h | 6 + 4 files changed, 456 insertions(+) create mode 100755 tools/update/update.cpp create mode 100755 tools/update/update.dsp create mode 100755 tools/update/update.dsw create mode 100755 tools/update/update.h (limited to 'tools/update') diff --git a/tools/update/update.cpp b/tools/update/update.cpp new file mode 100755 index 0000000..e933945 --- /dev/null +++ b/tools/update/update.cpp @@ -0,0 +1,322 @@ +#ifdef LC_WINDOWS +#include +#endif +#include +#include "defines.h" +#include "file.h" +#include "update.h" + +#define UPDATE_DELETE 0x00 +#define UPDATE_DESCRIPTION 0x01 +#define UPDATE_DRAWINFO 0x02 +#define UPDATE_NEWPIECE 0x04 + +typedef struct +{ + char oldname[9]; + char newname[9]; +} LC_MOVED_DATA; + +typedef struct +{ + char name[9]; + char description[65]; + short bricksize[6]; + unsigned char flags; + unsigned long group; + unsigned long offset; + unsigned long size; +} LC_PIECEINFO; + +// ======================================================== + +static void message(File* f, char *fmt, ...) +{ + char s[300]; + va_list argptr; + va_start(argptr, fmt); + vsprintf(s, fmt, argptr); + va_end(argptr); + + printf(s); + f->Write(s, strlen(s)); +} + +// ======================================================== + +int main(int argc, char* argv[]) +{ + char oldpath[LC_MAXPATH], newpath[LC_MAXPATH], str[LC_MAXPATH]; + FileDisk oldidx, oldbin, newidx, newbin, out, txt; + int number; + + if (argc != 4) + { + printf("LeoCAD Libray Update\n"); + printf("Old path: "); + scanf("%s", oldpath); + printf("New path: "); + scanf("%s", newpath); + printf("Update number: "); + scanf("%d", &number); + } + else + { + strcpy(oldpath, argv[1]); + strcpy(newpath, argv[2]); + sscanf(argv[3], "%d", &number); + } + + if ((oldpath[strlen(oldpath)-1] != '/') && + (oldpath[strlen(oldpath)-1] != '\\')) + strcat(oldpath, "/"); + + if ((newpath[strlen(newpath)-1] != '/') && + (newpath[strlen(newpath)-1] != '\\')) + strcat(newpath, "/"); + + // Open files + strcpy(str, oldpath); + strcat(str, "pieces.bin"); + if (!oldbin.Open(str, "rb")) + return 1; + + strcpy(str, oldpath); + strcat(str, "pieces.idx"); + if (!oldidx.Open(str, "rb")) + return 1; + + strcpy(str, newpath); + strcat(str, "pieces.bin"); + if (!newbin.Open(str, "rb")) + return 1; + + strcpy(str, newpath); + strcat(str, "pieces.idx"); + if (!newidx.Open(str, "rb")) + return 1; + + sprintf(str, "%supdate%02d.lup", newpath, number); + if (!out.Open(str, "wb")) + return 1; + + sprintf(str, "%supdate%02d.txt", newpath, number); + if (!txt.Open(str, "wt")) + return 1; + + // Now we start the update + const char id[32] = "LeoCAD piece library update\0\0\0\0"; + unsigned short oldcount, newcount, changes = 0; + LC_PIECEINFO *oldinfo, *newinfo; + void *oldbuf, *newbuf; + unsigned long sz; + unsigned char bt; + int i, j; + + out.Write(id, 32); + bt = 2; // version + out.WriteByte(&bt, 1); + bt = number; // update number + out.WriteByte(&bt, 1); + + oldidx.Seek(-2, SEEK_END); + oldidx.ReadShort(&oldcount, 1); + oldidx.Seek(34, SEEK_SET); + newidx.Seek (-2, SEEK_END); + newidx.ReadShort(&newcount, 1); + newidx.Seek(34, SEEK_SET); + message(&txt, "Old count: %d, New count: %d\n\n", oldcount, newcount); + + oldinfo = (LC_PIECEINFO*)malloc(sizeof(LC_PIECEINFO)*oldcount); + memset(oldinfo, 0, sizeof(LC_PIECEINFO)*oldcount); + newinfo = (LC_PIECEINFO*)malloc(sizeof(LC_PIECEINFO)*newcount); + memset(newinfo, 0, sizeof(LC_PIECEINFO)*newcount); + + for (i = 0; i < oldcount; i++) + { + oldidx.Read(&oldinfo[i].name, 8); + oldidx.Read(&oldinfo[i].description, 64); + oldidx.Read(&oldinfo[i].bricksize, 12); + oldidx.ReadByte(&oldinfo[i].flags, 1); + oldidx.ReadLong(&oldinfo[i].group, 1); + oldidx.ReadLong(&oldinfo[i].offset, 1); + oldidx.ReadLong(&oldinfo[i].size, 1); + } + + for (i = 0; i < newcount; i++) + { + newidx.Read(&newinfo[i].name, 8); + newidx.Read(&newinfo[i].description, 64); + newidx.Read(&newinfo[i].bricksize, 12); + newidx.ReadByte(&newinfo[i].flags, 1); + newidx.ReadLong(&newinfo[i].group, 1); + newidx.ReadLong(&newinfo[i].offset, 1); + newidx.ReadLong(&newinfo[i].size, 1); + } + + for (i = 0; i < oldcount; i++) + { + unsigned char update = 0; + + for (j = 0; j < newcount; j++) + { + if (strcmp(newinfo[j].name, oldinfo[i].name) == 0) + { + // Compare Descriptions + if (strcmp(newinfo[j].description, oldinfo[i].description) != 0) + update |= UPDATE_DESCRIPTION; + + // Compare drawinfo + sz = newinfo[j].size; + if (sz != oldinfo[i].size) + { + update |= UPDATE_DRAWINFO; + newbuf = malloc(sz); + newbin.Seek(newinfo[j].offset, SEEK_SET); + newbin.Read(newbuf, sz); + } + else + { + oldbuf = malloc(sz); + oldbin.Seek(oldinfo[i].offset, SEEK_SET); + oldbin.Read(oldbuf, sz); + newbuf = malloc(sz); + newbin.Seek(newinfo[j].offset, SEEK_SET); + newbin.Read(newbuf, sz); + + if (memcmp(newbuf, oldbuf, sz) != 0) + update |= UPDATE_DRAWINFO; + else + free(newbuf); + + free(oldbuf); + } + break; + } + } + + // deleted + if (j == newcount) + { + message(&txt, "%s (%s) deleted\n", oldinfo[i].name, oldinfo[i].description); + out.Write(&oldinfo[i].name, 8); + out.WriteByte(&update, 1); + changes++; + } + else + { + if (update != 0) + { + message(&txt, "%s (%s) updated ", oldinfo[i].name, oldinfo[i].description); + if (update & UPDATE_DESCRIPTION) + { + strcat(str, "description"); + if (update & UPDATE_DRAWINFO) + strcat(str, " & "); + } + if (update & UPDATE_DRAWINFO) + strcat(str, "draw info"); + + changes++; + out.Write(&oldinfo[i].name, 8); + out.WriteByte(&update, 1); + + if (update & UPDATE_DESCRIPTION) + { + out.Write(&newinfo[j].description, 64); + out.WriteLong(&newinfo[j].group, 1); + } + + if (update & UPDATE_DRAWINFO) + { + out.Write(&newinfo[j].bricksize, 12); + out.WriteByte(&newinfo[j].flags, 1); + out.WriteLong(&sz, 1); + out.Write(newbuf, sz); + free(newbuf); + } + + message(&txt, "\n"); + } + } + } + + message(&txt, "------------\n"); + + for (j = 0; j < newcount; j++) + { + for (i = 0; i < oldcount; i++) + if (strcmp(newinfo[j].name, oldinfo[i].name) == 0) + break; + + // found a new piece + if (i == oldcount) + { + message(&txt, "%s (%s) added\n", newinfo[j].name, newinfo[j].description); + + bt = UPDATE_NEWPIECE; + out.Write(&newinfo[j].name, 8); + out.Write(&bt, 1); + changes++; + + sz = newinfo[j].size; + newbuf = malloc(sz); + newbin.Seek(newinfo[j].offset, SEEK_SET); + newbin.Read(newbuf, sz); + out.Write(&newinfo[j].description, 64); + out.Write(&newinfo[j].bricksize, 12); + out.WriteLong(&newinfo[j].group, 1); + out.WriteByte(&newinfo[j].flags, 1); + out.WriteLong(&sz, 1); + out.Write(newbuf, sz); + free(newbuf); + } + } + + // Moved pieces list + strcpy(str, newpath); + strcat(str, "moved.txt"); + FILE* f = fopen(str, "rt"); + char buf[100], f1[9], f2[9], *ptr, *ptr2; + unsigned short movecount = 0; + + while (fgets(buf, 100, f) != NULL) + { + if (ptr = strchr(buf, ' ')) + { + *ptr = 0; + memset(f1, 0, 9); + strcpy(f1, buf); + ptr++; + if (ptr2 = strchr(ptr, ' ')) + { + *ptr2 = 0; + memset(f2, 0, 9); + strcpy(f2, ptr); + movecount++; + strupr(f1); + strupr(f2); + out.Write(f1, 8); + out.Write(f2, 8); + } + } + } + fclose(f); + + message(&txt, "\nTotal changes: %d\nMoved files: %d\n", changes, movecount); + + out.WriteShort(&movecount, 1); + out.WriteShort(&changes, 1); + + free(oldinfo); + free(newinfo); + + oldidx.Close(); + oldbin.Close(); + newidx.Close(); + newbin.Close(); + out.Close(); + txt.Close(); + + return 0; +} diff --git a/tools/update/update.dsp b/tools/update/update.dsp new file mode 100755 index 0000000..9dd0671 --- /dev/null +++ b/tools/update/update.dsp @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="update" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=update - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "update.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "update.mak" CFG="update - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "update - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "update - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "update - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /I "../../common" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "LC_WINDOWS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "update - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "../../common" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "LC_WINDOWS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "update - Win32 Release" +# Name "update - Win32 Debug" +# Begin Source File + +SOURCE=..\..\common\file.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\common\file.h +# End Source File +# Begin Source File + +SOURCE=.\update.cpp +# End Source File +# Begin Source File + +SOURCE=.\update.h +# End Source File +# End Target +# End Project diff --git a/tools/update/update.dsw b/tools/update/update.dsw new file mode 100755 index 0000000..a5ca0a2 --- /dev/null +++ b/tools/update/update.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 5.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "update"=.\update.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/tools/update/update.h b/tools/update/update.h new file mode 100755 index 0000000..f3ec823 --- /dev/null +++ b/tools/update/update.h @@ -0,0 +1,6 @@ +#ifndef _UPDATE_H_ +#define _UPDATE_H_ + + + +#endif // _UPDATE_H_ -- cgit v1.2.3