MadAd1
asked on
Delete lines from a text file
I play a game called BF2. For reasons known only to the authors, on each load it attempts to ping every server in a history list that it saved in a text file. This can add serious delays in starting the game, not only for servers that have moved IP but also current servers that can take up to 5 seconds apiece to relay information.
One problem is that other stuff exists in the text file so simply clearing the file is not an option. I decided to look into how to make a simple batch file that would delete the necessary lines before the game runs- however it appears its not a trivial task and (as you guys probably know) deletions can only be done by a few methods, one reading into memory and only writing back the info that needs to be kept.
Now while I can tinker with a few very basic scripting tasks, this one is a little beyond my current abilities (im a hardware guy) so after googling somewhat, and scratching my head over 3rd party programs such as sed and parsomatic, I decided to ask you guys if you could take a look and see if theres a simple way to do this.
Requirements of the script: on double click
1) If exists, delete a variable amount of lines with the string addServerHistory from general.con
2) Run the game with its shortcut switches intact
See below for a sample of a general.con file. In this example there are 3 addServerHistory lines to delete, however
there may be none, ten even twenty lines to delete and the position of the first addServerHistory may or may not be at the same location.
It would be unusual for a general.con to exceed 200 lines, this example has 151 so we are not expecting large processing delays. Ideally it would use wsh or someother script method that does not rely on third party programming external to windows xp as others in the game community may wish to use this script too.
The path to general.con may vary from user to user, and there may be multiple copies of general.con on any one machine. My current path is:
C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\General.co n
However there is also a general.con in 0004, 0002 and 0001 which need not be altered
Shortcut information:
An untypical bf2 shortcut can carry all sorts of information, from user account login to screen resolutions, I have exampled one below however not all users may have the same information in their shortcut.
_______________________beg in general.con example___________________ _________
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_KITT AB_pickArm yAndKit"
GeneralSettings.setPlayedV OHelp "HUD_HELP_GAMEPLAY_exitToC apture"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ SUBMACHINE GUN_CONTRO LS_toggleF ireModes"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_CONTROLS _exitVehic le"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ zoomAltFir e"
GeneralSettings.setPlayedV OHelp "HUD_HELP_GAMEPLAY_climbLa dder"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ sprint"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ SNIPERRIFL E_CONTROLS _switchToS copeView"
GeneralSettings.setPlayedV OHelp "USRIF_M24"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_ca llMedicWhe nManDown"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_sp awnScreen"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_F35_PILO T_CONTROLS _engageHov erEngines"
GeneralSettings.setPlayedV OHelp "air_f35b"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_HELO_PIL OT_CONTROL S_deployFl ares"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_HELO_PAS SENGER_CON TROLS_swit chToGuided Missiles"
GeneralSettings.setPlayedV OHelp "switchToGuidedMissiles"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ parachute"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_KITT AB_pickSpa wnPoint"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ moveMouseT oLook"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ fireLeftMo use"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_TANK_DRI VER_CONTRO LS_smoke"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_ch angeWeapon "
GeneralSettings.setPlayedV OHelp "HUD_HELP_GAMEPLAY_capture Flag"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_STATIONAR Y_CONTROLS _enterStat ionaryWeap on"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WORLD_PLAYER_RAD AR_friendl y"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_CO MMOROSE_sp ecificSpot ted"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WORLD_PLAYER_ART ILLERY_fri endly"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WORLD_PLAYER_UAV _TRAILER_f riendly"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_SQUA DTAB_joinS quad"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SQUAD_squadJoine d"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_spaw nOnSL"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_TANK_TUR RET_CONTRO LS_duckInT urret"
GeneralSettings.setPlayedV OHelp "DuckInTurret"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEPAON_HANDHELD_ GENERAL_re loadWeapon "
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_JET_LOWH EALTH_useF riendlyRep airStation "
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_AA_DRIVE R_CONTROLS _fireSecon daryWeapon "
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ WRENCH_fix Stuff"
GeneralSettings.setPlayedV OHelp "HUD_HELP_KIT_ENGINEER_NAM ETAG_indic atorBar"
GeneralSettings.setPlayedV OHelp "HUD_HELP_KIT_ENGINEER_inV ehicle"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_JET_LOWA MMO_flyOve rFriendlyA irField"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_JET_PILO T_CONTROLS _toggleWea ponsShortc ut"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_APC_DRIV ER_CONTROL S_fireSeco ndaryWeapo n"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_STATIONAR Y_AT_CONTR OLS_guideM issile"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ ASSAULTRIF LE_CONTROL S_switchTo Grenades"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ ASSAULTRIF LE_CONTROL S_switchTo Rifle"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_HELO_PAS SENGER_CON TROLS_TVGU IDED_click ToGuide"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_CO MMOROSE_sl commoRoseA vailable"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SQUAD_LEADER_VOI P_commande rChannel"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ HANDGRENAD E_CONTROLS _rollGrena de"
GeneralSettings.setPlayedV OHelp "ushgr_m67"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ ATMINE_veh icles"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SQUAD_LEADER_mai nMapRightM ouseMenu"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SQUAD_squadCreat ed"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_APC_PASS ENGER_CONT ROLS_fireP assengerWe apon"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_STATIONAR Y_AA_CONTR OLS_lockOn Tone"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_KITT AB_trySqua ds"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ radioMessa ges"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_la rgeMap"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ lieDown"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_sc oreBoard"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ crouch"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_HELO_LOW HEALTH_use FriendlyRe pairStatio n"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WORLD_PLAYER_RAD AR_enemy"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WORLD_PLAYER_ART ILLERY_ene my"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ moveForwar dsBackward s"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ jump"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_GENERAL_ CONTROLS_e nterVehicl e"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WORLD_PLAYER_UAV _TRAILER_e nemy"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ strafeLeft Right"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_SQUA DTAB_creat eSquad"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_comman derApply"
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_CONTROLS_zo omMap"
GeneralSettings.setPlayedV OHelp "RURIF_AK101"
GeneralSettings.setPlayedV OHelp "HUD_HELP_KIT_MEDIC_inVehi cle"
GeneralSettings.setPlayedV OHelp "HUD_HELP_KIT_MEDIC_NAMETA G_indicato rBar"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ SHOCKPADDL ES_CONTROL S_reviveTe amMates"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ HEALBAG_GE NERAL_hold HealBagToH ealLocally "
GeneralSettings.setPlayedV OHelp "medikit"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ LMG_GENERA L_watchTem pGauge"
GeneralSettings.setPlayedV OHelp "HUD_HELP_KIT_SUPPORT_NAME TAG_indica torBar"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_SQUA DTAB_apply Commander"
GeneralSettings.setPlayedV OHelp "HUD_HELP_KIT_SUPPORT_inVe hicle"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ AMMOBAG_CO NTROLS_thr owAmmoBagD own"
GeneralSettings.setPlayedV OHelp "ammokit"
GeneralSettings.setPlayedV OHelp "HUD_HELP_VEHICLE_JET_GUNN ER_CONTROL S_switchTo LaserMissi les"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_MINIMA P_descript ion"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_MAP_QU ICKMENU"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_SATELL ITESCAN_de scription"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_UAV_de scription"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_ARTILL ERY_descri ption"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_SUPPLI ES_descrip tion"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_MAP_FI LTERS"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_placeA rtillery"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_artill eryFired"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_UAVpla ced"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_placeU AV"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_placeS upplies"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ C4_CONTROL S_switchTo Detonator"
GeneralSettings.setPlayedV OHelp "c4_explosives"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_SQUADL IST_clickS quadList"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_SQUADL IST_commoM enu"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_MAP_SA TELLITEVIE W_moveKeys "
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_uavDam aged"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_MAP_RE QUESTS_rec eived"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_radarD amaged"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_artill eryDamaged "
GeneralSettings.setPlayedV OHelp "HUD_HELP_MENU_COMMOROSE_s lCommoRose FirstUse"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_SQUADL IST_orderI con"
GeneralSettings.setPlayedV OHelp "HUD_HELP_COMMANDER_VOIP_a llSquadLea dersChanne l"
GeneralSettings.setPlayedV OHelp "HUD_HELP_SPAWNSCREEN_KITT AB_useUnlo ck"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ CLAYMORE_G ENERAL_min eHasDirect ionalBlast "
GeneralSettings.setPlayedV OHelp "usmin_claymore"
GeneralSettings.setPlayedV OHelp "gbrif_l96a1"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ ZLINE_CONT ROLS_useZi pLine"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ GasMask"
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ HANDGRENAD E_CONTROLS _flashbang "
GeneralSettings.setPlayedV OHelp "HUD_HELP_WEAPON_HANDHELD_ GHOOK_CONT ROLS_useGr applingHoo kUp"
GeneralSettings.setPlayedV OHelp "HUD_HELP_PLAYER_CONTROLS_ NightVisio n"
GeneralSettings.setPlayedV OHelp "ats_tow"
GeneralSettings.setSortOrd er 0
GeneralSettings.setSortKey ""
GeneralSettings.setNumRoun dsPlayed 0
GeneralSettings.setServerF ilter ""
GeneralSettings.addServerH istory "193.160.156.170" 29900 "TV2 - 5 JETS" 87
GeneralSettings.addServerH istory "193.160.156.173" 29901 "TV2 - 26 DRAGON 2" 96
GeneralSettings.addServerH istory "193.160.156.176" 29901 "Battlefield2.no Server #8 Dragon+Kubra" 3
GeneralSettings.setHUDTran sparency 60.3361
GeneralSettings.setCrossha irColor 255 0 0 255
GeneralSettings.setBuddyta gColor 0 0 0
GeneralSettings.setSquadta gColor 0 255 0
GeneralSettings.setMinimap Rotate 1
GeneralSettings.setMinimap Transparen cy 93.0419
GeneralSettings.setViewInt roMovie 1
GeneralSettings.setOutOfVo ting 0
GeneralSettings.setBFTVSav eDirectory ""
GeneralSettings.setConfirm Quit 1
GeneralSettings.setMapIcon AlphaTrans parency 190.76
GeneralSettings.setUseAdva ncedServer Browser 0
GeneralSettings.setUseBots 1
GeneralSettings.setMaxBots 16
GeneralSettings.setMaxBots IncludeHum ans 1
GeneralSettings.setBotSkil l 1
GeneralSettings.setLastAwa rdsCheckDa te 1161730798
GeneralSettings.setAllowPu nkBuster 1
GeneralSettings.setItemSel ectionReve rseItems 0
GeneralSettings.setToggleF ilters 63490
GeneralSettings.setAutoRel oad 1
GeneralSettings.setAutoRea dy 1
GeneralSettings.setConnect ionType 4
GeneralSettings.setLCDDisp layModes 0
__________________________ _end general.con example___________________ __________ ________
_________________________b egin shortcut switch example___________________ __________ ______
"F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes
__________________________ end shortcut switch example___________________ __________ _______
Thats it I think...sorry its a bit long but I wanted to outline all the parameters as clearly as possible, if something cant be done, or is hard to do, please say so. Ideally it would be as user friendly as possible so it can be posted on bulletin boards for others to use too, the main 2 problems are outlined above as variable locations of general.con and variable types of switches in the shortcut.
Thanks a lot
Ad
One problem is that other stuff exists in the text file so simply clearing the file is not an option. I decided to look into how to make a simple batch file that would delete the necessary lines before the game runs- however it appears its not a trivial task and (as you guys probably know) deletions can only be done by a few methods, one reading into memory and only writing back the info that needs to be kept.
Now while I can tinker with a few very basic scripting tasks, this one is a little beyond my current abilities (im a hardware guy) so after googling somewhat, and scratching my head over 3rd party programs such as sed and parsomatic, I decided to ask you guys if you could take a look and see if theres a simple way to do this.
Requirements of the script: on double click
1) If exists, delete a variable amount of lines with the string addServerHistory from general.con
2) Run the game with its shortcut switches intact
See below for a sample of a general.con file. In this example there are 3 addServerHistory lines to delete, however
there may be none, ten even twenty lines to delete and the position of the first addServerHistory may or may not be at the same location.
It would be unusual for a general.con to exceed 200 lines, this example has 151 so we are not expecting large processing delays. Ideally it would use wsh or someother script method that does not rely on third party programming external to windows xp as others in the game community may wish to use this script too.
The path to general.con may vary from user to user, and there may be multiple copies of general.con on any one machine. My current path is:
C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\General.co
However there is also a general.con in 0004, 0002 and 0001 which need not be altered
Shortcut information:
An untypical bf2 shortcut can carry all sorts of information, from user account login to screen resolutions, I have exampled one below however not all users may have the same information in their shortcut.
_______________________beg
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setPlayedV
GeneralSettings.setSortOrd
GeneralSettings.setSortKey
GeneralSettings.setNumRoun
GeneralSettings.setServerF
GeneralSettings.addServerH
GeneralSettings.addServerH
GeneralSettings.addServerH
GeneralSettings.setHUDTran
GeneralSettings.setCrossha
GeneralSettings.setBuddyta
GeneralSettings.setSquadta
GeneralSettings.setMinimap
GeneralSettings.setMinimap
GeneralSettings.setViewInt
GeneralSettings.setOutOfVo
GeneralSettings.setBFTVSav
GeneralSettings.setConfirm
GeneralSettings.setMapIcon
GeneralSettings.setUseAdva
GeneralSettings.setUseBots
GeneralSettings.setMaxBots
GeneralSettings.setMaxBots
GeneralSettings.setBotSkil
GeneralSettings.setLastAwa
GeneralSettings.setAllowPu
GeneralSettings.setItemSel
GeneralSettings.setToggleF
GeneralSettings.setAutoRel
GeneralSettings.setAutoRea
GeneralSettings.setConnect
GeneralSettings.setLCDDisp
__________________________
_________________________b
"F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes
__________________________
Thats it I think...sorry its a bit long but I wanted to outline all the parameters as clearly as possible, if something cant be done, or is hard to do, please say so. Ideally it would be as user friendly as possible so it can be posted on bulletin boards for others to use too, the main 2 problems are outlined above as variable locations of general.con and variable types of switches in the shortcut.
Thanks a lot
Ad
grep --invert-match addServerHistory input.txt > output.txt
this should simply output all lines that DON'T contain the word "addServerHistory" (case-sensitive). you can add another option for case insensitivity. Grep is available on windows via cygwin.
alternatively in windows xp you could do
find /v "addServerHistory" input.txt > output.txt
here i've assumed that your input file is input.txt and filtered result is placed in output.txt since you'd appreciate not overwriting your original files :0)
HTH
this should simply output all lines that DON'T contain the word "addServerHistory" (case-sensitive). you can add another option for case insensitivity. Grep is available on windows via cygwin.
alternatively in windows xp you could do
find /v "addServerHistory" input.txt > output.txt
here i've assumed that your input file is input.txt and filtered result is placed in output.txt since you'd appreciate not overwriting your original files :0)
HTH
Here is a VBScript (.vbs) to remove those lines:
Option Explicit
Dim fileName
fileName = "C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\General.co n"
Dim fso, f
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.Fi leSystemOb ject")
If fso.FileExists(fileName) Then
' Read in the whole file
Set f = fso.OpenTextFile(fileName, ForReading, False)
Dim lines ' Seperate the file out into individual lines
lines = Split(f.ReadAll, vbCrLf)
f.Close
' Set lines we don't want to blank ones
Dim i, beginning
For i = LBound(lines) To UBound(lines)
If Left(lines(i), 32) = "GeneralSettings.addServer History" Then
lines(i) = ""
End If
Next
' Put the file back together as one string
lines = Join(lines, vbCrLf)
' Take out the multiple blank lines left behind
If Left(lines, 2) = vbCrLf Then
lines = Mid(lines, 3)
End If
While Instr(lines, vbCrlf & vbCrLf) > 0
lines = Replace(lines, vbCrLf & vbCrLf, vbCrLf)
Wend
' Overwrite the existing File with the changes
Set f = fso.OpenTextFile(fileName, ForWriting, True)
f.Write(lines)
f.Close
End If
Option Explicit
Dim fileName
fileName = "C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\General.co
Dim fso, f
Const ForReading = 1, ForWriting = 2
Set fso = CreateObject("Scripting.Fi
If fso.FileExists(fileName) Then
' Read in the whole file
Set f = fso.OpenTextFile(fileName,
Dim lines ' Seperate the file out into individual lines
lines = Split(f.ReadAll, vbCrLf)
f.Close
' Set lines we don't want to blank ones
Dim i, beginning
For i = LBound(lines) To UBound(lines)
If Left(lines(i), 32) = "GeneralSettings.addServer
lines(i) = ""
End If
Next
' Put the file back together as one string
lines = Join(lines, vbCrLf)
' Take out the multiple blank lines left behind
If Left(lines, 2) = vbCrLf Then
lines = Mid(lines, 3)
End If
While Instr(lines, vbCrlf & vbCrLf) > 0
lines = Replace(lines, vbCrLf & vbCrLf, vbCrLf)
Wend
' Overwrite the existing File with the changes
Set f = fso.OpenTextFile(fileName,
f.Write(lines)
f.Close
End If
Variable explaination:
FIXPATH is the directory which holds your general.con
FIXFILE is the name of the file you want to clean, in this case: general.con
TEMPFILE is a just a tempfile it gets removed
EXECCMD is the command you want to execute after the script is complete.
Create a batch file with the following code:
------------------------ BEGIN CUTTING BELOW THIS LINE --------------------------
@ECHO OFF
SET FIXPATH="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="general.con"
SET TEMPFILE="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\general.tm p"
SET EXECCMD=""F:\Games\Battlef ield 2\BF2.exe" +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes"
FOR /F "usebackq eol=; tokens=1,2* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad dServerHis tory" ECHO %%i %%j >> %TEMPFILE%
DEL %FIXPATH%%FIXFILE%
RENAME %TEMPFILE% %FIXFILE%
%EXECCMD%
------------------------ STOP CUTTING HERE --------------------------
FIXPATH is the directory which holds your general.con
FIXFILE is the name of the file you want to clean, in this case: general.con
TEMPFILE is a just a tempfile it gets removed
EXECCMD is the command you want to execute after the script is complete.
Create a batch file with the following code:
------------------------ BEGIN CUTTING BELOW THIS LINE --------------------------
@ECHO OFF
SET FIXPATH="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="general.con"
SET TEMPFILE="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\general.tm
SET EXECCMD=""F:\Games\Battlef
FOR /F "usebackq eol=; tokens=1,2* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad
DEL %FIXPATH%%FIXFILE%
RENAME %TEMPFILE% %FIXFILE%
%EXECCMD%
------------------------ STOP CUTTING HERE --------------------------
ASKER
chhokra_expert: Thanks for the reply, however grep and cygwin seem to be additional installables, my console does not recognise grep and I cant seem to find a cygwin dll on my machine (fully updated sp2 instal) so im at a loss knowing how to run it. While the find /v suggestion seemed to run without errors from a dos console, it didnt do anything. Yes overwriting the file was required as the game will not run without it.
Idle_Mind: Thanks for the reply, your script does indeed remove the required lines but does not include running the game once terminated. Ideally id like the script to be a one hit replacement for a shortcut. I tried setting a wshshell.run but as expected it spat it back at me with an error ( ')' expected) at the point after the first shortcut. Oh how I wish I understood wsh scripting properly :(
mattcarver: Thanks for the reply, I can almost understand that and with the setpath commands like that it makes it very user friendly for passing on to non-coders via bulletin boards. It removes the lines as required but the major problem is that it does not run the game either. I have doubly made sure that the correct path is entered for EXECCMD, with both sets of "" "" but no run.
I had a tinker with it and if I remove all the switches and the outer " ", it does attempt to run, however the menu switch is essential for the game starting correctly so it only gets to the loading screen then errors exactly the same way as if switches are stripped from the normal windows shortcut. In its most simple format, it refuses to run even with ""F:\Games\Battlefield 2\BF2.exe"". It runs to the same error as described with ""F:\Games\Battle~1\BF2.ex e"" but again refuses as soon as switches are added to the 8.3 format. So it seems windows is baulking at two " " sets for some reason?
So all in all, good suggestions so far but theres still that last hurdle of getting the game to actually run. I cannot describe how frustrating it is not being able to sort this out myself.
Idle_Mind: Thanks for the reply, your script does indeed remove the required lines but does not include running the game once terminated. Ideally id like the script to be a one hit replacement for a shortcut. I tried setting a wshshell.run but as expected it spat it back at me with an error ( ')' expected) at the point after the first shortcut. Oh how I wish I understood wsh scripting properly :(
mattcarver: Thanks for the reply, I can almost understand that and with the setpath commands like that it makes it very user friendly for passing on to non-coders via bulletin boards. It removes the lines as required but the major problem is that it does not run the game either. I have doubly made sure that the correct path is entered for EXECCMD, with both sets of "" "" but no run.
I had a tinker with it and if I remove all the switches and the outer " ", it does attempt to run, however the menu switch is essential for the game starting correctly so it only gets to the loading screen then errors exactly the same way as if switches are stripped from the normal windows shortcut. In its most simple format, it refuses to run even with ""F:\Games\Battlefield 2\BF2.exe"". It runs to the same error as described with ""F:\Games\Battle~1\BF2.ex
So all in all, good suggestions so far but theres still that last hurdle of getting the game to actually run. I cannot describe how frustrating it is not being able to sort this out myself.
Let's get rid of EXECCMD and just put your program as the last line in the batch file. Check to see if this works.
------------------------ BEGIN CUTTING BELOW THIS LINE --------------------------
@ECHO OFF
SET FIXPATH="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="general.con"
SET TEMPFILE="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\general.tm p"
FOR /F "usebackq eol=; tokens=1,2* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad dServerHis tory" ECHO %%i %%j >> %TEMPFILE%
DEL %FIXPATH%%FIXFILE%
RENAME %TEMPFILE% %FIXFILE%
"F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes
------------------------ STOP CUTTING HERE --------------------------
------------------------ BEGIN CUTTING BELOW THIS LINE --------------------------
@ECHO OFF
SET FIXPATH="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="general.con"
SET TEMPFILE="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\general.tm
FOR /F "usebackq eol=; tokens=1,2* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad
DEL %FIXPATH%%FIXFILE%
RENAME %TEMPFILE% %FIXFILE%
"F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes
------------------------ STOP CUTTING HERE --------------------------
Try adding this to the bottom of my script:
cmd = Chr(34) & "F:\Games\Battlefield 2\BF2.exe" & Chr(34) & " +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes"
Set objShell = WScript.CreateObject("WScr ipt.Shell" )
Set objExecObject = objShell.Exec(cmd)
cmd = Chr(34) & "F:\Games\Battlefield 2\BF2.exe" & Chr(34) & " +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes"
Set objShell = WScript.CreateObject("WScr
Set objExecObject = objShell.Exec(cmd)
ASKER
Ok, after much fiddling and much googling ive learned a lot but seem to know nothing still.
mattcarver: Thanks for the reply but nothing still, no run. As soon as I remove the switches it attempts to run, the bf2 loading screen appears but of course errors. On top of that Ive found a bug- when parsing or writing, it misses off secondary characters from 3 of the lines.
GeneralSettings.setCrossha irColor 255 0 0 255
GeneralSettings.setBuddyta gColor 0 0 0
GeneralSettings.setSquadta gColor 0 255 0
becomes
GeneralSettings.setCrossha irColor 255
GeneralSettings.setBuddyta gColor 0
GeneralSettings.setSquadta gColor 0
Obviously that is a problem - I was wondering why I was losing my crosshair colour but on investigation found that.
Idle_Mind: Thanks for the reply. Had a long session this evening reading through wsh syntax but still no further. I added in the lines you specified however the first error was "Variable is undefined: 'cmd'. So I added a Dim cmd which shut that up but created a Variable is undefined: objShell error.
A quick Dim objShell before the line cured that (why I do not know as they appear to be core commands) and suddenly 2 things, first a Variable is undefined: objExecObject pops up and at the same time the game attempts to run, but I can tell its without the switches as it errors out in the usual place.
Ive tried different approaches, most by trial and error but got nowhere. All the little tutorial examples on wsh create object seem to focus on running trivial programs like notepad or passing a doc file to word and nothing about passing command switches...I cant belive its not possible, It cant be the first time anyones tried to run a program from a script surely?
mattcarver: Thanks for the reply but nothing still, no run. As soon as I remove the switches it attempts to run, the bf2 loading screen appears but of course errors. On top of that Ive found a bug- when parsing or writing, it misses off secondary characters from 3 of the lines.
GeneralSettings.setCrossha
GeneralSettings.setBuddyta
GeneralSettings.setSquadta
becomes
GeneralSettings.setCrossha
GeneralSettings.setBuddyta
GeneralSettings.setSquadta
Obviously that is a problem - I was wondering why I was losing my crosshair colour but on investigation found that.
Idle_Mind: Thanks for the reply. Had a long session this evening reading through wsh syntax but still no further. I added in the lines you specified however the first error was "Variable is undefined: 'cmd'. So I added a Dim cmd which shut that up but created a Variable is undefined: objShell error.
A quick Dim objShell before the line cured that (why I do not know as they appear to be core commands) and suddenly 2 things, first a Variable is undefined: objExecObject pops up and at the same time the game attempts to run, but I can tell its without the switches as it errors out in the usual place.
Ive tried different approaches, most by trial and error but got nowhere. All the little tutorial examples on wsh create object seem to focus on running trivial programs like notepad or passing a doc file to word and nothing about passing command switches...I cant belive its not possible, It cant be the first time anyones tried to run a program from a script surely?
ASKER
Oh and just for simplicities sake, lets make the path and switches
F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1
rather than dragging all the account info into it...if/when the above runs then the rest can be added after.
F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1
rather than dragging all the account info into it...if/when the above runs then the rest can be added after.
Sorry for the late response. I fixed the bug with the cutoff. I also changed the double quotes to surround the entire command string. I think that may have been the problem, Here you are:
------------------------ BEGIN CUTTING BELOW THIS LINE --------------------------
@ECHO OFF
SET FIXPATH="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="general.con"
SET TEMPFILE="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\general.tm p"
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad dServerHis tory" ECHO %%i %%j >> %TEMPFILE%
DEL %FIXPATH%%FIXFILE%
RENAME %TEMPFILE% %FIXFILE%
"F:\Games\Battlefield 2\BF2.exe +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes"
------------------------ BEGIN CUTTING BELOW THIS LINE --------------------------
@ECHO OFF
SET FIXPATH="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="general.con"
SET TEMPFILE="C:\Documents and Settings\Ad\My Documents\Battlefield 2\Profiles\0003\general.tm
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad
DEL %FIXPATH%%FIXFILE%
RENAME %TEMPFILE% %FIXFILE%
"F:\Games\Battlefield 2\BF2.exe +menu 1 +fullscreen 1 +username *~blaster~* +playerPassword cornflakes"
ASKER
I dont know what to say guys....is this task impossible maybe?
Thanks for repaing the script mattcarver, that definately fixed the missing chrs bug however still no luck with the shortcuts...I have tried with one set of "", two sets, nothing seems to work, well, until the switches are removed and then as mentioned before, it errors out.
The only progress I have made is by putting in and executing the script from the battlefield 2 folder, removing the filepath and just using BF2.exe +menu 1 +fullscreen 1 (no quotes) as the target line - now that actually loads the game further but only as far as the accounts screen and as soon as I retry with the added in correct +username *~blaster~* +playerPassword cornflakes details, or, use any path behind the bf2.exe, then its back to no go.
I think idle_mind has given up already and I wouldnt blame you if you did too, I didnt realise it would be such an insummountable task. Because of the response to the BF2.exe +menu 1 +fullscreen 1 and not any more, im beginning to think theres some special interraction between C written game engines and WinXP shortcuts that cannot be triggererd in dos or wsh.
I did try using the either script as the first part of a multi file bookmark but it would only execute the script and not the game shortcut. No matter what I put in it comes out "F:\Games\Battlefield 2\clr3.bat" "F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1 *~blaster~* +playerPassword cornflakes
Dont really know where to go from here.
Thanks for repaing the script mattcarver, that definately fixed the missing chrs bug however still no luck with the shortcuts...I have tried with one set of "", two sets, nothing seems to work, well, until the switches are removed and then as mentioned before, it errors out.
The only progress I have made is by putting in and executing the script from the battlefield 2 folder, removing the filepath and just using BF2.exe +menu 1 +fullscreen 1 (no quotes) as the target line - now that actually loads the game further but only as far as the accounts screen and as soon as I retry with the added in correct +username *~blaster~* +playerPassword cornflakes details, or, use any path behind the bf2.exe, then its back to no go.
I think idle_mind has given up already and I wouldnt blame you if you did too, I didnt realise it would be such an insummountable task. Because of the response to the BF2.exe +menu 1 +fullscreen 1 and not any more, im beginning to think theres some special interraction between C written game engines and WinXP shortcuts that cannot be triggererd in dos or wsh.
I did try using the either script as the first part of a multi file bookmark but it would only execute the script and not the game shortcut. No matter what I put in it comes out "F:\Games\Battlefield 2\clr3.bat" "F:\Games\Battlefield 2\BF2.exe" +menu 1 +fullscreen 1 *~blaster~* +playerPassword cornflakes
Dont really know where to go from here.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK! now we are in business....at least on the DOS side, Im getting a bf2link.lnk is not a valid win 32 application from the VBS even with my dim patchups, but at least we've got progress on one front, I thought wed never get there, many thanks for being patient matt.
_____________INTERIM CODE _______________
@ECHO OFF
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c on"
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad dServerHis tory" ECHO %%i %%j >> %TEMPFILE%
MOVE %TEMPFILE% %FIXPATH%
bf2link.lnk
_____________END CODE______________________
Right as you can see ive streamlined it a little :) Do you think this will be robust (even though it works for me)? I didnt trust anyone to work out adding general.tmp to the end of the path no matter how well I explained. Also using %userprofile% means thats that user interaction is reduced to just one thing, adding in the correct profile number.
Now the points are yours matt, as the following is outside the original question, but im thinking that to reduce user interaction to zero i need to parse a file called Global.con one directory up that holds a text string pointing to which the live account is. Ive made a stab at what it might look like but I dont know how to parse the data properly.
_____________GLOBAL.CON CONTENTS__________________ ___
GlobalSettings.setDefaultU ser "0003"
GlobalSettings.setNamePref ix ""
______________END GLOBAL.CON________________ __________
Obviously 0003 is my setting, its numbered from 1, and I wouldn't expect people to have more than 9 accounts but it might happen.
In my playing about I got this far
______________TEST CODE______________________ __________ __
@ECHO OFF
SET LIVEPRO=""
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\%LIVEPRO%\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c on"
SET GLOBFILE="%USERPROFILE%\My Documents\Battlefield 2\Profiles\Global.con"
FOR /F "usebackq tokens=1* delims=" %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set DefaultUse r" SET LIVEPRO=%%l
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad dServerHis tory" ECHO %%i %%j >> %TEMPFILE%
MOVE %TEMPFILE% %FIXPATH%
pause
rem bf2link.lnk
__________________________ END TEST CODE______________________ __________ ___
My thinking is making a variable LIVEPRO and using that to hold the parsed 4 digits from Global.con and plug that in with FIXPATH. That way it would always pick the live account but I cant get the damn thing to run- I just get back 2x 'system cannot find the file specified' errors.- is it my syntax or my attempt at a variable variable?
Thanks
_____________INTERIM CODE _______________
@ECHO OFF
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\0003\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad
MOVE %TEMPFILE% %FIXPATH%
bf2link.lnk
_____________END CODE______________________
Right as you can see ive streamlined it a little :) Do you think this will be robust (even though it works for me)? I didnt trust anyone to work out adding general.tmp to the end of the path no matter how well I explained. Also using %userprofile% means thats that user interaction is reduced to just one thing, adding in the correct profile number.
Now the points are yours matt, as the following is outside the original question, but im thinking that to reduce user interaction to zero i need to parse a file called Global.con one directory up that holds a text string pointing to which the live account is. Ive made a stab at what it might look like but I dont know how to parse the data properly.
_____________GLOBAL.CON CONTENTS__________________
GlobalSettings.setDefaultU
GlobalSettings.setNamePref
______________END GLOBAL.CON________________
Obviously 0003 is my setting, its numbered from 1, and I wouldn't expect people to have more than 9 accounts but it might happen.
In my playing about I got this far
______________TEST CODE______________________
@ECHO OFF
SET LIVEPRO=""
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\%LIVEPRO%\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c
SET GLOBFILE="%USERPROFILE%\My
FOR /F "usebackq tokens=1* delims=" %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad
MOVE %TEMPFILE% %FIXPATH%
pause
rem bf2link.lnk
__________________________
My thinking is making a variable LIVEPRO and using that to hold the parsed 4 digits from Global.con and plug that in with FIXPATH. That way it would always pick the live account but I cant get the damn thing to run- I just get back 2x 'system cannot find the file specified' errors.- is it my syntax or my attempt at a variable variable?
Thanks
ASKER
I still cant get this right
if I do a test script with just this lot in
SET GLOBFILE="%USERPROFILE%\My Documents\Battlefield 2\Profiles\Global.con"
SET TESTFILE="%TEMP%\test.con"
FOR /F "usebackq tokens=1*" %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set DefaultUse r" ECHO %%l >> %TESTFILE%
I get exactly what I expect, a file called test.con in temp with the text "0003" inside it. However in the main script perhaps %LIVEPRO% gets ""0003"" passed to it?? Or maybe my SET LIVEPRO=%%l instead of the ECHO is messing things up?
The only errors I get are the 2x 'system cannot find the file specified' errors, that is solely from your line not finding the full FIXPATH variable (which is understandable) but other than that it appears error free.
But does not work.
If I do this
_______________________TES T_________ __________ __________ ___
@ECHO OFF
SET LIVEPRO="0003"
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\%LIVEPRO%\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c on"
SET GLOBFILE="%USERPROFILE%\My Documents\Battlefield 2\Profiles\Global.con"
FOR /F "usebackq tokens=1*" %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set DefaultUse r" SET LIVEPRO="%%l"
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad dServerHis tory" ECHO %%i %%j >> %TEMPFILE%
MOVE %TEMPFILE% %FIXPATH%
__________________________ _END TEST______________________ __________ __
It runs but completely ignores my FOR /F line, because if I change the 0003 to 0002 (expecting it to plug 0003 instead of the 0002 set) again its broken therefore its evident that its not setting the LIVEPRO variable properly.
argggghhh!
if I do a test script with just this lot in
SET GLOBFILE="%USERPROFILE%\My
SET TESTFILE="%TEMP%\test.con"
FOR /F "usebackq tokens=1*" %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set
I get exactly what I expect, a file called test.con in temp with the text "0003" inside it. However in the main script perhaps %LIVEPRO% gets ""0003"" passed to it?? Or maybe my SET LIVEPRO=%%l instead of the ECHO is messing things up?
The only errors I get are the 2x 'system cannot find the file specified' errors, that is solely from your line not finding the full FIXPATH variable (which is understandable) but other than that it appears error free.
But does not work.
If I do this
_______________________TES
@ECHO OFF
SET LIVEPRO="0003"
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\%LIVEPRO%\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c
SET GLOBFILE="%USERPROFILE%\My
FOR /F "usebackq tokens=1*" %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad
MOVE %TEMPFILE% %FIXPATH%
__________________________
It runs but completely ignores my FOR /F line, because if I change the 0003 to 0002 (expecting it to plug 0003 instead of the 0002 set) again its broken therefore its evident that its not setting the LIVEPRO variable properly.
argggghhh!
ASKER
FIXED! (at last). Used %%~ to remove the outer quotes from the 003, plus had to make sure LIVEPRO sets before its read. If theres a way to optimise it, feel free to comment.
__________________________ FINAL SCRIPT____________________ ______
@ECHO OFF
rem dont pester me, just run
rem find out which profile last run
SET GLOBFILE="%USERPROFILE%\My Documents\Battlefield 2\Profiles\Global.con"
FOR /F "usebackq tokens=1* delims= " %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set DefaultUse r" SET LIVEPRO="%%~l"
rem clear server history
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\%LIVEPRO%\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c on"
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad dServerHis tory" ECHO %%i %%j >> %TEMPFILE%
MOVE %TEMPFILE% %FIXPATH%
rem load new shortcut because extended bf2 switches wont run from batch
bf2link.lnk
_______________________END SCRIPT____________________ __________ ____
So there we have it, apart from the hassle of copying over a shortcut, theres no input needed. Im still going to investigate why I can't use the full set of switches in a batch file but for now ive got something close.
Thank you very much to mattcarver for code and inspiration and thanks also to idle_mind for trying.
__________________________
@ECHO OFF
rem dont pester me, just run
rem find out which profile last run
SET GLOBFILE="%USERPROFILE%\My
FOR /F "usebackq tokens=1* delims= " %%k IN (%GLOBFILE%) DO IF "%%k"=="GlobalSettings.set
rem clear server history
SET FIXPATH="%USERPROFILE%\My Documents\Battlefield 2\Profiles\%LIVEPRO%\"
SET FIXFILE="General.con"
SET TEMPFILE="%TEMP%\General.c
FOR /F "usebackq tokens=1* delims= " %%i IN (`type %FIXPATH%%FIXFILE%`) DO IF NOT "%%i"=="GeneralSettings.ad
MOVE %TEMPFILE% %FIXPATH%
rem load new shortcut because extended bf2 switches wont run from batch
bf2link.lnk
_______________________END
So there we have it, apart from the hassle of copying over a shortcut, theres no input needed. Im still going to investigate why I can't use the full set of switches in a batch file but for now ive got something close.
Thank you very much to mattcarver for code and inspiration and thanks also to idle_mind for trying.
ASKER