c4group: Remove unused -a, -m, -e, -d, -r, -o commands

The new release scripts use -p instead. This doesn't make c4group a lot
simpler, but every bit helps.
Günther Brammer 2010-12-05 19:04:40 +01:00
parent ccf84f5dbe
commit 47594765cb
5 changed files with 15 additions and 867 deletions

View File

@ -684,7 +684,6 @@ EXTRA_DIST = \
src/res/Play_Trans.png \
src/res/Rect_Trans.png \
src/res/Static_Trans.png \
src/c4group/c4group_cmdl.cpp \
src/c4group/resource.h \
src/c4group/Resource.rc \
src/res/brush1.bmp \

View File

@ -97,12 +97,6 @@ void C4Group_SetSortList(const char **ppSortList)
C4Group_SortList = ppSortList;
}
void C4Group_SetPasswords(const char *szPassword)
{
if (!szPassword) C4Group_Passwords[0]=0;
else SCopy(szPassword,C4Group_Passwords,CFG_MaxString);
}
void C4Group_SetTempPath(const char *szPath)
{
if (!szPath || !szPath[0]) C4Group_TempPath[0]=0;
@ -135,16 +129,7 @@ int C4Group_GetCreation(const char *szFilename)
C4Group hGroup;
if (hGroup.Open(szFilename)) { iResult=hGroup.GetCreation(); hGroup.Close(); }
return iResult;
}
bool C4Group_SetOriginal(const char *szFilename, bool fOriginal)
{
C4Group hGroup;
if (!hGroup.Open(szFilename)) return false;
hGroup.MakeOriginal(fOriginal);
if (!hGroup.Close()) return false;
return true;
}
}
bool C4Group_CopyItem(const char *szSource, const char *szTarget1, bool fNoSort, bool fResetAttributes)
{
@ -542,7 +527,7 @@ void C4GroupHeader::Init()
Ver1=C4GroupFileVer1; Ver2=C4GroupFileVer2;
Entries=0;
SCopy("New C4Group",pad1,C4GroupMaxMaker);
Password[0]=0;
pad2[0]=0;
}
C4GroupEntryCore::C4GroupEntryCore()
@ -597,7 +582,6 @@ C4Group::C4Group()
Init();
StdOutput=false;
fnProcessCallback=NULL;
MadeOriginal=false;
NoSort=false;
}
@ -917,9 +901,6 @@ bool C4Group::Close()
// Creation stamp
Head.Creation = time(NULL);
// Lose original on any save unless made in this session
if (!MadeOriginal) Head.Original=0;
// Automatic sort
SortByList(C4Group_SortList);
@ -1977,95 +1958,7 @@ bool C4Group::FindNextEntry(const char *szWildCard,
if (fChild) *fChild=!!centry->ChildGroup;
return true;
}
#ifdef _WIN32
bool C4Group::Add(const char *szFiles)
{
bool fMove = false;
if (StdOutput) printf("%s...\n",fMove ? "Moving" : "Adding");
// Add files & directories
char szFileName[_MAX_FNAME+1];
int iFileCount = 0;
long lAttrib = 0x037; // _A_ALL
struct _finddata_t fdt; long fdthnd;
// Process segmented path & search wildcards
char cSeparator = (SCharCount(';', szFiles) ? ';' : '|');
for (int cseg=0; SCopySegment(szFiles, cseg, szFileName, cSeparator); cseg++)
if ((fdthnd=_findfirst( (char*) szFileName, &fdt))>=0)
{
do
{
if (fdt.attrib & lAttrib)
{
// ignore
if (C4Group_TestIgnore(fdt.name)) continue;
// Compose item path
SCopy(szFiles,szFileName,_MAX_FNAME); *GetFilename(szFileName) = 0;
SAppend(fdt.name, szFileName, _MAX_FNAME);
// File count
iFileCount++;
// Process output & callback
if (StdOutput) printf("%s\n",GetFilename(szFileName));
if (fnProcessCallback) fnProcessCallback(GetFilename(szFileName),0); // cbytes/tbytes
// AddEntryOnDisk
AddEntryOnDisk(szFileName, NULL, fMove);
}
}
while (_findnext(fdthnd,&fdt)==0);
_findclose(fdthnd);
}
if (StdOutput) printf("%d file(s) %s.\n",iFileCount,fMove ? "moved" : "added");
return true;
}
bool C4Group::Move(const char *szFiles)
{
bool fMove = true;
if (StdOutput) printf("%s...\n",fMove ? "Moving" : "Adding");
// Add files & directories
char szFileName[_MAX_FNAME+1];
int iFileCount = 0;
long lAttrib = 0x037; // _A_ALL
struct _finddata_t fdt; long fdthnd;
// Process segmented path & search wildcards
char cSeparator = (SCharCount(';', szFiles) ? ';' : '|');
for (int cseg=0; SCopySegment(szFiles, cseg, szFileName, cSeparator); cseg++)
if ((fdthnd=_findfirst( (char*) szFileName, &fdt))>=0)
{
do
{
if (fdt.attrib & lAttrib)
{
// ignore
if (C4Group_TestIgnore(fdt.name)) continue;
// Compose item path
SCopy(szFiles,szFileName,_MAX_FNAME); *GetFilename(szFileName) = 0;
SAppend(fdt.name, szFileName, _MAX_FNAME);
// File count
iFileCount++;
// Process output & callback
if (StdOutput) printf("%s\n",GetFilename(szFileName));
if (fnProcessCallback) fnProcessCallback(GetFilename(szFileName),0); // cbytes/tbytes
// AddEntryOnDisk
AddEntryOnDisk(szFileName, NULL, fMove);
}
}
while (_findnext(fdthnd,&fdt)==0);
_findclose(fdthnd);
}
if (StdOutput) printf("%d file(s) %s.\n",iFileCount,fMove ? "moved" : "added");
return true;
}
#endif
bool C4Group::Add(const char *szName, void *pBuffer, int iSize, bool fChild, bool fHoldBuffer, int iTime, bool fExecutable)
{
return AddEntry(C4GRES_InMemory,
@ -2244,28 +2137,6 @@ bool C4Group::LoadEntryString(const char *szEntryName, StdStrBuf &Buf)
return true;
}
void C4Group::SetPassword(const char *szPassword)
{
if (!SEqual(szPassword,Head.Password)) Modified=true;
SCopy(szPassword,Head.Password,C4GroupMaxPassword);
}
const char* C4Group::GetPassword()
{
return Head.Password;
}
int C4Group::GetVersion()
{
return Head.Ver1*10+Head.Ver2;
}
void C4Group::SetProcessCallback(bool (*fnCallback)(const char *, int))
{
fnProcessCallback = fnCallback;
}
int SortRank(const char *szElement, const char *szSortList)
{
int cnt;
@ -2420,32 +2291,6 @@ StdStrBuf C4Group::GetFullName() const
return sResult;
}
void C4Group::MakeOriginal(bool fOriginal)
{
Modified=true;
if (fOriginal) { Head.Original=1234567; MadeOriginal=true; }
else { Head.Original=0; MadeOriginal=false; }
}
bool C4Group::GetOriginal()
{
return (Head.Original==1234567);
}
bool C4Group::Add(const char *szEntryname, C4Group &hSource)
{
char *bpBuf; size_t iSize;
// Load entry from source group to buffer
if (!hSource.LoadEntry(szEntryname, &bpBuf, &iSize)) return false;
// Determine executable
bool fExecutable = GetEntry(szEntryname) ? !!GetEntry(szEntryname)->Executable : false;
// Add entry (hold buffer)
if (!Add(szEntryname, bpBuf, iSize, false, true, 0, fExecutable))
{ delete [] bpBuf; return false; }
// Success
return true;
}
bool C4Group::CalcCRC32(C4GroupEntry *pEntry)
{
// checksum already calculated?
@ -2593,7 +2438,7 @@ void C4Group::PrintInternals(const char *szIndent)
//printf("%sHead.Maker: '%s'\n", szIndent, Head.Maker);
//printf("Head.Password: '%s'\n", szIndent, Head.Password);
printf("%sHead.Creation: %d\n", szIndent, Head.Creation);
printf("%sHead.Original: %d\n", szIndent, Head.Original);
//printf("%sHead.Original: %d\n", szIndent, Head.Original);
for (C4GroupEntry * p = FirstEntry; p; p = p->Next)
{
printf("%sEntry '%s':\n", szIndent, p->FileName);

View File

@ -69,7 +69,6 @@ const int32_t C4GroupSwapThreshold = 10 * 1024 * 1024;
#define C4GroupFileID "RedWolf Design GrpFolder"
bool C4Group_TestIgnore(const char *szFilename);
void C4Group_SetPasswords(const char *szPassword);
void C4Group_SetTempPath(const char *szPath);
const char* C4Group_GetTempPath();
void C4Group_SetSortList(const char **ppSortList);
@ -103,9 +102,10 @@ public:
int Ver1,Ver2;
int Entries;
char pad1[C4GroupMaxMaker+2];
char Password[C4GroupMaxPassword+2];
int Creation,Original;
BYTE fbuf[92];
char pad2[C4GroupMaxPassword+2];
int Creation;
int pad3;
BYTE pad4[92];
public:
void Init();
};
@ -190,7 +190,6 @@ protected:
bool StdOutput;
bool (*fnProcessCallback)(const char *, int);
char ErrorString[C4GroupMaxError+1];
bool MadeOriginal;
bool NoSort; // If this flag is set, all entries will be marked NoSort in AddEntry
@ -202,14 +201,11 @@ public:
bool OpenAsChild(C4Group *pMother, const char *szEntryName, bool fExclusive=false, bool fCreate=false);
bool OpenChild(const char* strEntry);
bool OpenMother();
bool Add(const char *szFiles);
bool Add(const char *szFile, const char *szAddAs);
bool Add(const char *szName, void *pBuffer, int iSize, bool fChild = false, bool fHoldBuffer = false, int iTime = 0, bool fExecutable = false);
bool Add(const char *szName, StdBuf &pBuffer, bool fChild = false, bool fHoldBuffer = false, int iTime = 0, bool fExecutable = false);
bool Add(const char *szName, StdStrBuf &pBuffer, bool fChild = false, bool fHoldBuffer = false, int iTime = 0, bool fExecutable = false);
bool Add(const char *szEntryname, C4Group &hSource);
bool Merge(const char *szFolders);
bool Move(const char *szFiles);
bool Move(const char *szFile, const char *szAddAs);
bool Extract(const char *szFiles, const char *szExtractTo=NULL, const char *szExclude=NULL);
bool ExtractEntry(const char *szFilename, const char *szExtractTo=NULL);
@ -219,7 +215,6 @@ public:
bool Sort(const char *szSortList);
bool SortByList(const char **ppSortList, const char *szFilename=NULL);
bool View(const char *szFiles);
bool GetOriginal();
bool AccessEntry(const char *szWildCard,
size_t *iSize=NULL, char *sFileName=NULL,
bool *fChild=NULL, bool NeedsToBeAGroup = false);
@ -241,13 +236,9 @@ public:
bool fStartAtFilename=false);
bool Read(void *pBuffer, size_t iSize);
bool Advance(int iOffset);
void SetPassword(const char *szPassword);
void SetStdOutput(bool fStatus);
void SetProcessCallback(bool (*fnCallback)(const char *, int));
void MakeOriginal(bool fOriginal);
void ResetSearch();
const char *GetError();
const char *GetPassword();
const char *GetName();
StdStrBuf GetFullName() const;
int EntryCount(const char *szWildCard=NULL);
@ -255,7 +246,6 @@ public:
size_t AccessedEntrySize() { return iCurrFileSize; } // retrieve size of last accessed entry
int EntryTime(const char *szFilename);
unsigned int EntryCRC32(const char *szWildCard=NULL);
int GetVersion();
int GetCreation();
int GetStatus();
inline bool IsOpen() { return Status != GRPF_Inactive; }

View File

@ -1,571 +0,0 @@
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2002, 2006, 2008 Sven Eberhardt
* Copyright (c) 2003-2004, 2007 Matthes Bender
* Copyright (c) 2004, 2007-2008 Peter Wortmann
* Copyright (c) 2005 Günther Brammer
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
*
* Portions might be copyrighted by other authors who have contributed
* to OpenClonk.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* See isc_license.txt for full license and disclaimer.
*
* "Clonk" is a registered trademark of Matthes Bender.
* See clonk_trademark_license.txt for full license.
*/
/* C4Group command line executable */
// Version 1.0 November 1997
// 1.1 November 1997
// 1.2 February 1998
// 1.3 March 1998
// 1.4 April 1998
// 1.5 May 1998
// 1.6 November 1998
// 1.7 December 1998
// 1.8 February 1999
// 1.9 May 1999
// 2.0 June 1999
// 2.6 March 2001
// 2.7 June 2001
// 2.8 June 2002
// 4.95.0 November 2003
// 4.95.4 July 2005 PORT/HEAD mixmax
#include <C4Include.h>
#include <C4ConfigShareware.h>
#include <StdRegistry.h>
#include <C4Group.h>
#include <C4Version.h>
#include <C4Update.h>
#include <shellapi.h>
#include <conio.h>
int globalArgC;
char **globalArgV;
int iFirstCommand = -1;
bool fQuiet = false;
bool fRecursive = false;
bool fRegisterShell = false;
bool fUnregisterShell = false;
bool fPromptAtEnd = false;
char strExecuteAtEnd[_MAX_PATH + 1] = "";
int iResult = 0;
C4ConfigShareware Config;
C4Config *GetCfg() { return &Config; }
#ifdef _WIN32
#ifdef _DEBUG
int dbg_printf(const char *strMessage, ...)
{
va_list args; va_start(args, strMessage);
// Compose formatted message
StdStrBuf Buf;
Buf.FormatV(strMessage, args);
// Log
OutputDebugString(Buf.getData());
return printf(Buf.getData());
}
#define printf dbg_printf
#endif
#endif
bool ProcessGroup(const char *szFilename)
{
C4Group hGroup;
int iArg;
bool fDeleteGroup = false;
hGroup.SetStdOutput(true);
int argc = globalArgC;
char **argv = globalArgV;
// Current filename
if (!fQuiet)
printf("Group: %s\n",szFilename);
// Open group file
if (hGroup.Open(szFilename, true))
{
// No commands: display contents
if (iFirstCommand<0)
{
hGroup.View("*");
}
// Process commands
else
for (iArg=iFirstCommand; iArg<argc; iArg++)
{
// This argument is a command
if (argv[iArg][0]=='-')
{
// Handle commands
switch (argv[iArg][1])
{
// Add
case 'a':
if ((iArg+1>=argc) || (argv[iArg+1][0]=='-'))
printf("Missing argument for add command\n");
else
{
if ((argv[iArg][2]=='s') || (argv[iArg][2] && (argv[iArg][3]=='s')) )
{
if ((iArg+2>=argc) || (argv[iArg+2][0]=='-'))
printf("Missing argument for add as command\n");
else
{ hGroup.Add(argv[iArg+1],argv[iArg+2]); iArg+=2; }
}
else
#ifdef _WIN32
{ hGroup.Add(argv[iArg+1]); iArg++; }
#else
{ hGroup.Add(argv[iArg+1], argv[iArg+1]); iArg++; }
#endif
}
break;
// Move
case 'm':
if ((iArg+1>=argc) || (argv[iArg+1][0]=='-'))
printf("Missing argument for move command\n");
else
#ifdef _WIN32
{ hGroup.Move(argv[iArg+1]); iArg++; }
#else
{ hGroup.Move(argv[iArg+1], argv[iArg+1]); iArg++; }
#endif
break;
// Extract
case 'e':
if ((iArg+1>=argc) || (argv[iArg+1][0]=='-'))
printf("Missing argument for extract command\n");
else
{
if ((argv[iArg][2]=='t') || (argv[iArg][2] && (argv[iArg][3]=='s')) )
{
if ((iArg+2>=argc) || (argv[iArg+2][0]=='-'))
printf("Missing argument for extract as command\n");
else
{ hGroup.Extract(argv[iArg+1],argv[iArg+2]); iArg+=2; }
}
else
{ hGroup.Extract(argv[iArg+1]); iArg++; }
}
break;
// Delete
case 'd':
if ((iArg+1>=argc) || (argv[iArg+1][0]=='-'))
printf("Missing argument for delete command\n");
else
{ hGroup.Delete(argv[iArg+1], fRecursive); iArg++; }
break;
// Sort
case 's':
// First sort parameter overrides default Clonk sort list
C4Group_SetSortList(NULL);
// Missing argument
if ((iArg+1>=argc) || (argv[iArg+1][0]=='-'))
printf("Missing argument for sort command\n");
// Sort, advance to next argument
else
{ hGroup.Sort(argv[iArg+1]); iArg++; }
break;
// Rename
case 'r':
if ((iArg+2>=argc) || (argv[iArg+1][0]=='-') || (argv[iArg+2][0]=='-'))
printf("Missing argument(s) for rename command\n");
else
{ hGroup.Rename(argv[iArg+1],argv[iArg+2]); iArg+=2; }
break;
// View
case 'v':
if ((iArg+1>=argc) || (argv[iArg+1][0]=='-'))
{ hGroup.View("*"); }
else
{ hGroup.View(argv[iArg+1]); iArg++; }
break;
// Make original
case 'o':
hGroup.MakeOriginal(true);
break;
// Pack
case 'p':
printf("Packing...\n");
// Close
if (!hGroup.Close()) printf("Closing failed: %s\n",hGroup.GetError());
// Pack
else if (!C4Group_PackDirectory(szFilename)) printf("Pack failed\n");
// Reopen
else if (!hGroup.Open(szFilename)) printf("Reopen failed: %s\n",hGroup.GetError());
break;
// Unpack
case 'u':
printf("Unpacking...\n");
// Close
if (!hGroup.Close()) printf("Closing failed: %s\n",hGroup.GetError());
// Unpack
else if (!C4Group_UnpackDirectory(szFilename)) printf("Unpack failed\n");
// Reopen
else if (!hGroup.Open(szFilename)) printf("Reopen failed: %s\n",hGroup.GetError());
break;
// Unpack
case 'x':
printf("Exploding...\n");
// Close
if (!hGroup.Close()) printf("Closing failed: %s\n",hGroup.GetError());
// Explode
else if (!C4Group_ExplodeDirectory(szFilename)) printf("Unpack failed\n");
// Reopen
else if (!hGroup.Open(szFilename)) printf("Reopen failed: %s\n",hGroup.GetError());
break;
// Print maker
case 'k':
printf("%s\n",hGroup.GetMaker());
break;
// Generate update
case 'g':
if ((iArg + 3 >= argc) || (argv[iArg+1][0] == '-') || (argv[iArg+2][0] == '-') || (argv[iArg+3][0] == '-'))
printf("Update generation failed: too few arguments\n");
else
{
C4UpdatePackage Upd;
// Close
if (!hGroup.Close()) printf("Closing failed: %s\n",hGroup.GetError());
// generate
else if (!Upd.MakeUpdate(argv[iArg+1], argv[iArg+2], szFilename, argv[iArg+3]))
printf("Update generation failed.\n");
// Reopen
else if (!hGroup.Open(szFilename)) printf("Reopen failed: %s\n",hGroup.GetError());
iArg+=3;
}
break;
// Apply update
case 'y':
printf("Applying update...\n");
if (C4Group_ApplyUpdate(hGroup))
{ if (argv[iArg][2]=='d') fDeleteGroup = true; }
else
printf("Update failed.\n");
break;
// Optimize update generation target
case 'z':
if ((iArg + 1 >= argc) || (argv[iArg+1][0] == '-'))
printf("Missing parameter for optimization\n");
else
{
printf("Optimizing %s...\n", argv[iArg+1]);
if (!C4UpdatePackage::Optimize(&hGroup, argv[iArg+1]))
printf("Optimization failed.\n");
iArg++;
}
break;
#ifdef _DEBUG
// Print internals
case 'q':
hGroup.PrintInternals();
break;
#endif
// Wait
case 'w':
if ((iArg+1>=argc) || (argv[iArg+1][0]=='-'))
printf("Missing argument for wait command\n");
else
{
int iMilliseconds = 0;
sscanf(argv[iArg+1], "%d", &iMilliseconds);
// Wait for specified time
if (iMilliseconds > 0)
{
printf("Waiting...\n");
Sleep(iMilliseconds);
}
// Wait for specified process to end
else
{
printf("Waiting for %s to end", argv[iArg+1]);
for (int i = 0; FindWindow(NULL, argv[iArg+1]) && (i < 5); i++)
{
Sleep(1000);
printf(".");
}
printf("\n");
}
iArg++;
}
break;
// Undefined
default:
printf("Unknown command: %s\n",argv[iArg]);
break;
}
}
else
{
printf("Invalid parameter %s\n",argv[iArg]);
}
}
// Error: output status
if (!SEqual(hGroup.GetError(),"No Error"))
printf("Status: %s\n",hGroup.GetError());
// Close group file
if (!hGroup.Close())
printf("Closing: %s\n",hGroup.GetError());
// Delete group file if desired (i.e. after apply update)
if (fDeleteGroup)
{
printf("Deleting %s...\n", GetFilename(szFilename));
EraseItem(szFilename);
}
}
// Couldn't open group
else
{
printf("Status: %s\n",hGroup.GetError());
}
// Done
return true;
}
int RegisterShellExtensions()
{
#ifdef _WIN32
char strModule[2048];
char strCommand[2048];
char strClass[128];
GetModuleFileName(NULL, strModule, 2048);
// Groups
const char *strClasses = "Clonk4.Definition;Clonk4.Folder;Clonk4.Group;Clonk4.Player;Clonk4.Scenario;Clonk4.Update;Clonk4.Weblink;Clonk4.Object";
for (int i = 0; SCopySegment(strClasses, i, strClass); i++)
{
// Unpack
sprintf(strCommand, "\"%s\" \"%%1\" \"-u\"", strModule);
if (!SetRegShell(strClass, "MakeFolder", "C4Group Unpack", strCommand)) return 0;
// Explode
sprintf(strCommand, "\"%s\" \"%%1\" \"-x\"", strModule);
if (!SetRegShell(strClass, "ExplodeFolder", "C4Group Explode", strCommand)) return 0;
}
// Directories
const char *strClasses2 = "Directory";
for (int i = 0; SCopySegment(strClasses2, i, strClass); i++)
{
// Pack
sprintf(strCommand, "\"%s\" \"%%1\" \"-p\"", strModule);
if (!SetRegShell(strClass, "MakeGroupFile", "C4Group Pack", strCommand)) return 0;
}
// Done
#endif
return 1;
}
int UnregisterShellExtensions()
{
#ifdef _WIN32
char strModule[2048];
char strClass[128];
GetModuleFileName(NULL, strModule, 2048);
// Groups
const char *strClasses = "Clonk4.Definition;Clonk4.Folder;Clonk4.Group;Clonk4.Player;Clonk4.Scenario;Clonk4.Update;Clonk4.Weblink";
for (int i = 0; SCopySegment(strClasses, i, strClass); i++)
{
// Unpack
if (!RemoveRegShell(strClass, "MakeFolder")) return 0;
// Explode
if (!RemoveRegShell(strClass, "ExplodeFolder")) return 0;
}
// Directories
const char *strClasses2 = "Directory";
for (int i = 0; SCopySegment(strClasses2, i, strClass); i++)
{
// Pack
if (!RemoveRegShell(strClass, "MakeGroupFile")) return 0;
}
// Done
#endif
return 1;
}
bool Log(const char *msg)
{
if (!fQuiet)
printf("%s\n", msg);
return 1;
}
bool LogFatal(const char *msg) { return Log(msg); }
bool LogF(const char *strMessage, ...)
{
va_list args; va_start(args, strMessage);
// Compose formatted message
StdStrBuf Buf;
Buf.FormatV(strMessage, args);
// Log
return Log(Buf.getData());
}
void StdCompilerWarnCallback(void *pData, const char *szPosition, const char *szError)
{
const char *szName = reinterpret_cast<const char *>(pData);
if (!szPosition || !*szPosition)
LogF("WARNING: %s: %s", szName, szError);
else
LogF("WARNING: %s (%s): %s", szName, szPosition, szError);
}
int main(int argc, char *argv[])
{
// Scan options (scan including first parameter - this means the group filename cannot start with a '/'...)
for (int i = 1; i < argc; i++)
{
// Option encountered
if (argv[i][0]=='/')
switch (argv[i][1])
{
// Quiet mode
case 'q': fQuiet = true; break;
// Recursive mode
case 'r': fRecursive = true; break;
// Register shell
case 'i': fRegisterShell = true; break;
// Unregister shell
case 'u': fUnregisterShell = true; break;
// Prompt at end
case 'p': fPromptAtEnd = true; break;
// Execute at end
case 'x': SCopy(argv[i] + 3, strExecuteAtEnd, _MAX_PATH); break;
// Unknown
default: printf("Unknown option %s\n",argv[i]); break;
}
// Command encountered: no more options expected
if (argv[i][0]=='-')
{
iFirstCommand = i;
break;
}
}
// Program info
if (!fQuiet)
printf("RedWolf Design C4Group %s\n", C4VERSION);
// Registration check
Config.Init();
bool fWasQuiet = fQuiet; fQuiet = true; // prevent premature logging of registration error
Config.Load(false);
fQuiet = fWasQuiet;
// Init C4Group
C4Group_SetMaker(Config.General.Name); // This makes no sense if unregistered but it is assumed that no groups can be written if unregistered
C4Group_SetTempPath(Config.General.TempPath);
C4Group_SetSortList(C4CFN_FLS);
// Display current working directory
if (!fQuiet)
{
char strWorkingDirectory[_MAX_PATH+1] = "";
GetCurrentDirectory(_MAX_PATH, strWorkingDirectory);
printf("Location: %s\n", strWorkingDirectory);
}
// Store command line parameters
globalArgC = argc;
globalArgV = argv;
// Register shell
if (fRegisterShell)
if (RegisterShellExtensions())
printf("Shell extensions registered.\n");
else
printf("Error registering shell extensions. You might need administrator rights.\n");
// Unregister shell
if (fUnregisterShell)
if (UnregisterShellExtensions())
printf("Shell extensions removed.\n");
else
printf("Error removing shell extensions.\n");
// At least one parameter (filename, not option or command): process file(s)
if ((argc>1) && (argv[1][0] != '/') && (argv[1][0] != '-')) // ...remember filenames cannot start with a forward slash because of options format
{
// Wildcard in filename: use file search
if (SCharCount('*',argv[1]))
ForEachFile(argv[1], &ProcessGroup);
// Only one file
else
ProcessGroup(argv[1]);
}
// Too few parameters: output help (if we didn't register stuff)
else if (!fRegisterShell && !fUnregisterShell)
{
printf("\n");
printf("Usage: c4group group [options] command(s)\n\n");
printf("Commands: -a[s] Add [as] -m Move -e[t] Extract [to]\n");
printf(" -v View -d Delete -r Rename -s Sort\n");
printf(" -p Pack -u Unpack -x Explode\n");
printf(" -k Print maker\n");
printf(" -g [source] [target] [title] Make update\n");
printf(" -y[d] Apply update [and delete group file]\n");
printf(" -z Optimize a group to be similar (smaller update)\n");
printf("\n");
printf("Options: /q Quiet /r Recursive /p Prompt at end\n");
printf(" /i Register shell /u Unregister shell\n");
printf(" /x:<command> Execute shell command when done\n");
printf("\n");
printf("Examples: c4group pack.c4g -a myfile.dat -v *.dat\n");
printf(" c4group pack.c4g -as myfile.dat myfile.bin\n");
printf(" c4group pack.c4g -et *.dat \\data\\mydatfiles\\\n");
printf(" c4group pack.c4g -et myfile.dat myfile.bak\n");
printf(" c4group pack.c4g -s \"*.bin|*.dat\"\n");
printf(" c4group pack.c4g -x\n");
printf(" c4group pack.c4g /q -k\n");
printf(" c4group update.c4u -g ver1.c4f ver2.c4f New_Version\n");
printf(" c4group ver1.c4f -z ver2.c4f\n");
printf(" c4group /i\n");
}
// Prompt at end
if (fPromptAtEnd)
{
printf("\nDone. Press any key to continue.\n");
_getch();
}
// Execute when done
if (strExecuteAtEnd[0])
{
printf("Executing: %s\n", strExecuteAtEnd);
STARTUPINFO startInfo;
ZeroMem(&startInfo, sizeof(startInfo));
startInfo.cb = sizeof(startInfo);
PROCESS_INFORMATION procInfo;
CreateProcess(strExecuteAtEnd, NULL, NULL, NULL, false, 0, NULL, NULL, &startInfo, &procInfo);
}
// Done
return iResult;
}

View File

@ -117,98 +117,6 @@ bool ProcessGroup(const char *FilenamePar)
// Handle commands
switch (argv[iArg][1])
{
// Add
case 'a':
if ((iArg + 1 >= argc) || (argv[iArg + 1][0] == '-'))
fprintf(stderr, "Missing argument for add command\n");
else
{
if ((argv[iArg][2] == 's') || (argv[iArg][2] && (argv[iArg][3] == 's')))
{
if ((iArg + 2 >= argc) || (argv[iArg + 2][0] == '-'))
{
fprintf(stderr, "Missing argument for add as command\n");
}
else
{
hGroup.Add(argv[iArg + 1], argv[iArg + 2]);
iArg += 2;
}
}
else
{
while (iArg + 1 < argc && argv[iArg + 1][0] != '-')
{
++iArg;
#ifdef _WIN32
// manually expand wildcards
hGroup.Add(argv[iArg]);
#else
hGroup.Add(argv[iArg], GetFilename(argv[iArg]));
#endif
}
}
}
break;
// Move
case 'm':
if ((iArg + 1 >= argc) || (argv[iArg + 1][0] == '-'))
{
fprintf(stderr, "Missing argument for move command\n");
}
else
{
while (iArg + 1 < argc && argv[iArg + 1][0] != '-')
{
++iArg;
#ifdef _WIN32
// manually expand wildcards
hGroup.Move(argv[iArg]);
#else
hGroup.Move(argv[iArg], argv[iArg]);
#endif
}
}
break;
// Extract
case 'e':
if ((iArg + 1 >= argc) || (argv[iArg + 1][0] == '-'))
{
fprintf(stderr, "Missing argument for extract command\n");
}
else
{
if ((argv[iArg][2] == 't') || (argv[iArg][2] && (argv[iArg][3] == 's')))
{
if ((iArg + 2 >= argc) || (argv[iArg + 2][0] == '-'))
{
fprintf(stderr, "Missing argument for extract as command\n");
}
else
{
hGroup.Extract(argv[iArg + 1], argv[iArg + 2]);
iArg += 2;
}
}
else
{
hGroup.Extract(argv[iArg + 1]);
iArg++;
}
}
break;
// Delete
case 'd':
if ((iArg + 1 >= argc) || (argv[iArg + 1][0] == '-'))
{
fprintf(stderr, "Missing argument for delete command\n");
}
else
{
hGroup.Delete(argv[iArg + 1], fRecursive);
iArg++;
}
break;
// Sort
case 's':
// First sort parameter overrides default Clonk sort list
@ -225,19 +133,6 @@ bool ProcessGroup(const char *FilenamePar)
iArg++;
}
break;
// Rename
case 'r':
if ((iArg + 2 >= argc) || (argv[iArg + 1][0] == '-')
|| (argv[iArg + 2][0] == '-'))
{
fprintf(stderr, "Missing argument(s) for rename command\n");
}
else
{
hGroup.Rename(argv[iArg + 1], argv[iArg + 2]);
iArg += 2;
}
break;
// View
case 'l':
hGroup.SetStdOutput(true);
@ -252,10 +147,6 @@ bool ProcessGroup(const char *FilenamePar)
}
hGroup.SetStdOutput(!fQuiet);
break;
// Make original
case 'o':
hGroup.MakeOriginal(true);
break;
// Pack
case 'p':
Log("Packing...");
@ -563,28 +454,22 @@ int main(int argc, char *argv[])
#endif
}
// Too few parameters: output help (if we didn't register stuff)
else if (!fRegisterShell && !fUnregisterShell)
{
else if (!fRegisterShell && !fUnregisterShell) {
printf("\n");
printf("Usage: c4group [options] group(s) command(s)\n\n");
printf("Commands: -a[s] Add [as] -m Move -e[t] Extract [to]\n");
printf(" -l List -d Delete -r Rename -s Sort\n");
printf(" -p Pack -u Unpack -x Explode\n");
printf(" -k Print maker\n");
printf(" -g [source] [target] [title] Make update\n");
printf("Commands: -l List\n");
printf(" -x Explode\n");
printf(" -u Unpack\n");
printf(" -p Pack\n");
printf(" -y Apply update\n");
printf(" -g [source] [target] [title] Make update\n");
printf(" -s Sort\n");
printf("\n");
printf("Options: -v Verbose -r Recursive\n");
printf(" -i Register shell -u Unregister shell\n");
printf(" -x:<command> Execute shell command when done\n");
printf("\n");
printf("Examples: c4group pack.c4g -a myfile.dat -l \"*.dat\"\n");
printf(" c4group pack.c4g -as myfile.dat myfile.bin\n");
printf(" c4group -v pack.c4g -et \"*.dat\" \\data\\mydatfiles\\\n");
printf(" c4group pack.c4g -et myfile.dat myfile.bak\n");
printf(" c4group pack.c4g -s \"*.bin|*.dat\"\n");
printf(" c4group pack.c4g -x\n");
printf(" c4group pack.c4g -k\n");
printf("Examples: c4group pack.c4g -x\n");
printf(" c4group update.c4u -g ver1.c4f ver2.c4f New_Version\n");
printf(" c4group -i\n");
}