DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 24th June 2010
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Eindhoven, Netherlands
Posts: 2,074
Thanked 198 Times in 156 Posts
Default Manage Unreal Tournament cache files

This is a little Python script to manage cache file for Unreal Tournament. Been using it for years, figured I might as well put it here.
I only used/tested this with the original UT on Windows and FreeBSD, should work for Linux and possible MacOS X too.

On FreeBSD you can install UT as a port: games/linux-ut. You'll need an original UT CD. The unreal anthology release is on sale for a few euro's (... And will work with the port in spite of the InstallShield crap installer they slapped on).
AFAIK it doesn't work with OpenBSD/Linux emulation.

Note this script will just rename the files to the correct name in the Cache/ directory, it doesn't put them in the correct UT Dirctory (System/, Textures/, etc.).
This is a feature and not a bug because when you're using mods you often don't want to use the standard UT directories and there is no way of figuring out which files belongs to which mod (Or even if it belongs to any mod).

A few simple commands can move the files:

Code:
  $ utdir=/usr/local/share/linux-ut/
  $ mv *.u ${utdir}/System/
  $ mv *.utx ${utdir}/Textures
etc...

The actual code
Code:
  #!/usr/bin/env python
  #
  # Martin Tournoij <martin@arp242.net>
  # http://carpetsmoker.net/weblog/Manage_Unreal_Tournament_cache_files.php
  # Free to use for whatever purpose. There are no restrictions.
  # Version 20100624
  #
  # This is a very simple script to manage unreal tournament cache files.
  # Works on Windows, FreeBSD, Linux.
  # 
  
  import os
  import re
  import shutil
  import sys
  
  if sys.platform[:3] == 'win':
  	cachefile = '%s\\UnrealTournament\\Cache\\cache.ini' % os.getenv('SYSTEMDRIVE')
  else:
  	cachefile = os.path.expanduser('~/.loki/ut/Cache/cache.ini')
  
  if len(sys.argv) > 1:
  	cachefile = sys.argv[1]
  
  def ReadFile(file):
  	newfile = [ ]
  	move = [ ]
  	f = open(file)
  	for line in f:
  		if line[0] == ';' or line[0] == '[':
  			continue
  
  		line = line.strip()
  		if line == '':
  			continue
  
  		l = line.split('=')
  		# There are multiple versions of these files active on servers, so skip
  		# them and keep them in cache!
  		if l[1] == 'INF_AimedPistols.u' or l[1] == 'UTCompass.u':
  			newfile.append(l)
  			continue
  		move.append(l)
  	
  	f.close()
  	return move, newfile
  
  if not os.path.exists(cachefile):
  	print 'Error: cache.ini file "%s" does not exists.' % cachefile
  	print 'Please specify the cache.ini file as the first argument'
  	print 'Example: %s C:/games/UnrealTournament/Cache/cache.ini' % sys.argv[0]
  	sys.exit(1)
  
  shutil.copy(cachefile, cachefile + '.bak')
  move, newfile = ReadFile(cachefile)
  dirname = os.path.dirname(cachefile)
  
  for file in move:
  	if os.path.exists('%s/%s.uxx' % (dirname, file[0])):
  		os.rename('%s/%s.uxx' % (dirname, file[0]), '%s/%s' % (dirname, file[1]))
  		print file
  	else:
  		print "Warning, cache file `%s/%s.uxx' doesn't exist." % (dirname, file[0])
  
  f = open(cachefile, 'w')
  f.write('[Cache]\n')
  for n in newfile:
  	f.write(n[0] + '=' + n[1] + '\n')
  f.close()
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote
Reply

Tags
freebsd, games, python, unreal tournament

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best way to manage multiple freebsd servers? WaBBiT FreeBSD General 1 4th April 2009 10:37 PM
improve proxy cache and replace gif MIME milo974 OpenBSD General 1 10th July 2008 12:14 PM
Memory cache graudeejs FreeBSD General 3 9th July 2008 03:27 AM
Manage changes in /etc johny FreeBSD Security 4 23rd May 2008 09:00 AM
in how many min/sec arp cache gets cleared in freebsd rex FreeBSD General 1 9th May 2008 08:01 AM


All times are GMT. The time now is 04:10 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick