CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2022
    Location
    Montreal, Canada
    Posts
    1

    INI file library checking for duplicates, missing, backing then replace?

    I have--limited--programming experience with C, C++, C# & Java but am not limiting myself to those, I'm more interested in finding something that has a good library to work with INI files or text files. The main program uses a relatively large .ini file, that is used for its settings, which I'm looking to modify from time-to-time, therefore performance is not an issue at all; it would be nice if INI modification would be completed within 1 min on average or if it would be longer on average that there was progress bar, but if not it's ok.

    So I've set the main program at 2 different configuration I'm interested in switching between occasionally; I've compared both configuration back-to-back, then cropped everything that remained the same (between the back-to-back configurations) then saved the difference in 2 different files with a name that reflect which version it is. The main program was not running during that time, only its launcher that has the option to do limited settings modification (more is available by either directly editing the .ini file or using an external (non-main) program). The main program may add or remove lines to the INI file during its use, which what I'm looking for should only account for the lines in the difference files that were removed (from the INI), in which case will be added to the INI. I'm only interested in the specific INI lines that are included in the saved differences (of the back-to-back configuration change).

    So I'd like to do a program that do the following chronologically:
    1. check if the INI file miss any of the saved difference, and if so include a special token during the backup (ie: some_setting=this_program_name_status_missing)
    2. save everything that is to be replaced and cropped (duplicates, explained in next step), only the lines that are included in the saved differences including multiple ones
    3. replace in the INI file only the lines included in the difference files, if a line was missing add it to the INI, and if one had a duplicate only replace its 1st then remove the corresponding duplicates (since the duplicate removal may introduce an issue, it's important that the previous step be done correctly)

    An example of this program actions: At the time of wanting to apply either of the 2 difference file,
    • INI contains for lines that aren't a group or comment a=1, b=2, c=3 & d=4,
    • the difference file contains the lines b=8, c=6 & e=5 (contains no group nor comment),
    • the backup will have the timestamp in its name and have for lines b=2 & c=3,
    • finally the INI will keep its groups, comments and lines a=1 & d=4 as they were but make a replacement such as the line b will become 8 and the line c become 6, as well as adding the line e=5.


    Only once everything else works as intended, I'd like this program to report if either
    • a) the INI file miss any of the items in the difference file (what's before '=' in its lines) or
    • b) any item in the difference file is included more than 1 time in the INI file

    , possibly using Event Viewer (Start Menu > Windows Administrative Tools > Event Viewer).

    Hopefully my explanation made at least a bit of sense, but if you'd like clarification I'd appreciate if it was about a specific part or mention which parts you understood.

    Thank you kindly for your help
    Last edited by 2kaud; March 27th, 2022 at 04:30 AM.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: INI file library checking for duplicates, missing, backing then replace?

    [requested changes made]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured