PSF FileRedirectionFixup not working as intended?

Brass Contributor

Hi All,

I need some help.  I have an application that writes to and reads from ProgramFilesX86\ApplicationDir, there's an INI file stored there which contains all the database settings for the application to function.  The APP always looks to ProgramFilesX86\ApplicationDir for this file, but it cannot edit it here, by design.

 

I've use the PSF and a FileRedirectionFixup to redirect requests for that file to another location.  I've pasted the code of my config.json file below.  I've placed my INI file that I need read by the application within the redirected folder, but the application still fails. 

 

{
    "processes": [
        {
            "executable": ".*",
            "fixups": [
                {
                    "dll": "FileRedirectionFixup",
                    "config": {
                        "redirectedPaths": {
                            "packageRelative": [
                                {
                                    "base": "VFS\\ProgramFilesX86\\IMPAC\\METRIQ",
                                    "redirectTargetBase": "C:\\IMPAC\\METRIQ",
                                    "patterns": [
                                        "IMSPHospital\\.ini"
                                    ]
                                },
                                {
                                    "base": "VFS\\ProgramFilesX86\\IMPAC\\METRIQ\\Logs",
                                    "redirectTargetBase": "C:\\IMPAC\\METRIQ\\LOGS",
                                    "patterns": [
                                        "ErrLog\\.log"
                                    ]
                                }
                            ]
                        }
                    }
                }
            ]
        }
    ]
}

 

Is my PSF config.json file wrong, or am I misunderstanding what fileRedirectionFixup will do for me? 

 

My final possibility is there's somethin in the read code of the application looking for this INI that is different than what fileRedirectionFixup is going to handle, and if this is true then I'm going to abandon the msix packaging for this app.

13 Replies

What seems to be happening here is that it's still reading from the ProgramFilesX86\ApplicationData folder, and writing to the location I've specified.  However when I close the app and run it again, over writes the data in the redirected folder and I have to run my initial INI configuration over and over.  Why can't it just read from the redirected location, after I've saved an INI file there?

Hey@John Wildes ,

 

Thank you so much for using the Package Support Framework.  It makes me happy when I hear people using it.

 

Quick question before I mention a solution.  Does this ini file exist before the app is started or is it made while the app is running?

 

@Darren_Hoehna , so normally it would.  When the application starts, it checks to see if there's an INI file, if it doesn't exist then it creates one. 

 

If one exists, but is blank (no meaningful data no connection strings) it brings up a configuration screen upon startup that asks the user to fill in database server, db, auth information.  We don't want this at all.  However, if I include an INI that has prepopulated strings and database information in it (which would be different for every customer) it poses a problem.  

@John Wildes 

 

I see.  So, what you want PSF to do is to find the ini file is ProgramFilesX86/ApplicationData, right?

 

The FRF works differently than what we naturally think as redirection. 

FRF takes the path we want to redirect and PSF takes care of the redirection for us.  An example from your configuration file.

 

{
                                    "base": "VFS\\ProgramFilesX86\\IMPAC\\METRIQ",
                                    "redirectTargetBase": "C:\\IMPAC\\METRIQ",
                                    "patterns": [
                                        "IMSPHospital\\.ini"
                                    ]
                                },

 

This is telling PSF to redirect all file operations in VFS\ProgramFilesX86\IMPAC\METRIQ to C:\IMPAC\METRIQ for all files that match the pattern IMSHospital\.ini.

 

What we want to do is tell PSF to redirect all file operations in ProgramFilesX86\ApplicationData that match the pattern IMSHospital\*.ini.

 

Because ProgramFilesX86 is a known folder I would suggest to use the known folder options instead.

 

Your configuration would look like this.

 

"config": {
    "redirectedPaths": {
        "knownFolders": [
            {
                "id": "ProgramFilesX86",
                "relativePaths": [
                    {
                        "base": "ApplicationData\\IMSHospital",
                        "patterns": [
                            ".*"
                        ]
                    }
                ]
            }
        ]
    }
}

 

Can you please try that and get back to me?

@Darren_Hoehna , thanks for the help. 

 

It's not working.  I now get an endless loop error from the application.  Where is it supposed to end up writing when I do this?  

@Darren_Hoehna when I do this I get this combination of error.

 

Error 1 is I'm assuming when the application sees that there's no .ini file in the C:\Program Files(X86)\IMPAC\METRIQ folder and attempts to create it.  With the redirection in place I was hoping this would see no INI and then would attempt to write it to the "writable" end user %APPDATA% location. 

Error 2 is because it can't log an error to the ErrLog and trying to write the INI file again.  

 

I have to use taskmanager to kill the processes.

 

I've also copied the config.json file I'm using, again maybe I'm doing something wrong.

 

 

