Macros for smart sorting INI and REG files

Help with writing and playing macros

Macros for smart sorting INI and REG files

Postby Mofi » Wed Sep 02, 2009 12:59 am

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?

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Macros for smart sorting INI and REG files

Postby danne » Wed Sep 02, 2009 2:20 am

Nice mofi, will definitely come to use ^^
User avatar
danne
Basic User
Basic User
 
Posts: 36
Joined: Mon Feb 07, 2005 12:00 am

Re: Macros for smart sorting INI and REG files

Postby Mofi » Wed Jul 06, 2011 3:25 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Macros for smart sorting INI and REG files

Postby Mofi » Tue Apr 24, 2012 12:40 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros