1

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.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • Don't hard code the path. Use `User Settings`. See https://msdn.microsoft.com/en-us/library/bb397755(v=vs.110).aspx – Vivek Jain Sep 21 '15 at 07:34
  • user.settings are, as the name says, designed to be for one specific user. If you want to get a portable version I would suggest you take care of the settings by yourself using a json serialize or something similar. – quadroid Sep 21 '15 at 07:43
  • @Console My intention is to add the application into a personalized installer (using InnoSetup) then, at install time I could run an automated tool developed in .Net (VB.Net or else C#) that could do the trick, the question is... How to?. But anyways I think this could be done without that kind of interaction, without developing an app, just designing a proper app.config or user.config file content that will perssist when copying it to another PC (because again I mention I did it in the past). Thanks! – ElektroStudios Sep 21 '15 at 09:42
  • @theghostofc Sorry but did you read the part where I mention its a 3rd party app?, I don't have a source code where to use the settings infrastructure. Thanks anyways! – ElektroStudios Sep 21 '15 at 09:46
  • 1
    @ElektroStudios, sorry, I missed that part. My bad! RED2 code is available on Github https://github.com/hxseven/Remove-Empty-Directories. You may download and tweak it a bit. :) – Vivek Jain Sep 21 '15 at 15:59
  • wha!! how you find it?, very good to know, thanks a lot because that solves the problem ...I'll made the necessary modifications in the source then problem solved, but since I have made a very specific question I would like to know anyway the solution to my question. I keep trying to find out. Thanks again man!. – ElektroStudios Sep 21 '15 at 16:11

2 Answers2

1

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.

Vivek Jain
  • 3,811
  • 6
  • 30
  • 47
0

I solved it by downloading the source code at https://github.com/hxseven/Remove-Empty-Directories and building a default ExeName.exe.config, then in its userSettings section I can modify the settings to preserve a default custom configuration when copying the app directory to another PC, just including the ExeName.exe.config that contains the per user settings, its very easy.

The trick to do it was that.

It doesn't seems to differ from the user.config file that is generated inside the Local AppData folder when per user settings are saved, so I suppose that just an easier way will be to perform the desired modifications under the UI to generate the file in the AppData fiolder, and then rename the generated user.config file to RED2.exe.config and store it in the app's working dir, then copy it to another PC.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417