Build Your Own Arcade Controls Forum
Main => Software Forum => Topic started by: BadMouth on December 01, 2012, 08:41:43 pm
-
I'm looking for an example of a batch file or AHK script to swap out a single line in an .ini file?
I found a couple of batch files online, but they seem more complicated than they should be.
-
Here's how I would do it with ahk. Say we're working with mame.ini. Have mame.ini be one setting (the one you're currently using) and mame_alt.ini be your alternate. The difference between the two files is just that line you want to change.
Then your script would be this:
FileCopy, mame.ini, temp_mame.ini ; this backs up your current setting.
FileCopy, mame_alt.ini, mame.ini, 1 ; this overwrites the mame.ini with your alternate setting.
FileMove, temp_mame.ini, mame_alt.ini, 1 ; this makes your original setting the new alternate.
Everytime you run this script it changes the ini file to your other setting.
There are other ways you could do it, but I think this is the most straight forward.
Hope this helps! :cheers:
-
Thanks for replying. I originally did it that way (for a different issue), but changes made to Mala while it was running would not be saved because they would be overwritten by the old .ini file. It became annoying to have to disable the script and redo the alternate .ini file.
I was trying to avoid a long explanation of everything I have going on that this could solve. :P
Here are the problems being able to do this would address for me:
Some of the Taito Type X games will not run if Mala is running, so I've made an autohotkey script that kills Mala, launches the game, then relaunches Mala on game exit.
Add to that a rotating monitor that Mala has to stay oriented correctly with.
The orientation issue was fixed via a Da'OldMan creation, malaori3, which he graciously modified to suit my purposes. It overwrites the lines in the .ini file responsible for orientation. However, since Mala is killed instead of shut down properly, Mala is not able to write the gamelist and position I was at to the .ini file.
So when Mala is relaunched, it will be on the gamelist and game that it was on last time it was shut down properly instead of where it was when the game was launched.
If I were able to change those lines of the .ini file as part of my script for launching the game and relaunching Mala, it could take me back to game Mala had highlighted before being killed. This would be different for each of the four games that I had to kill Mala to launch.
Add to that the startup video needing to be disabled, and I'd have 5 .ini files that I would need to make changes to any time I made a change in Mala's options menu.
It would simplify things immensely if I could just have each script swap in the things it needs to.
I'm having a hard time understanding exactly what I need to change in the examples I've found online.
http://www.dostips.com/DtCodeBatchFiles.php#Batch.FindAndReplace (http://www.dostips.com/DtCodeBatchFiles.php#Batch.FindAndReplace)
https://irfanview-forum.de/showthread.php?t=3263 (https://irfanview-forum.de/showthread.php?t=3263)
I also don't know if the fact that I need to change lines that contain "=" will mean that it needs to be handled in a special way.
:dizzy:
-
Have you checked out IniWrite (http://www.autohotkey.com/docs/commands/IniWrite.htm) for AHK?
-
Have you checked out IniWrite (http://www.autohotkey.com/docs/commands/IniWrite.htm) for AHK?
I never dreamed it would be that simple!
I'd been searching for how to swap text in a txt file.
Never came accross that ahk command.
One friggin' line and it works perfectly.
I can think of a lot of other uses for this too.
:notworthy:
-
Glad you got it worked out, but...D'oh! :banghead: I should have asked about the ini file. For a standard ini file IniWrite is obviously the way to go. I was thinking of Mame's ini file for which you would need something like the method I suggested.