.com.unity Forums

.com.unity Forums (http://forum.shrapnelgames.com/index.php)
-   Dominions 3: The Awakening (http://forum.shrapnelgames.com/forumdisplay.php?f=138)
-   -   Automatic backup of turn files (http://forum.shrapnelgames.com/showthread.php?t=31522)

Lollipop November 1st, 2006 02:22 PM

Automatic backup of turn files
 
This is my first post and I hope I don't get a bad rep as 'the gal who propagates cheating tools', but 1) it was useful during my 'what? only 20 devils! Pretender, let's go!" phase, and 2) I want to contribute something (semi) useful, before I start bothering you with my 20000 questions.

Okay first the windows version for the mortals:

1) create a link of your dom3.exe (right drag to a location of your choice and select 'create link here')

2) right click on your link, select 'properties' and find the line containing 'dom3.exe'

3) add ' --preexec backup.bat'

4) open notepad

5) copy & paste the following lines:

<font class="small">Code:</font><hr /><pre>set Game=&lt;name&gt;
cd savedgames
del /S /Q "%Game%.backup"
mkdir "%Game%.backup"
copy "%Game%\" "%Game%.backup\"
</pre><hr />

save in your dom3 install directory as 'backup.bat'

You have to substitute "&lt;name&gt;" with the name of the game you're currently playing. It's clumsy but it's windows. So if your last game was called 'trash' and you start a new game called 'MoreTrash', you have to edit 'backup.bat' and set the appropriate name.

Now whenever something goes horribly wrong (power failure, your husband mentioning that the kitchen looks like a battle field or simply walking your mages while sneaking your meatshield), go to the 'savedgames' directory, delete the &lt;name&gt; directory and rename &lt;name&gt;.backup to &lt;name&gt;.

A much nicer version which finds the last played game, but requires python (though if you have Civ IV, you probably have python installed):


<font class="small">Code:</font><hr /><pre>#!/usr/bin/python
from os import *
from os.path import *
import shutil

def checkDate(name):
turnFile = join(name,"ftherlnd")
if access (turnFile,F_OK):
return getmtime(turnFile)
return 0

def findLastGame():
lastTime = 0
lastName = ""
chdir("savedgames")
for file in listdir("."):
if isdir(file):
time = checkDate(file)
if time &gt; lastTime:
lastTime = time
lastName = file
return lastName

def doCopy(name):
backup = name + ".backup"
shutil.rmtree(backup,True)
shutil.copytree(name,backup)

last = findLastGame()
if len(last) &gt; 0:
doCopy(last)
</pre><hr />

Use sparingly.

Hopefully someone find this useful..

kind regards
Pia Kraft

Gandalf Parker November 1st, 2006 02:33 PM

Re: Automatic backup of turn files
 
Very nice. And excellent explanation.

One note. If your icon has a Target line like
"C:\Program Files\dominions3\dom3.exe"
with the quotes (windows puts the quotes because of the space in that line) then put the --preexec backup.bat outside of the second quote.

It also answers a question I had about windows variables that I was going to look up so that I could convert some of my linux scripts to windows batch files.

thejeff November 1st, 2006 02:57 PM

Re: Automatic backup of turn files
 
Another thing I found useful is to pass the game name on the --preexec line.

--preexec "backup.bat GameName"

This way you can use the same script for every game you play and just change the line in properties.

If you also generate the score dump, you can parse that for the turn number and actually save each turn.

I had a fairly simple bash script version, but gave up on converting it to Windows, since the current version behaves badly when running the postexec, at least if it's full screen.

Gandalf Parker November 1st, 2006 04:45 PM

Re: Automatic backup of turn files
 
The passed name is a good thing. Thanks.
I can see it being useful since I tend to create a seperate icon for every server game Im in because it saves me changing the server and port when Im playing multiple games on multiple servers. With your hint I can have one bat file making backups of all of my MP games, and just have each icon telling it which game to save. Very handy since multiple games makes it hard to remember what I did last turn.

Lollipop November 2nd, 2006 10:12 AM

Re: Automatic backup of turn files
 
Quote:

thejeff said:
If you also generate the score dump, you can parse that for the turn number and actually save each turn.


Thanks, that was exactly what I was looking for.

I attached a python script. Instead of long winded explanations:

<font class="small">Code:</font><hr /><pre>pia@Lollipop:~/dominions3$ ./dom3backup.py --help
usage: dom3backup.py [options]

options:
-h, --help show this help message and exit
-n NAME, --name=NAME Process file &lt;name&gt;. Otherwise latest file
-f FREQ, --freq=FREQ create a Zipfile every &lt;n&gt; turns. Default: 0 (no
zipfile)
-m MAXFILES, --maxfiles=MAXFILES
keep max. &lt;n&gt; Zipfiles. Delete oldest. Default: 0
(keep all)
-d ARCHDIR, --archdir=ARCHDIR
create Zipfiles in archdir. archdir must exists.
Default: &lt;dom3&gt;/archivedgames
--nocopy don't copy files to backup-dir. Default: False
--clean remove all zipfiles and the backup-dir
</pre><hr />

Gandalf Parker November 2nd, 2006 02:16 PM

Re: Automatic backup of turn files
 
I posted a batch file for playing with the map making commands. It makes it easy to generate map after map with the same settings. It also lets you play with things like the color settings. I posted it into the MOD/MAP subforum since I think it is more useful to that crowd.

PDF November 3rd, 2006 07:27 PM

Re: Automatic backup of turn files
 
