;============================================================
; Script Name: TrailMyx's Advanced File System Handling Subs
; Author: TrailMyx
; Version: 1.3
; Shard OSI / FS: Any
; Revision Date: 10/20/2007
; Purpose:
; Simplify the saving of variables to a file. Also to speed up the process
; by minimizing the number times calls to the shell are issued. A maximum of
; 2000 bytes are assigned to each shell call, with an unlimited amount of calls
; possible. It's easy to store 1000's of variables in a relatively short period
; of time.
;
; This set of functions will also handle any namespace (local, global, immediate)!
; Also, this file is ready to be 'called'.
;
; Limitations:
; You cannot store spaces to a file due to the way DOS handles the command line.
; So if a space is found, it will be converted to an underscore '_'
;
; Functions:
; TM_FileSystem_CreateFileHandle
; -- ex. gosub TM_FileSystem_CreateFileHandle handle1
; TM_FileSystem_SaveVariable
; -- ex. gosub TM_FileSystem_SaveVariable local std handle1 testval ; note not to include the '%' or '!' for variable
; TM_FileSystem_SaveFile
; -- ex. gosub TM_FileSystem_SaveFile handle1 c:\bigtest.txt
; TM_FileSystem_LoadFile
; -- ex. gosub TM_FileSystem_LoadFile c:\bigtest.txt
; TM_FileSystem_SaveArray
; -- ex. gosub TM_FileSystem_SaveArray local ns1 handle ns1_test 10 20
;
; Support functions:
; TM_ReadVariables
; AddUnderscore
; AddSpace
;
;============================================================
; Revision History:
; v1.0 - Initial release.
; v1.1 - 5/16/2007 - Added support for array saving TM_SaveArray.
; v1.2 - Much faster load times.
; v1.3 - Much faster save preparation, fixed a bug in load pointer, added call handler
;=================================================================
Introduction:I wanted to be able to save a very large number of variables quickly. I wrote these subs to be able to handle 1000s of variables, keeping the saving time down to a very reasonable amount. In fact you can save nearly 100 variables with a single DOS cmd.exe execution! I use a similar file format in my rail engine, but this is meant to be generic.
You may also store information about different namespaces within the same output text file.
New to version 1.1: - Array Support: Now you can handle arrays of any size using TM_FileSystem_SaveArray.
Theory:Basically, you are building a very long string of variables that will be saved. In order to write a bunch of variables to a file you do the following:
1) Grab a file handle using
TM_FileSystem_CreateFileHandle2) Add variables to this handle using
TM_FileSystem_SaveVariable3) Add as many variables as you want to this file handle, note these have not been saved to the file yet...
4) Once you have added all the variables you want to save to the file handle, you must use
TM_FileSystem_SaveFile to actually write the file string containing all your variables to disk. During the saving process, the very long string containing all your variables will be cut up into strings of less than 2000 bytes. These sub-strings will be saved to specified file.
Loading this file using
TM_FileSystem_LoadFile will re-assemble the sub strings contained in the save file into your large string containing all your saved variables. Then this string will be parced and the appropriate values will be written to the specified variables.
Here are some examples:
set #LPC 10000
for %i 0 1000
set %test . %i %i * 100
gosub TM_FileSystem_CreateFileHandle handle1 ; clear handle named 'handle1'
for %i 0 1000
{
gosub TM_FileSystem_SaveVariable local std handle1 test , %i ; store %test0, %test1, %test2, etc.
}
gosub TM_FileSystem_SaveFile handle1 c:\bigtest.txt ; save the file
stop
This test generates 1000 variables ranging from %test0 to %test1000 and assigns values from 0 100000. The corresponding file looks like this:
set !fileout0 localstdtest00localstdtest1100localstdtest2200localstdtest3300localstdtest4400localstdtest5500localstdtest6600localstdtest7700localstdtest8800localstdtest9900localstdtest101000localstdtest111100localstdtest121200localstdtest131300localstdtest141400localstdtest151500localstdtest161600localstdtest171700localstdtest181800localstdtest191900localstdtest202000localstdtest212100localstdtest222200localstdtest232300localstdtest242400localstdtest252500localstdtest262600localstdtest272700localstdtest282800localstdtest292900localstdtest303000localstdtest313100localstdtest323200localstdtest333300localstdtest343400localstdtest353500localstdtest363600localstdtest373700localstdtest383800localstdtest393900localstdtest404000localstdtest414100localstdtest424200localstdtest434300localstdtest444400localstdtest454500localstdtest464600localstdtest474700localstdtest484800localstdtest494900localstdtest505000localstdtest515100localstdtest525200localstdtest535300localstdtest545400localstdtest555500localstdtest565600localstdtest575700localstdtest585800localstdtest595900localstdtest606000localstdtest616100localstdtest626200localstdtest636300localstdtest646400localstdtest656500localstdtest666600localstdtest676700localstdtest686800localstdtest696900localstdtest707000localstdtest717100localstdtest727200localstdtest737300localstdtest747400localstdtest757500localstdtest767600localstdtest777700localstdtest787800localstdtest797900localstdtest808000localstdtest818100localstdtest828200localstdtest838300localstdtest848400localstdtest858500localstdtest868600localstdtest878700localstdtest888800localstdtest898900localstdtest909000localstdtest91910
set !fileout1 0localstdtest929200localstdtest939300localstdtest949400localstdtest959500localstdtest969600localstdtest979700localstdtest989800localstdtest999900localstdtest10010000localstdtest10110100localstdtest10210200localstdtest10310300localstdtest10410400localstdtest10510500localstdtest10610600localstdtest10710700localstdtest10810800localstdtest10910900localstdtest11011000localstdtest11111100localstdtest11211200localstdtest11311300localstdtest11411400localstdtest11511500localstdtest11611600localstdtest11711700localstdtest11811800localstdtest11911900localstdtest12012000localstdtest12112100localstdtest12212200localstdtest12312300localstdtest12412400localstdtest12512500localstdtest12612600localstdtest12712700localstdtest12812800localstdtest12912900localstdtest13013000localstdtest13113100localstdtest13213200localstdtest13313300localstdtest13413400localstdtest13513500localstdtest13613600localstdtest13713700localstdtest13813800localstdtest13913900localstdtest14014000localstdtest14114100localstdtest14214200localstdtest14314300localstdtest14414400localstdtest14514500localstdtest14614600localstdtest14714700localstdtest14814800localstdtest14914900localstdtest15015000localstdtest15115100localstdtest15215200localstdtest15315300localstdtest15415400localstdtest15515500localstdtest15615600localstdtest15715700localstdtest15815800localstdtest15915900localstdtest16016000localstdtest16116100localstdtest16216200localstdtest16316300localstdtest16416400localstdtest16516500localstdtest16616600localstdtest16716700localstdtest16816800localstdtest16916900localstdtest17017000localstdtest17117100localstdtest17217200localstdtest17317300localstdtest17417400localstdtest1751750
set !fileout2 << there's more here that I deleted (it whas 27Kbytes) >>
.
.
.
Finally, if you want to load this file, just do:
gosub TM_FileSystem_LoadFile c:\bigtest.txt
Here's an example that stores information to 2 different namespaces:
gosub TM_FileSystem_CreateFileHandle handle1
set %testval 12345
gosub TM_FileSystem_SaveVariable local std handle1 testval ; don't add the '%' or '!'
namespace push
namespace local NS1
set !ns1val 56789
gosub TM_FileSystem_SaveVariable local NS1 handle1 ns1val ; don't add the '%' or '!'
gosub TM_FileSystem_SaveFile handle1 c:\filesystem_test.txt
If you load the file, the data will automatically be written to the approperate namespaces
gosub TM_FileSystem_LoadFile c:\filesystem_test.txt
so you'll find:
%testval = 12345 in local:std
!ns1val = 56789 in local:NS1
Note in order to start a clean file, you need to call
TM_FileSystem_CreateFileHandle to make sure the TM_FileSystem namespace variable doesn't have old data.
Note:Remember that you can't store spaces using this filesystem. It automatically convertes spaces to '_'(underscores) so beware.
Scripts known to use this filesystem:- WHQuester beta2.00 - Save/Restore user preferences, artifact list, etc.
- TrailMyx's Complete Looting Assistant (CLAw) - Save/Restore user setup.
- TrailMyx's Recall Beetle Logging Machine
If you use this filesystem, please PM me so I can add your script to the above list! Thanks, TrailMyx