0
votes

first attempt at posting this question was with severe jet lag. This re-edit of the question I only have the associated sleep deprivation...

I want to know the best way to use the installer to capture path information and then remove any reference to the user profile.

My program is designed to run from a central network location. To reduce network traffic some files are copied to a local drive, eg. AppData\MyProg\

I use a file browse dialogue so the person installing can specify the location:

pg_LocalPaths := CreateInputDirPage(pg_CentralPaths.id,
'Confirm File Locations For User Settings', 'To improve user experience these locations should be off the network.',
'Default Locations are:', False, 'New Folder');
     // Add file browswer item (with an empty caption)
        pg_LocalPaths.Add('Supporting files will be copied here by the application:');
        pg_LocalPaths.Add('User settings (for a single user) will be saved here:');

     // Set initial value 
        pg_LocalPaths.Values[0] := GetPreviousData('pg_LocalPaths0', ExpandConstant('{userappdata}\{#pFolder}'));
        pg_LocalPaths.Values[1] := GetPreviousData('pg_LocalPaths1', ExpandConstant('{userappdata}\{#pFolder}'));

During install the local drive location is specified and stored in a config file.

An issue that I failed to predict is that when the program is installed, the path in the config file is defined for a single user, namely the user performing the install. In practice any user should be able to run the program...

To get the correct path for any given user, my software looks for a string "{UserName}" and replaces it with: Environ(UserName)

MyPath = Replace(MyPath, "{UserName}", Environ(UserName))

So, for example, in the installer I need to replace:

C:\Users\My Name\My Program   OR     C:\Users\My Admin\My Program   

with something like:

C:\Users\\{UserName}\My Program

I alreay have this working in My Program but I am not sure of the best way to get it working in Inno... My inital thought was to write the config file like this:

StringChangeEx(MyPath, "My Name", "{UserName}", True)

Would like some perspective on this, not sure how to get it working for all situations.

Cheers,

1

1 Answers

1
votes

You're doing it the wrong way.

Don't store the complete path in the config file; merely store a value that indicates that the user wishes to store data in the usual per-user location. (Or don't store any value, since that should be the default anyway.)

Then in your application, on every run of your application, use the Shell API to fetch the current AppData path for the current user and append your app's unique subfolder to this.

Note that it is perfectly valid for the user's AppData path to not contain their username, and not even be on C:. Don't make assumptions; use the Shell API. That's what it's for.

(Exactly which one to use and how to call it varies depending on target OS and your programming language of choice, which you haven't specified.)