Tapatalk

Macros for smart sorting INI and REG files

Macros for smart sorting INI and REG files

6,685587
Grand MasterGrand Master
6,685587

    Sep 02, 2009#1

    Do you want to compare two INI files, for example uedit32.ini from a previous version with an updated or just created new uedit32.ini or uedit64.ini?

    Yes, then you could have a problem because the lines in an INI file are often not sorted and even whole groups are stored in the INI files on different positions. That makes it nearly impossible to compare two different INIs of an application.

    Or have you exported a registry key with all its subkeys from two different computers, or from a program before installing a new version and after running the new program version, and want to compare the REG files now?

    Well, then you have often the same problem as with comparing INI files, the lines in the *.reg files are not in any useful order for comparison.

    Here is the solution for you: specialfilesorts.zip.

    This ZIP file contains an UltraEdit/UEStudio macro file with mainly 3 macros:
    • Sort INI File
      This macro is the default macro after loading the macro file. It sorts INI files by sorting the lines of a group not case sensitive, but numeric independent where a number exists in a setting name. Additionally the groups are also sorted alphabetically and numeric in the INI file. It can be used also for files with a different extension, but using the structure of INI files like *.prj and *.pui files.
       
    • Sort REG File
      This macro is similar to the macro for sorting INI files. It is for sorting the content of Windows registry files (*.reg). Supported are registry files version 4 in ASCII/ANSI (first line is REGEDIT4) and version 5 in Unicode with encoding UTF-16 LE (first line is Windows Registry Editor Version 5.00).
       
    • Sort UE/UES INI
      This is a special add-on for macro Sort INI File. It is designed to sort INI files of UltraEdit (default: uedit32.ini) and UEStudio (default: uestudio.ini) using macro Sort INI File and then move the main group [Settings] to top of the file and sort the groups [Tools] and [Scripting] based on tool/script number instead of the names of the settings.
    Additionally the ZIP file contains also the source code of the macros in the UEM file with lots of comments, additional help and important information.

    Please read the lines at top of the text file with file extension UEM and also the comment lines at top of the macro you want to use before you load the macro file and run one of the macros. They contain important information.

    ATTENTION!
    Never run the macro for sorting an INI file on the INI file currently used by a running application. Always make a copy of the INI file while no instance of the program is running and run the macro on this copy.

    For a faster solution using an UltraEdit script for sorting INI and REG files see RegIniFileSort - Script for smart sorting REG and INI files.

    DISCLAIMER

    THE MACRO SET IN THE PACKAGE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, STATUTORY OR OTHERWISE, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO USE, RESULTS AND PERFORMANCE OF THE MACRO SET IS ASSUMED BY YOU AND IF THE MACRO SET SHOULD PROVE TO BE DEFECTIVE, YOU ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING, REPAIR OR OTHER REMEDIATION. UNDER NO CIRCUMSTANCES, CAN THE AUTHOR BE HELD RESPONSIBLE FOR ANY DAMAGE CAUSED IN ANY USUAL, SPECIAL, OR ACCIDENTAL WAY OR BY THE MACRO SET.

    FEEDBACK

    If you detect a problem with one of the macros, find a spelling mistake in the comments, have a question or a suggestion, or just want to contribute something, please post a reply here.

    HISTORY

    2009-12-29:
    Updated macro Sort UE/UES INI to special sort also Tool ID[0-9]+= in section [Tools] of UltraEdit/UEStudio INI files.

    2011-07-05:
    Updated all 3 macros. The macros Sort INI File and Sort REG File have been improved for a better result on sorting registry files with special keys. And in macro Sort UE/UES INI a small issue has been fixed. For details see my second post below.

    2012-04-21:
    The macros Sort INI File and Sort REG File have been improved once again for a better result on sorting registry files with special keys. For details see my post below from 2012-04-24.
    Further I speed up these 2 macros by using a new method for replicating a registry value name respectively group / registry key name on all lines below which belong to the registry value respectively group / registry key. For details read top of macro source code file SpecialFileSorts.uem.
    For UltraEdit prior v13.00 alternate versions of the macros Sort INI File and Sort REG File are added which work better on large registry files than the faster new versions of the macros. For small files like INI files with just 100 KB or less the faster standard macros can be used also by UltraEdit prior v13.00.

    2013-07-09:
    The macro Sort UE/UES INI improved slightly by adding special sort support for setting Script Init Directory.

    36
    Basic UserBasic User
    36

      Sep 02, 2009#2

      Nice mofi, will definitely come to use ^^

      6,685587
      Grand MasterGrand Master
      6,685587

        Jul 06, 2011#3

        I improved the 3 macros in the special file sorts package on 2011-07-05. Below is a detailed description of the changes.


        Changes on macro Sort INI File

        Made 2 small changes in this macro and inserted a new small code block for sorting registry files better. Microsoft Installers (MSI) add during installation in registry many keys with a hexadecimal string of fixed length (GUID). Those keys stored in a *.reg file were partly not correct sorted in previous versions because of the code to get a numeric sort independent on location of a number. With these changes made in macro Sort INI File such registry keys are sorted now also correct. For INI files and similar files these changes have no effect on result.


        Changes on macro Sort REG File

        Enhanced sorting of registry files by using additional code. In the registry keys

        [HKCR] respectively [HKEY_CLASSES_ROOT]
        [HKCU\Software\Classes] respectively [HKEY_CURRENT_USER\Software\Classes]
        [HKLM\Software\Classes] respectively [HKEY_LOCAL_MACHINE\Software\Classes]

        often keys exist which differ from other keys only by a number at end of key name. Some examples:

        [HKEY_CLASSES_ROOT\MDACVer.Version]
        @="MDACVer.Version"

        [HKEY_CLASSES_ROOT\MDACVer.Version\CLSID]
        @="{54AF9350-1923-11D3-9CA4-00C04F72C514}"

        [HKEY_CLASSES_ROOT\MDACVer.Version\CurVer]
        @="MDACVer.Version.2.81"

        [HKEY_CLASSES_ROOT\MDACVer.Version
        .2.81]
        @="MDACVer.Version"

        [HKEY_CLASSES_ROOT\MDACVer.Version
        .2.81\CLSID]
        @="{54AF9350-1923-11D3-9CA4-00C04F72C514}"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\DirectPlay8.Client]
        @="DirectPlay8Client Object"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\DirectPlay8.Client\CLSID]
        @="{743F1DC6-5ABA-429F-8BDF-C54D03253DC2}"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\DirectPlay8.Client\CurVer]
        @="DirectPlay8.Client.1"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\DirectPlay8.Client
        .1]
        @="DirectPlay8Client Object"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\DirectPlay8.Client
        .1\CLSID]
        @="{743F1DC6-5ABA-429F-8BDF-C54D03253DC2}"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WeOnlyDo.DirItem]
        @="DirItem Class"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WeOnlyDo.DirItem\CLSID]
        @="{86F65A80-59CA-44D3-A6BC-CF7E230D4EB6}"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WeOnlyDo.DirItem
        .1]
        @="DirItem Class"

        [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\WeOnlyDo.DirItem
        .1\CLSID]
        @="{86F65A80-59CA-44D3-A6BC-CF7E230D4EB6}"

        [HKLM\SOFTWARE\Classes\DirectDraw]
        @="DirectDraw Object"

        [HKLM\SOFTWARE\Classes\DirectDraw\CLSID]
        @="{D7B70EE0-4340-11CF-B063-0020AFC2CD35}"

        [HKLM\SOFTWARE\Classes\DirectDraw
        7]
        @="DirectDraw7 Object"

        [HKLM\SOFTWARE\Classes\DirectDraw
        7\CLSID]
        @="{3C305196-50DB-11D3-9CFE-00C04FD930C5}"


        The result with previous version of macro Sort REG File was not as displayed above. The subkeys of the class key without number at end were after sort always below the keys and subkeys starting in name with same string, but end with a (version) number. Such class keys and their subkeys are sorted better now.


        Changes on macro Sort UE/UES INI

        Moved command Clipboard 9 down one line below call of macro Sort INI File because the played macro selects the Windows clipboard before exit and macro Sort UE/UES INI should use the user clipboard until this macro exits too.

          Apr 24, 2012#4

          Sort INI File and Sort REG File from 2011-07-05 failed to correct handle following registry values:

          Code: Select all

          [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\024FDFFF5FFA2D11A94E0006794C4E25]
          "00000000000000000000000000000000"="C?\\Windows\\system32\\msvcirt.dll"
          
          [HKEY_USERS\S-1-5-21-796845957-790525478-725345543-287106\Software\Microsoft\Installer\Win32Assemblies\Global]
          "Microsoft.MSXML2,processorArchitecture=\"x86\",publicKeyToken=\"6bd6b9abf345378f\",version=\"4.20.9818.0\",type=\"win32\""=hex(7):25,\
            5e,47,69,6a,7a,62,5d,69,40,25,46,68,5e,40,51,51,46,64,75,3e,32,49,4e,52,33,\
            60,49,39,26,3f,67,69,50,36,78,2c,73,7b,62,6f,00,00
          As I found out the macros produced for these 2 registry values:

          [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\024FDFFF5FFA2D11A94E0006794C4E25]
          "00000000000000000000000000000000"="C?\\Windows\\system32\\msvcirt.dll"
          ?00000=="C?\\Windows\\system32\\msvcirt.dll"? 0000=="C?\\Windows\\system32\\msvcirt.dll"?00000=="C?\\Windows\\system32\\msvcirt.dll" and so on to ?00000=="C?\\Windows\\system32\\msvcirt.dll"

          [HKEY_USERS\S-1-5-21-796845957-790525478-725345543-287106\Software\Microsoft\Installer\Win32Assemblies\Global]
          "Microsoft.MSXML2,processorArchitecture=\"x86\",publicKeyToken=\"6bd6b9abf345378f\",version=\"4.20.9818.0\",type=\"win32\""=hex(7):25,\

          "Microsoft.MSXML2,processorArchitecture=|08|5e,47,69,6a,7a,62,5d,69,40,25,46,68,5e,40,51,51,46,64,75,3e,32,49,4e,52,33,\
          "Microsoft.MSXML2,processorArchitecture=|09|60,49,39,26,3f,67,69,50,36,78,2c,73,7b,62,6f,00,00

          The first wrong registry value result after sort was caused by a mistake in some regular expressions in macro Sort INI File resulting in this wrong output for value names consisting only of digits.

          The second wrong registry value result after sort was caused by the fact that I had thought no value or setting name would ever contain an equal sign or a double quote character. There are obviously exceptions as everyone can see above. My solution in the macro Sort REG File modified on 2012-04-21 takes exactly this exception into account by replacing temporarily all occurrences of =\" by a placeholder string.

          1581
          Power UserPower User
          1581

            Macro SpecialFileSorts.mac - Sort INI file

            Feb 13, 2018#5

            The macro SpecialFileSorts.mac offers the feature Sort INI File. It works fine, but I found a limitation.

            Example:

            Code: Select all

            [aa]
            a=1
            
            [Layer]
            A_1_HL1=1,0.00,Continuous
            A_1_HL2=2,0.00,Continuous
            A_1_HL3=2,0.00,Continuous
            
            ---> it seems that the commas here create a problem. See description below.
            
            A_1_HL4=150,0.00,Continuous
            A_1_HL5=1,0.00,Continuous
            A_1_HL6=1,0.00,Continuous
            A_1_HLU=219,0.00,Continuous
            --> and continue these lines up to count 49 / 50 / 51 
            You see the entries with two commas. If I have exactly up to 50 entries in the section, it works fine.
            But all lines over the limit of 50 will lose their [Section] and appear at the top of the file.

            Somewhere who can find the problem?

            Regards

            Peter
            UE 26.20.0.74 German / Win 10 x 64 Pro

            6,685587
            Grand MasterGrand Master
            6,685587

              Feb 14, 2018#6

              Peter, I created an INI file with A_1_HL1= to A_1_HL70= in section [Layer] not sorted and executed macro Sort INI File. Here are the results:

              The sort works as expected with UltraEdit for Windows up to v23.20.0.43 (= last public released build of v23.20).

              The entry lines in [Layer] are not sorted as expected but kept together with UltraEdit v24.00.0.42 (= first public released build of v24.00) to v24.10.0.24.

              The entry lines in [Layer] are not sorted as expected and additionally split up into first 50 lines kept in section [Layer] and last 20 lines outside any section with UltraEdit v24.10.0.32 to currently latest v24.20.0.62.
              Best regards from an UC/UE/UES for Windows user from Austria

              1581
              Power UserPower User
              1581

                Feb 14, 2018#7

                Hi Mofi

                thanks for clarification. For me it is not that important that you have to spent some hours more. I think IDM should fix it ...
                UE 26.20.0.74 German / Win 10 x 64 Pro

                6,685587
                Grand MasterGrand Master
                6,685587

                  Feb 15, 2018#8

                  I found two issues:
                  1. UltraEdit v24.xx and UEStudio v17.xx do not convert the macro file created with UE v11.20 for maximum compatibility with all versions of UltraEdit right from macro version 1.00 to macro version 1.35. It was necessary to open each macro file in Edit Macro dialog, insert a space in code and remove it immediately for a pseudo change of macro code, and confirm update of not really changed macro on switching to next macro respectively closing macro editor on last macro. These steps resulted in recompiling each macro from text to binary. The recompilation of all macros from text to binary fixed the issues with not correct sorting the lines in an INI file.
                  2. In macro Sort INI File one UltraEdit regular expression replace all not finding a string to replace resulted in inserting three null bytes before last non whitespace character in last line after sort. I fixed this UE regex replace all issue by inserting at end of each macro a Perl regular expression replace all searching for one or more null bytes and delete them from file.
                  I reported both issues to IDM support by email and hope that both issues are fixed in UE v25.00 and UES v18.00.

                  The attached ZIP file contains the macro file SpecialFileSorts_UEv24_UESv17.mac for usage with UltraEdit for Windows v24.00/v24.10 and UEStudio v17.00/v17.10. It is not usable with UE v24.20 or UES v17.20 because of tagged UltraEdit regular expression replace all are not working correct in UE v24.20 up to currently latest v24.20.0.62 and UES v17.20 up to currently latest v17.20.0.16.
                  SpecialFileSorts_UEv24_UESv17.zip (2.24 KiB)   32
                  Special file sort macros updated for UE v24.xx and UES v17.xx
                  Best regards from an UC/UE/UES for Windows user from Austria

                  11327
                  MasterMaster
                  11327

                    Feb 15, 2018#9

                    Dear Mofi! Thank you for you efforts!

                    Unfortunately, new ini sort macros are sorting my wincmd.ini with UE 24.20.0.62 x64 incorrectly:

                    Code: Select all

                    [1920x1200 (10x20)]
                    Divider=500
                    DividerComments=500@ ividerComments=500@  viderComments=500@ ividerCommen500@ ividerComments=500@   iderComments=500@ ividerCommen500@ ividerComments=500@  viderComments=500@ ividerCommen500@ ividerComments=500@    derComments=500@ ividerCommen500@ ividerComments=500@  viderComments=500@ ividerCommen500@ ividerComments=500@   iderComments=500@ ividerCommen500@ ividerComments=500@  viderComments=500@ ividerCommen500@ ividerComments=500
                    ker    ]»«ZipUni500
                    It's impossible to lead us astray for we don't care even to choose the way.

                    6,685587
                    Grand MasterGrand Master
                    6,685587

                      Feb 16, 2018#10

                      Thank you Ovg. You are right, even recompiled macro with the additional Perl regular expression replace all for deleting null bytes does not work for sorting Wincmd.ini. The complex tagged regular expression replace all used in the macro are not working with UE v24.20 and UES v17.20. I think, I can get the macros work for all UE v24.xx and UES v17.xx by replacing all UltraEdit by Perl regular expression replaces. But that takes some time.
                      Best regards from an UC/UE/UES for Windows user from Austria

                      11327
                      MasterMaster
                      11327

                        Feb 16, 2018#11

                        Mofi wrote: But that takes some time.
                        Of course, don't worry. No problem at all.
                        It's impossible to lead us astray for we don't care even to choose the way.