Search code examples
.netwindowsapp-configappsettingsuser-config

How to move an 'user.config' file from source PC to target PC preserving its settings?


I have a 3rd party application, Remove Empty Directories aka RED which can be downloaded here:

http://sourceforge.net/projects/rem-empty-dir/files/?source=navbar

The user settings of the application follows the standard .Net settings infrastructure, it saves its settings in a directory like this:

...\AppData\Local\RED2\RED2.ex_Url_ilre4odeu2sx2xsqyulyx2jybty45cd5\2.2.0.0

My problem is that I will make the ignore_directories setting perssistent inside the user.config file when I move the application folder to another PC, I mean that I will preserve the user settings of the source PC when I move the app and the settings file to the target PC, but of course I can't just copy the folder that stores the user.config file because the user.config settings will be automatically stored in a new folder with a new hash totally different from the source PC, so the old user.config file in the target PC will be ignored ...not recognized.

This is the default content of the user.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="RED2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <RED2.Properties.Settings>
            <setting name="last_used_directory" serializeAs="String">
                <value>C:\Users\Administrador\AppData\Local\RED2\RED2.ex_Url_ilre4odeu2sx2xsqyulyx2jybty45cd5\</value>
            </setting>
            <setting name="infinite_loop_detection_count" serializeAs="String">
                <value>10</value>
            </setting>
            <setting name="pause_between" serializeAs="String">
                <value>80</value>
            </setting>
            <setting name="max_depth" serializeAs="String">
                <value>-1</value>
            </setting>
            <setting name="ignore_directories" serializeAs="String">
                <value>System Volume Information
RECYCLER
Papierkorb
Recycled
NtUninstall
$RECYCLE.BIN
GAC_MSIL</value>
            </setting>
        </RED2.Properties.Settings>
    </userSettings>
</configuration>

This is the content that I will make perssistent/portable:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="RED2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <RED2.Properties.Settings>
            <setting name="last_used_directory" serializeAs="String">
                <value>C:\</value>
            </setting>
            <setting name="infinite_loop_detection_count" serializeAs="String">
                <value>10</value>
            </setting>
            <setting name="ignore_0kb_files" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="pause_between" serializeAs="String">
                <value>80</value>
            </setting>
            <setting name="max_depth" serializeAs="String">
                <value>-1</value>
            </setting>
            <setting name="keep_system_folders" serializeAs="String">
                <value>False</value>
            </setting>
            <setting name="ignore_directories" serializeAs="String">
                <value>$RECYCLE.BIN
C:\Program Files\WindowsApps\Microsoft.WinJS.2.0_1.0.9600.16384_neutral__8wekyb3d8bbwe\microsoft.system.package.metadata
C:\ProgramData\Microsoft\Crypto
C:\ProgramData\Microsoft\Device Stage
C:\ProgramData\Microsoft\DRM
C:\ProgramData\Microsoft\IdentityCRL
C:\ProgramData\Microsoft\RAC\Temp
C:\ProgramData\Microsoft\Windows\DRM
C:\ProgramData\Microsoft\Windows\Sqm
C:\ProgramData\Microsoft\Windows\Start Menu
C:\Users\Administrador\AppData\Local\Microsoft\CLR_v2.0
C:\Users\Administrador\AppData\Local\Microsoft\Feeds Cache
C:\Users\Administrador\AppData\Local\Microsoft\Windows\AppCache
C:\Users\Administrador\AppData\Local\Microsoft\Windows\Application Shortcuts
C:\Users\Administrador\AppData\Local\Microsoft\Windows\Burn
C:\Users\Administrador\AppData\Local\Microsoft\Windows\Explorer\ThumbCacheToDelete
C:\Users\Administrador\AppData\Local\Microsoft\Windows\INetCache\IE
C:\Users\Administrador\AppData\Local\Microsoft\Windows\Notifications
C:\Users\Administrador\AppData\Roaming\Microsoft\Crypto
C:\Users\Administrador\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch
C:\Users\Administrador\AppData\Roaming\Microsoft\SystemCertificates
C:\Users\Administrador\AppData\Roaming\Microsoft\Windows\AccountPictures
C:\Users\Administrador\AppData\Roaming\Microsoft\Windows\Network Shortcuts
C:\Users\Administrador\AppData\Roaming\Microsoft\Windows\Printer Shortcuts
C:\Users\Administrador\AppData\Roaming\Microsoft\Windows\Recent
C:\Users\Administrador\AppData\Roaming\Microsoft\Windows\Start Menu
C:\Users\Default\AppData\Local\Microsoft\Windows
C:\Users\Default\AppData\Roaming\Microsoft\Windows
C:\Users\Public
C:\Windows\assembly
C:\Windows\Downloaded Program Files
C:\Windows\Help
C:\Windows\ImmersiveControlPanel
C:\Windows\Installer
C:\Windows\Logs
C:\Windows\Microsoft.NET\assembly
C:\Windows\Offline Web Pages
C:\Windows\Resources\Themes\aero
C:\Windows\ServiceProfiles
C:\Windows\servicing
C:\Windows\System32\catroot
C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\CLR_v4.0
C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows
C:\Windows\System32\config\systemprofile\AppData\Roaming\Microsoft\SystemCertificates
C:\Windows\System32\DriverStore\Temp
C:\Windows\System32\LogFiles
C:\Windows\System32\Microsoft\Crypto
C:\Windows\System32\ProximityToast
C:\Windows\System32\RasToast
C:\Windows\SysWOW64\config\systemprofile\AppData\Local\Microsoft\CLR_v4.0_32
C:\Windows\SysWOW64\config\systemprofile\AppData\LocalLow\Microsoft
C:\Windows\SysWOW64\DriverStore\FileRepository
C:\Windows\SysWOW64\ProximityToast
C:\Windows\SysWOW64\RasToast
C:\Windows\Temp
C:\Windows\WinSxS\Backup
C:\Windows\WinSxS\InstallTemp
C:\Windows\WinSxS\Temp
System Volume Information</value>
            </setting>
            <setting name="delete_stats" serializeAs="String">
                <value>3496</value>
            </setting>
        </RED2.Properties.Settings>
    </userSettings>
</configuration>

My question is, I can override the settings file properties or other workaround that could make the user.config file really portable avoiding the problem of the directory hash?

Well, I'm pretty sure its possibly because I did it in the past with another user.config file of another .Net app, I can't remember exactly what I did because it was a lot of trial and error, but I think what I did was creating a new app.config file in the same directory of the application folder and just copying the full content of the user.config stored in AppData directory to my new app.config file in the app's working dir, then editing at my desire the properties inside the app.config file to preserve a custom default value when the app creates the user.config in the AppData directory for first time ran, but that technique didn't worked this time for this application RED2.exe.

I tried some basic ideas like adding the user.config in the same folder where the RED2.exe is stored then adding in the file the configuration I like, also I did the same thing creating an app.config, anything worked, but maybe I did something wrong during the procedure.


Solution

  • It would be easier for you if you have access to the code. RED2 code is available on Github here. You may download and tweak it a bit to suit your purpose.

    This is not a link-only answer. As a solution to a specific problem, access to the code is the best solution in this case. I am just sharing a link to the publically available codebase for everyone to know.