Many thanks Lolly (can I call you that ? http://forum.shrapnelgames.com/images/smilies/wink.gif ) !
I've installed Python and copied the script, it works quite well as advertised. Only small problem is that if Dom3 runs in fullscreen mode it's automatically minimized when executing the script... I suppose it's a Windowze thingie and can live in windowed mode.
Would it be easy to not only backup the last turn but also make a file history, I mean having subdirs with each turn's saves ? I know the game doesn't pass the turn numbers, so the utility should assume the player uses it by turn 1..
Just an idea, but it'll be cool http://forum.shrapnelgames.com/images/smilies/happy.gif

Lollipop November 4th, 2006 04:10 AM

Re: Automatic backup of turn files
 
Quote:

PDF said:
Many thanks Lolly (can I call you that ? ) !

By way of an exception, cause you was brave enough to try my scripthttp://forum.shrapnelgames.com/image...es/biggrin.gif

Quote:

Only small problem is that if Dom3 runs in fullscreen mode it's automatically minimized when executing the script... I suppose it's a Windowze thingie

Yes, it is. I doubt there's a way around


Quote:

Would it be easy to not only backup the last turn but also make a file history, I mean having subdirs with each turn's saves ? I know the game doesn't pass the turn numbers, so the utility should assume the player uses it by turn 1..
Just an idea, but it'll be cool http://forum.shrapnelgames.com/images/smilies/happy.gif

The script already does it, kind of. I was in a hurry when posting cause my boss was approaching and I wasn't supposed to work on a dom3 script:).

1) create a 'archivedgames' directory in your dom3 directory.

2) modify the dom3 link to:
dom3.exe --scoredump --preexec 'python dom3backup.py -f 1'

The script parses scores.html to get the turn number (assumes turn 1, if not found) and creates a zipfile (name-Turn&lt;turnnumber&gt;.zip) every '-f &lt;n&gt;' turns (in archivedgames, optionally use the -d arg), with '-f 1' every turn.

You can limit the number of zip-files kept with '-m &lt;n&gt;', default is to keep all.

I hope this isn't too confusing.

Caveat: I haven't tested it under xp. The pyhton-doc says, that you need zlib (prob. not present) only, when deflating, so I used a simple store mechanism. But who knows..

Thanks for testing

Pia

Edit: Gnu zlib for XP is here. Change the line:

zipFile = ZipFile(zipName,'w')

to:
zipFile = ZipFile(zipName,'w',ZIP_DEFLATED)

Compression ratio is 1:10, not bad.

PDF November 4th, 2006 08:26 AM

Re: Automatic backup of turn files
 
Wunderbar !! That's just what we needed to have a real "save" feature in Dom3 http://forum.shrapnelgames.com/images/smilies/happy.gif
Can I kiss you Lolly ? http://forum.shrapnelgames.com/images/smilies/laugh.gif

In fact in my previous post I had just tested the first small script that you gave in your first post and didn't notice there was a second post with attachment !! I'm distracted...

About XP I had everything working but had to "spell" the shortcut command like this :
&lt;dom3path&gt;\dom3.exe --scoredump --preexec "&lt;Dom3 path&gt;\dom3backup.py -f 1"
With &lt;dom3path&gt; my Dom3 directory where I've also copied the .py file. Double apostrophs are required ("), simple ones (')don't work.

This tool give me ideas but I don't charm Pythons like you do so well http://forum.shrapnelgames.com/images/smilies/wink.gif , could you please continue this fine work ? http://forum.shrapnelgames.com/images/smilies/wink.gif
- I don't like much having the .backup reps directly under Dom3 rep, I'd prefer to have them underneath each game's rep, ie Dominions3/MyGame/MyGame.backup
I suppose it's rather easy to change ? Just tell me what lines/command to edit, I'm able to do that.
- For pbems, now that we got automatic numbered zipped turn files we just lack an automatic email sending to a list of addresses (the players) ! http://forum.shrapnelgames.com/images/smilies/cool.gif Do you think you could handle that ? (I'm sure you can http://forum.shrapnelgames.com/image...es/biggrin.gif ! )
For Dom2 I had a buddy who make scripts to use a small free command-line email tool called "postie", perhaps we could use it also ? http://forum.shrapnelgames.com/images/smilies/smile.gif

Lollipop November 4th, 2006 09:53 AM

Re: Automatic backup of turn files
 
Quote:

PDF said:
Wunderbar !! That's just what we needed to have a real "save" feature in Dom3 http://forum.shrapnelgames.com/images/smilies/happy.gif
Can I kiss you Lolly ? http://forum.shrapnelgames.com/images/smilies/laugh.gif

I guess I have to ask my husband first. http://forum.shrapnelgames.com/images/smilies/happy.gif

Quote:

- I don't like much having the .backup reps directly under Dom3 rep, I'd prefer to have them underneath each game's rep, ie Dominions3/MyGame/MyGame.backup
I suppose it's rather easy to change ? Just tell me what lines/command to edit, I'm able to do that.

Very well, Master, your wish is my commandhttp://forum.shrapnelgames.com/image...es/biggrin.gif. I'm working on it.

Quote:

- For pbems, now that we got automatic numbered zipped turn files we just lack an automatic email sending to a list of addresses (the players) ! http://forum.shrapnelgames.com/images/smilies/cool.gif Do you think you could handle that ? (I'm sure you can http://forum.shrapnelgames.com/image...es/biggrin.gif ! )

I lack any dom pbem experience, but I think, --pre/postexec only works when hosting. So this would be a stand-alone program. Like reading the addresses from &lt;gamename&gt;.pbem and sending the .2h file? Something like that?

However, I only used python cause it was available at work (which says something about my working morale). Python isn't my favorite language &amp; if that thing gets bigger, I'll use ruby. No worries, it's a 1.x mb download iirc and called 'ruby-one-click-installer.exe'.

And could you do me a favor and test, if the zip file creation works under XP. TIA.

Pia


All times are GMT -4. The time now is 05:00 AM.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.