CIVSVE.BAT -- a command line save file moving and versioning tool

Whelkman

Phantom Taxman
Joined
Mar 16, 2007
Messages
524
CIVSVE is a crude Windows NT 5.0 and higher command line batch program that permits convenient archival and shuffling of save files for those who find the default system limiting. To use, download the attached file or copy dump in next post.

Usage is available by issuing CIVSVE with no arguments or the standard /?:

Code:
Utility program for Sid Meier's Civilization (DOS) save files.

CIVSVE [drive:][path]CIVSRC [[drive:][path]CIVDST] [/COMPRESS] [/DELBACK]
  [/MOVE]

  [drive:][path]CIVSRC
              Specifies location for save file to process
  [[drive][path]CIVDST]
              Specifies location for copy save file

  /COMPRESS   Create compressed archive along with backup MAP and SVE files
              Must edit CIVSVE.BAT and set COMPRESSORPATH to use.
  /DELBACK    Delete backup MAP and SVE files. Use with /COMPRESS and/or /MOVE
  /MOVE       Delete CIVSRC after copying to CIVDST

  View CIVSVE.BAT in a pager or text editor for more info.

Examples

Code:
C:\>CIVSVE CIVIL0
The simplest usage creates a timestamped backup of the file given in the first argument. Copies will be in BASE-YYYYMMDD-HHMMSS.[MAP|SVE] format, e.g. CIVIL0-20070826-171406.MAP.
Code:
C:\>CIVSVE CIVIL0 CIVIL9
Create a timestamped backup AND copy to CIVIL9.
Code:
C:\>CIVSVE CIVIL0 /COMPRESS /DELBACK
Compress a timestamped backup with defined compressor then delete uncompressed backups.
Code:
C:\>CIVSVE CIVIL0 CIVIL9 /MOVE
Create a timestamped backup, copy CIVIL0 to CIVIL9, then delete CIVIL0
Code:
C:\>CIVSVE CIVIL0 /MOVE
Strange but valid usage: after creating the timestamped backup CIVIL0 will be moved to NULL (deleted).
Code:
C:\>CIVSVE CIVIL0 /DELBACK
Also technically valid but a little pointless: creates then deletes timestamped backup.
Code:
C:\>CIVSVE CIVIL0 /DELBACK /MOVE
Don't do this.

Gotchas:
  • CIVSVE currently isn't smart enough to strip extensions. Only bases are acceptable, e.g. CIVIL0 and not CIVIL0.MAP
  • CIVSVE relies on command line features introduced after DOS 5 and likely after NT4. While none of the included functionality is inherently exclusive to NT5, to function in DOS, the program would require replacement logic along with a versioning system that fits in eight characters.
  • While attempts were made to trap destructive actions such as bad filenames and illogical flag combinations, I cannot guarantee usage of this program will not lead to data loss. Bugs are likely. The following clause is included in the MIT License text but is reproduced here: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
@ECHO OFF
SETLOCAL

REM CIVSVE.BAT utility program for Sid Meier's Civilization (DOS) save files.
REM Revision 2007-08-26

REM TODO: Add suitable description here after posting at CivFanatics. See end of file for license.

REM *****Begin User configurable options*****
REM COMPRESSORPATH and COMPRESSOROPTIONS set variables to be used upon invocation of the /COMPRESS flag.
REM Set COMPRESSORPATH to your preferred commandline compressor. Spaces are okay but don't use quotes.
REM Usage assumes compressor follows standard "archive_name files_list" convention.
REM Set COMPRESSOROPTIONS with any flags needed by your compressor. Spaces are okay but don't use quotes.
REM Setting COMPRESSOROPTIONS to null or whitespace is okay.
REM Compressor output is surpressed so ensure output with /COMPRESS before using /DELBACK

SET COMPRESSORPATH=C:\Documents and Settings\Administrator\Desktop\share\applications\exe\7za.exe
SET COMPRESSOROPTIONS=a

REM Set timezone for Infozip, etc.
SET TZ=EST4EDT

REM *****End User configurable options*****
REM Begin processing...

IF (%1)==() GOTO USAGE
IF (%1)==(/?) GOTO USAGE

REM Initialize variables

SET COMPRESSORUSE=0
SET DELETECOPY=0
SET DELETESOURCE=0
SET N=1

REM Parse commandline options

:PARSESTART
IF (%1)==() GOTO PARSEEND
IF /I (%1)==(/COMPRESS) (
SET COMPRESSORUSE=1
SHIFT
GOTO PARSESTART
)
IF /I (%1)==(/MOVE) (
SET DELETESOURCE=1
SHIFT
GOTO PARSESTART
)
IF /I (%1)==(/DELBACK) (
SET DELETECOPY=1
SHIFT
GOTO PARSESTART
)
SET FILE%N%=%1
IF (%FILE3%) NEQ () (
ECHO Invalid argument "%FILE3%"! Aborting.
GOTO END
)
SET /A N=%N%+1
SHIFT
GOTO PARSESTART
:PARSEEND

IF NOT EXIST %FILE1%.SVE (
ECHO Can't find file "%FILE1%.SVE"! Aborting.
GOTO :END
)

IF NOT EXIST %FILE1%.MAP (
ECHO Can't find file "%FILE1%.MAP"! Aborting.
GOTO :END
)

IF NOT (%FILE2%)==() (
COPY /Y %FILE1%.MAP %FILE2%.MAP > NUL
COPY /Y %FILE1%.SVE %FILE2%.SVE > NUL
IF NOT EXIST %FILE2%.MAP (
ECHO Invalid argument "%FILE2%"! Aborting.
GOTO END
)
)

REM Set timestamp. Because DOS time does not support zero padding for HH < 10 we must check the
REM string and pad if necessary. Thanks to "Elliot" for routine:
REM http://blog.209software.com/2004/10/dos-batch-file-fun-creating.html#comment-7480354985522561447

SET UNPADDEDHOURWITHSPACE=%TIME:~0,2%
SET /A UNPADDEDHOUR=%UNPADDEDHOURWITHSPACE%
SET EXTRAZERO=0%UNPADDEDHOUR%
SET HOUR=%EXTRAZERO:~-2%
SET TIMESTAMP=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%-%HOUR%%TIME:~3,2%%time:~-5,2%

REM Check if user has specified combination of options which destroys data.

IF NOT EXIST %FILE2%.MAP (
IF %COMPRESSORUSE%==1 GOTO ENDDELCHECK
IF %DELETESOURCE%==1 (
IF %DELETECOPY%==0 GOTO ENDDELCHECK
) ELSE GOTO ENDDELCHECK
ECHO WARNING: You've specified no destination along with /MOVE and /DELBACK and
ECHO without /COMPRESS, which would irrecoverably destroy "%FILE1%" save data.
ECHO Aborting.
GOTO END
)
:ENDDELCHECK

COPY /Y %FILE1%.MAP %FILE1%-%TIMESTAMP%.MAP > NUL
COPY /Y %FILE1%.SVE %FILE1%-%TIMESTAMP%.SVE > NUL

IF (%COMPRESSORUSE%)==(1) "%COMPRESSORPATH%" %COMPRESSOROPTIONS% %FILE1%-%TIMESTAMP% %FILE1%-%TIMESTAMP%.* > NUL

IF (%DELETECOPY%)==(1) (
DEL %FILE1%-%TIMESTAMP%.MAP
DEL %FILE1%-%TIMESTAMP%.SVE
)

IF (%DELETESOURCE%)==(1) (
DEL %FILE1%.MAP
DEL %FILE1%.SVE
)

GOTO :END

:USAGE
ECHO Utility program for Sid Meier's Civilization (DOS) save files.
ECHO.
ECHO CIVSVE [drive:][path]CIVSRC [[drive:][path]CIVDST] [/COMPRESS] [/DELBACK]
ECHO [/MOVE]
ECHO.
ECHO [drive:][path]CIVSRC
ECHO Specifies location for save file to process
ECHO [[drive][path]CIVDST]
ECHO Specifies location for copy save file
ECHO.
ECHO /COMPRESS Create compressed archive along with backup MAP and SVE files
ECHO Must edit CIVSVE.BAT and set COMPRESSORPATH to use.
ECHO /DELBACK Delete backup MAP and SVE files. Use with /COMPRESS and/or /MOVE
ECHO /MOVE Delete CIVSRC after copying to CIVDST
ECHO.
ECHO View CIVSVE.BAT in a pager or text editor for more info.
ECHO.
:END

REM The MIT License

REM Copyright (c) 2007 Robert J. Kosinski

REM Permission is hereby granted, free of charge, to any person obtaining a copy
REM of this software and associated documentation files (the "Software"), to deal
REM in the Software without restriction, including without limitation the rights
REM to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
REM copies of the Software, and to permit persons to whom the Software is
REM furnished to do so, subject to the following conditions:

REM The above copyright notice and this permission notice shall be included in
REM all copies or substantial portions of the Software.

REM THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
REM IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
REM FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
REM AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
REM LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
REM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
REM THE SOFTWARE.
 
Back
Top Bottom