Sign in to follow this  
Followers 0
Helge

Ini Updater

9 posts in this topic

#1 ·  Posted (edited)

For a couple of weeks ago I made a script that use a INI-file to

receive information for usage..

And after a while I got my hands on a lot of information for it, so I was trying

to make a INI-updater...

The updater have to check the original INI, and the new INI with the newest entries.

And if there is any new, then it should add them to the original..

INI Example 1 : The Original

1=This script
2=is really
3=pissing me
4=off !

INI Example 2 : Update INI

1=This
2=is really
3=a strange
4=project..

Now, if you understood me correctly, you probably found out that all the entries in the update-INI,

EXCEPT nr 2, should be written to the original INI..

Is there a good way of doing this ?

Any help appreciated.

Edited by Helge

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

as long as you know the original values, you can do a simple compare. I would do it with an array, or just fileinclude the original.

$var = IniRead("C:\Temp\myoldfile.ini", "section2", "key", "NotFound")
$var2 = IniRead("C:\Temp\mynewfile.ini", "section2", "key", "NotFound")
if $var2==$var then
IniWrite("C:\Temp\myparsedfile.ini", "section2", "key", $var2)

loop it, or give the keys an array, or do a file read to grab all the keys. Many choices.

What I don't understand is why not just use the new file? If I am reading your text right.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Ok...

I'll try to explain this a little bit better !

The update-script should first check entry nr. 1 in the update-INI, and then check

if it matches with any of the entries in the original INI.

If any matches, then it should skip to the next entry in the update-INI, and continue the process.

If it didn't find any matches at the last entry in the original INI, it adds the value to the original INI.

Pheew....Started to get a little confused there myself..

Anyway, if anyone understood that and wouldn't mind helping me out please leave a post here..

EDIT : Ooh....the reason why it checks all, and don't just replace the update-INI with the

old INI, is because the original-INI can contain entries that the update-INI don't have..

Hope that made clearer..

-Helge E.-

Edited by Helge

Share this post


Link to post
Share on other sites

If you're not locked into a scripted solution, you could always use a compare / merge tool. BeyondCompare and ExamDiff for example.

Share this post


Link to post
Share on other sites

I think he wants it automated that's why he's using AutoIt.

Share this post


Link to post
Share on other sites

If you're not locked into a scripted solution, you could always use a compare / merge tool. BeyondCompare and ExamDiff for example.

I was thinking of using just AutoIt..

If it can't be done (I know it can, be there is a limit....two actually) then I will probably just cancel this project..

Må alle ha en riktig god dag !

Share this post


Link to post
Share on other sites

Hi Helge

I did somthing like this about a year ago with autoit v2. I have been meaning to write it in v3 but havn't got round to it. The updater work for my needs but i must warn you that the coding is quite messy but it does do the job.

AdlibOn

;HideAutoItWin, On

HideAutoItDebug, on

setenv,appname, ini updater v1

setenv,changes, c:\\changes.txt

setenv,number, 1

setenv,modified, 0

setenv,zerolines, 0

FileAppend,, %changes%

;---------------------------------------------------------------------------------------------------------------------

start:

inputbox, riva,%appname%, Please enter the name and path of the ini file you wish to update.\n\nFor example c:\\\\customer\\\\pc01.ini\n\nPlease use double backslashes

IfEqual,riva,, goto, error2

Run, notepad.exe %changes%, C:\\WINNT

WinWaitActive,changes.txt - Notepad

setenv,riva, %riva%

ifnotexist,%riva%,goto, error2

ifnotexist,%changes%,goto, error3

MsgBox, 0, %appname%, Paste all the ini entries into the text file including all headers.

MsgBox, 36, %appname%, do you wish to Update %riva%?

IfMsgBox, no, goto, abort

WinClose,changes.txt - Notepad

WinWaitClose,changes.txt - Notepad

FileAppend,\n*, %changes%

splashtexton,500,200,%companyName%,Working - Please Wait...

Question:

;--------------------------------------------------------------------------------------------------------------

FileReadLine, header, %changes%, %number%

setenv,headercheck, %header%

StringLeft, headercheck , headercheck, 1

IfEqual,headercheck,[, goto, headertitle

goto, error1

Headertitle:

;...................................................................................................

.........

FileReadLine, header, %changes%, %number%

StringTrimLeft,header,header,1

StringTrimRight,header,header,1

      EnvAdd, number, 1

entry:

;...................................................................................................

...........

FileReadLine, iniline, %changes%, %number%

StringLeft, headercheck, iniline, 1

   

StringLen, value, iniline

setenv,error, %value%

StringGetPos,entry,iniline,=

      Envsub, value, %entry%

      EnvAdd, entry, 1

StringTrimLeft,inivalue,iniline,%entry%

StringTrimRight,inientry,iniline,%value%

IfEqual,headercheck,[, goto, Headertitle

Ifequal, iniline, , goto,bypass

Ifequal, iniline, *, goto,end

IniRead, checkentry, %riva%, %Header%, %inientry%

ifnotequal,checkentry,error, Envadd,modified,1

iniwrite,%inivalue%,%riva%, %Header%, %inientry%

EnvAdd, number, 1

goto,entry

BYPASS:

;...................................................................................................

............

envadd,zerolines, 1

EnvAdd, number, 1

goto,entry

;-------------------------------------------------------------------------------------------------------------------

end:

Envsub, number, 4

envsub, number,%modified%

envsub, number,%zerolines%

splashtextoff

MsgBox, 48, %appname%,Total Entries Modified %Modified%, Total Entries Added %number%

exit

error1:

splashtextoff

MsgBox, 48, %appname%, there must be and header before any entry

exit

error2:

splashtextoff

MsgBox, 48, %appname%, you did not enter any path.

goto, start

abort:

WinClose,changes.txt - Notepad

WinWaitClose,changes.txt - Notepad

exit

[ADLIB]Notepad, save the changes?, Send, !y

Share this post


Link to post
Share on other sites

Have you writen any code for this project yet? If so maybe we can help with what you have. :D


Triton

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Have you writen any code for this project yet? If so maybe we can help with what you have.

Yeah, I have..

But I got it at home, and I will not get home before the 15th...

Anyway, you don't need to know the code to be able to make this updater..

Basically it's just matching of two INI-files..

But, I'm sure I can figure something out when I get back home.

Have a great day, people !!

Edited by Helge

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0