{
    "applications": [
        {
            "id": "HOSPITAL",
            "executable": "VFS/ProgramFilesX86/IMPAC/METRIQ/HOSPITAL.exe",
            "workingDirectory": "VFS/ProgramFilesX86/IMPAC/METRIQ"
        },
        {
            "id": "IMSMAX",
            "executable": "VFS/ProgramFilesX86/IMPAC/MOSAIQ Connect/IMSMAX.exe",
            "workingDirectory": "VFS/ProgramFilesX86/IMPAC/MOSAIQ Connect"
        }
    ],
    "processes": [
        {
            "executable": "HOSPITAL",
            "fixups": [
                {
                    "dll": "FileRedirectionFixup32.dll",
                    "config": {
                        "redirectedPaths": {
                            "knownFolders": [
                                {
                                    "id": "ProgramFilesX86",
                                    "relativePaths": [
                                        {
                                            "base": "ApplicationData\\IMSHospital",
                                            "patterns": [
                                                ".*"
                                            ]
                                        },
                                        {
                                            "base": "ApplicationData\\ErrLog",
                                            "patterns": [
                                                ".*"
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                }
            ]
        }
    ]
}

 

 

There's no APPLICATIONDATA directory listed in the MSIX package that I have. 

@John Wildes 

 

You made the configuration file correct.  You're all good there. :)

 

Thank you for trying out my suggestion.  We'll get to the bottom of this issue and make your app work.

 

I'm going to type out my thought process here. 

The configuration tells PSF to redirect all file operations in ProgramFilesX86\ApplicationData\[IMSHospital|ErrLog]

 

When the application looks for the .ini file in C:\Program Files X86\ApplicationData\IMSHospital\*.ini PSF will intercept that call and look at call the same method the application called, just in the redirected location.

 

The same happens when the call is made to make the file.  PSF will intercept the call and redirect the createfile call to the redirected location.

 

From the error messages you attached (Thank you for attaching them) it seems like the application was able to find the ini file but the file is read-only.  The error you are getting is that the application does not have permission to write over the file.

 

What I am confused about is why you got the "can't write over a file that is read-only."  Your original configuration file didn't specify that the ini file is read-only.  My guess is maybe the application writes the file as read-only.

 

Here is how we will continue.

1. We need to make sure PSF is being called.  Is "PSFLauncher32.exe" listed as the executable for the application?

2. Maybe we are getting this error because the ini file is read-only.  To test, could you please remove the ini file before you execute the application?

 

Thanks,

 

Darren.

@Darren_Hoehna so the app checks for the presence of the IMSPHospital.ini in the root of the application directory.  In this instance, it should be looking at C:\ProgramFilesX86\IMPAC\METRIQ\IMSPHospital.ini.  If it doesn't find it, then it tries to create it.  

 

From the application developer.  They say that during this process it looks to a variable, or env variable, not sure which, that is called APPPATH, which essentially is where the .exe located, and our .exe is HOSPITAL.exe .  In the package case, when the app is packaged, the path that comes up to the application is C:\Program files\WindowsApps\<package name>\VFS\ProgramFilesX86\IMPAC\METRIQ , which is READ ONLY by design because it is the application directory within the package, and not writable.  This is why I believe we're getting these read only errors, is that in any case where it's trying to write something it's using this path and not a writable one. 

@Darren_Hoehna 

I also checked the launcher and PSFLauncher32.exe is the executable that launches the app.  The INI shouldn't be read only and isn't readonly on a normal basis.  I believe this to be because it is trying to write to the application directory and the fixup isn't somehow intercepting the requests.

 

The App is VB6 by the way, in case this matters.

@John Wildes 

 

Thank you for replying.

 

I see what is going on.  An environment variable is used so the app can figure out where the install directory is. 

 

What you app developers said is correct.  An application can't write to the install directory because it is read-only be default.  We don't want to mess with that.

 

I can now understand why PSF was not able to redirect the file operation.  I assumed that the application was writing to C:\ProgramfilesX68\... not C:\Program files\WindowsApps\\VFS\ProgramFilesX86\IMPAC\METRIQ.  That would require a change in the configuration.

 

We need to tell PSF to redirect all writes to the pacakge root.  I would try changing the config to point to VFS\ProgramFilesX86\IMPAC\METRIQ and see if that works.

 

Another question.  Is it possible for the app developers to change the programs logic?  That might be easier than trying to get PSF to work.

 

@Darren_Hoehna thanks for your continued help.  When i originally started this I had used the full path for re-direction, and what would happen was the INI file (which is just the first of many files of concern) would be copied out of the package to the redirected location. However, any changes to that file during the application session would be over written the very next time the application started.  so rather than having the app read the redirected location, it reads within the package, and changes the copy that is in the writable location.  This is not preferable.  

 

Changing the application is not something that is going to happen in the current timeline I'm in.   

 

I have a workaround specifically for the INI file that I'm going to look into, but it's only viable if I can have all new folder and file creation that would happen in the application directory happen in the writable redirected location.  it's probably more of a phone conversation to discuss this, not sure if you would be open to that.  

 

Thanks again for the help Darren.

@John Wildes 

 

You are very welcome.  I try to help where I can.

 

PSF's FRF handles redirection for the creation of directories.  If you have a clean slate PSF can redirect the Create Directory calls. 

 

I didn't think re-writing the application would work, but it was worth an ask.

 

I think a phone call would be great.  Before we go further with that action I would like to talk to my boss first.  He is out today but will be in the office tomorrow.  Is it okay if I get back to you on Monday with a time?

@Darren_HoehnaThank you!  Monday is fine.