Add special folder verification for issue #144

This commit is contained in:
Michael J. Seiferling
2018-07-24 13:53:52 -06:00
parent 2680f857a9
commit a3572abb3d
4 changed files with 58 additions and 12 deletions
+6
View File
@@ -1051,6 +1051,12 @@ Public Class frmMain
Exit Sub
End If
'Check Special Paths
If Not mgrPath.CheckSpecialPaths Then
bInitFail = True
Exit Sub
End If
'Local Database Check
VerifyDBVersion(mgrSQLite.Database.Local)
LocalDatabaseCheck()
+40 -12
View File
@@ -202,6 +202,28 @@ Public Class mgrPath
Return sResult
End Function
Public Shared Function CheckSpecialPaths() As Boolean
Dim hshEnvs As New Hashtable
Dim bNoError As Boolean = True
hshEnvs.Add("Documents", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
hshEnvs.Add("AppDataRoaming", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
hshEnvs.Add("AppDataLocal", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
If Not mgrCommon.IsUnix Then
hshEnvs.Add("UserData", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
hshEnvs.Add("PublicDocuments", Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments))
End If
For Each de As DictionaryEntry In hshEnvs
If de.Value = String.Empty Then
mgrCommon.ShowMessage(mgrPath_SpecialPathError, de.Key, MsgBoxStyle.Critical)
bNoError = False
End If
Next
Return bNoError
End Function
Public Shared Function ReplaceSpecialPaths(sValue As String) As String
Dim sMyDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sPublicDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
@@ -246,39 +268,45 @@ Public Class mgrPath
Public Shared Function ReverseSpecialPaths(sValue As String) As String
Dim sMyDocs As String = "*mydocs*"
Dim sEnvMyDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sPublicDocs As String = "*publicdocs*"
Dim sAppDataRoaming As String = "*appdatalocal*"
Dim sAppDataLocal As String = "*appdataroaming*"
Dim sEnvPublicDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
Dim sAppDataLocal As String = "*appdatalocal*"
Dim sEnvAppDataLocal As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Dim sAppDataRoaming As String = "*appdataroaming*"
Dim sEnvAppDataRoaming As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Dim sCurrentUser As String = "*currentuser*"
Dim sEnvCurrentUser As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Dim oCustomVariable As clsPathVariable
For Each oCustomVariable In hshCustomVariables.Values
If sValue.Contains(oCustomVariable.Path) Then
Return sValue.Replace(oCustomVariable.Path, oCustomVariable.FormattedName)
End If
Next
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), sAppDataLocal)
If sValue.Contains(sEnvAppDataRoaming) Then
Return sValue.Replace(sEnvAppDataRoaming, sAppDataRoaming)
End If
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), sAppDataRoaming)
If sValue.Contains(sEnvAppDataLocal) Then
Return sValue.Replace(sEnvAppDataLocal, sAppDataLocal)
End If
'This needs to be tested last for Unix compatability
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), sMyDocs)
If sValue.Contains(sEnvMyDocs) Then
Return sValue.Replace(sEnvMyDocs, sMyDocs)
End If
'Don't use these in Unix
If Not mgrCommon.IsUnix Then
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), sPublicDocs)
If sValue.Contains(sEnvPublicDocs) Then
Return sValue.Replace(sEnvPublicDocs, sPublicDocs)
End If
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), sCurrentUser)
If sValue.Contains(sEnvCurrentUser) Then
Return sValue.Replace(sEnvCurrentUser, sCurrentUser)
End If
End If
+9
View File
@@ -6060,6 +6060,15 @@ Namespace My.Resources
End Get
End Property
'''<summary>
''' Looks up a localized string similar to An error occured while determining a required system path. [BR][BR]The environment value for [PARAM] is empty.[BR][BR]The application will now exit..
'''</summary>
Friend ReadOnly Property mgrPath_SpecialPathError() As String
Get
Return ResourceManager.GetString("mgrPath_SpecialPathError", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to [PARAM] backup restored..
'''</summary>
+3
View File
@@ -2191,4 +2191,7 @@
<data name="mgrBackup_ConfirmOverwriteRelative" xml:space="preserve">
<value>A file with the same name already exists in the backup folder.[BR][BR]This game stores saves in a relative location, you may need to restore the current backup if the game was recently re-installed.[BR][BR]Do you want to overwrite this file?</value>
</data>
<data name="mgrPath_SpecialPathError" xml:space="preserve">
<value>An error occured while determining a required system path. [BR][BR]The environment value for [PARAM] is empty.[BR][BR]The application will now exit.</value>
</data>
</root>