RegIniFileSort - Script for smart sorting REG and INI files

RegIniFileSort - Script for smart sorting REG and INI files

4
NewbieNewbie
4

    Nov 10, 2012#1

    The script idea was inspired from the macros for smart sorting INI and REG files posted by Mofi at the IDM user-to-user forum.

    Script features
    • Smart sorting of *.reg and *.ini and similar files
      • sorting of ini section headers and registry keys
      • sorting of items of each ini section and registry key
      • special sorting of UltraEdit/UES INI file. ('Scripting' and 'Tools' sections)
      • sorting of similar files like *.prj and *.pui
    • Shuffle feature
    • Ultra-fast algorithms for sort and shuffle
    Requirements
    • This script requires at least UltraEdit v13.10 or UEStudio v06.30.
    • If you plan to sort a large file with many thousands of lines, please use the script with UltraEdit v14.20.0 or UES v09.00.0 or later.
    Updates

    Modification Date: 19/01/2013

    Improvements suggested by Mofi:
    - Getting document encoding information via a native UE property in supported versions.
    - Detection of NT4/NT5 registry files as well as registry files without a heading.
    - Fix issue a blank line could be missing after sort, if the last line of registry file is not blank.
    - Updated readme file.

    Changes by me:
    - Escaping UE special characters to fix error in UltraEdit.activeDocument.write.
    - Minor enhancements to the existing regular expressions.
    - Other minor changes to some lines of code.

    Note: Users with older versions of UE/UES can still use the macro posted by Mofi which is compatible with all versions of UltraEdit/UEStudio.

    Note: There is another related script RegDelEmptyParentKeys that serves to clean up a registry file from the redundant empty keys after sorting, see RegDelEmptyParentKeys - Clean up a Windows registry file from redundant empty keys.

    It may be useful together with the RegIniFileSort script for example when you want to compare two registry files side by side.
    RegIniFileSort.zip (5.48 KiB)   370
    enhanced script, version 3
    Including Mofi's suggestions

    6,686585
    Grand MasterGrand Master
    6,686585

      Dec 06, 2012#2

      Great work, very impressive.

      I needed to sort today a file with registry values the first time since you published your script, used your script and compared the results with the results created by the macro. Your script worked quite well and of course was much faster than my macro.

      Although the script works fine for registry files, I found 3 points for improvement:
      1. isUnicode function is needed only for UE < 16.00 and UES < 10.00 as for later versions there is an easier method to find out if the current file is a Unicode file or an ASCII/ANSI file (with the exception of rarely used ASCII Escaped Unicode files).
      2. Detection of registry files can be enhanced to support also registry files version 4 as well as registry files without a heading.
        Regedit still supports export of registry data to an ANSI file with REGEDIT4 in first line instead of a UTF-16 LE file with Windows Registry Editor Version 5.00 in first line and I use nearly always the option (file type in export dialog) to export in the older format.
        And I use my macro respectively the script mainly for files containing registry keys and values extracted from a comparison of two registry files which contains at top whether REGEDIT4 nor Windows Registry Editor Version 5.00. Those files always start directly with a registry key (sometimes after a blank line).
      3. If last line of registry file is not a blank line, a blank line could be missing after sort.
      The necessary changes for point 1 and 2 were very easy to do in your script and therefore I have modified the script already. Download the attached ZIP file and compare the enhanced RegIniFileSort.js and also the slightly updated readme.txt in this ZIP file with your original version to see my changes and evaluate them.

      For point 3 I give you an example and hope you can improve your script to handle this case also perfect.

      There is a new ASCII file opened containing following lines with used here as placeholder for a DOS line termination.

      [HKEY_CLASSES_ROOT\.txt]
      @="txtfile"

      [HKEY_CLASSES_ROOT\.ttf]
      @="ttffile"

      Sorting those 5 lines with the already enhanced RegIniFileSort.js produces:

      [HKEY_CLASSES_ROOT\.ttf]
      @="ttffile"
      [HKEY_CLASSES_ROOT\.txt]
      @="txtfile"


      As you can see there is no blank line above the second registry key, but instead a blank line at bottom. A perfect result would be:

      [HKEY_CLASSES_ROOT\.ttf]
      @="ttffile"

      [HKEY_CLASSES_ROOT\.txt]
      @="txtfile"

      Please note that such a file without a blank line at end is not typical. Registry files created with Regedit (version 4 and 5) end always with 2 DOS line terminators. So a really exported registry file would be

      REGEDIT4

      [HKEY_CLASSES_ROOT\.txt]
      @="txtfile"

      [HKEY_CLASSES_ROOT\.ttf]
      @="ttffile"


      And for such a file the result is already perfect.

      If you decide to improve your script to handle this not common case for registry files with no blank line at bottom of the file also correct, please edit your first post and replace the attached ZIP file with a new one containing the script with my enhancements (if they are good in your point of view) and your improvements for this special case.

      4
      NewbieNewbie
      4

        Jan 13, 2013#3

        Thanks mofi for taking the time to review my script and improve it, this was very kind of you.
        I was planning to refine the script with some other minor changes,
        but i did not have the free time since i wrote the script :(
        The changes you suggest are good and I will post an improved version this week end.
        Thanks,

        6,686585
        Grand MasterGrand Master
        6,686585

          Jan 26, 2013#4

          Many thanks for enhancing your great script. Now it works great for the sorting tasks I need from time to time.

          24
          Basic UserBasic User
          24

            Aug 02, 2013#5

            I got this with my registry:

            Code: Select all

            Running script: C:\RegIniFileSort.js
            ========================================================================================================
            The file has 214096188 ascii characters before Sorting
            An error occurred on line 232:
              ��/
            Script failed.
            Line 231 and beyond:

            Code: Select all

            var reSection_block = /\[.+\](?:[\r\n](?:[^[\r\n].*)?)*/g;
            if (a = s.match(reSection_block)) {
            	outputWrite("Number of " + (bRegfile ? "registry keys: " : "ini sections: ") + a.length);
            } else {
            	outputWrite("  ** Error: No matches found. This file may have a wrong structure!");
            	exit;
            }

            6,686585
            Grand MasterGrand Master
            6,686585

              Aug 02, 2013#6

              Your registry file has 204 MB? That must be a registry file from a server or do you use multiple user accounts on a single computer?

              You can for such a large registry file forget the error information. The reason for the script error was an out of memory condition. The script failed to allocate enough memory to complete the task. You can watch this with Windows task manager or Process Explorer tool. If UltraEdit together with all other running 32-bit applications use already 2 GB RAM on Windows x86 or UE itself uses already 2 GB of RAM on Windows x64 which is the maximum addressable RAM for 32-bit applications using signed 32-bit pointers, scripts like this one running on a large file fail with a not really helpful error message. The JavaScript core engine developers have obviously not implemented any bad memory allocation handling in the core as JavaScript is mainly used for webpages where JavaScript scripts use usually only a small amount of memory.

              I suggest as a workaround to sort the large registry file in smaller pieces. For example sort first just HKLM\Software, then HKML\System, all the user accounts separately, ...

              24
              Basic UserBasic User
              24

                Aug 02, 2013#7

                Single user (just me).

                Desktop win7 64-bit.

                But I found this freeware as replacement:
                http://www.registryrecycler.com