Correct error in saving settings

This commit is contained in:
Michael Bucari-Tovo 2022-06-20 14:04:03 -06:00
parent b2992da370
commit 141a4c29bb
3 changed files with 33 additions and 18 deletions

View File

@ -52,15 +52,36 @@ namespace FileManager
} }
} }
public static implicit operator string(LongPath path) => path?.Path ?? null; public static implicit operator string(LongPath path) => path?.Path;
[JsonIgnore] [JsonIgnore]
public string ShortPathName public string ShortPathName
{ {
get get
{ {
//Short Path names are useful for navigating to the file in windows explorer,
//which will not recognize paths longer than MAX_PATH. Short path names are not
//always enabled on every volume. So to check if a volume enables short path
//names (aka 8dot3 names), run the following command from an elevated command
//prompt:
//
// fsutil 8dot3name query c:
//
//It will say:
//
// "Based on the above settings, 8dot3 name creation is [enabled/disabled] on c:"
//
//To enable short names on all volumes on the system, run the following command
//from an elevated command prompt:
//
// fsutil 8dot3name set c: 0
//
//Note that after enabling 8dot3 names on a volume, they will only be available
//for newly-created entries in ther file system. Existing entries made while
//8dot3 names were disabled will not be reachable by short paths.
if (Path is null) return null; if (Path is null) return null;
GetShortPathName(Path, longPathBuffer, MAX_PATH); GetShortPathName(Path, longPathBuffer, MaxPathLength);
return longPathBuffer.ToString(); return longPathBuffer.ToString();
} }
} }
@ -84,9 +105,9 @@ namespace FileManager
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern int GetShortPathName(string path, StringBuilder shortPath, int shortPathLength); private static extern int GetShortPathName([MarshalAs(UnmanagedType.LPWStr)] string path, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder shortPath, int shortPathLength);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern int GetLongPathName(string lpszShortPath, StringBuilder lpszLongPath, int cchBuffer); private static extern int GetLongPathName([MarshalAs(UnmanagedType.LPWStr)] string lpszShortPath, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszLongPath, int cchBuffer);
} }
} }

View File

@ -52,12 +52,6 @@ namespace LibationWinForms.Dialogs
return; return;
} }
if (!Directory.Exists(newBooks) && booksSelectControl.SelectedDirectoryIsCustom)
{
validationError($"Not saving change to Books location. This folder does not exist:\r\n{newBooks}", "Folder does not exist");
return;
}
// these 3 should do nothing. Configuration will only init these with a valid value. EditTemplateDialog ensures valid before returning // these 3 should do nothing. Configuration will only init these with a valid value. EditTemplateDialog ensures valid before returning
if (!Templates.Folder.IsValid(folderTemplateTb.Text)) if (!Templates.Folder.IsValid(folderTemplateTb.Text))
{ {
@ -76,8 +70,9 @@ namespace LibationWinForms.Dialogs
} }
#endregion #endregion
if (!Directory.Exists(newBooks) && booksSelectControl.SelectedDirectoryIsKnown) LongPath lonNewBooks = newBooks;
Directory.CreateDirectory(newBooks); if (!Directory.Exists(lonNewBooks))
Directory.CreateDirectory(lonNewBooks);
config.Books = newBooks; config.Books = newBooks;

View File

@ -37,7 +37,6 @@
<ProjectReference Include="..\AppScaffolding\AppScaffolding.csproj" /> <ProjectReference Include="..\AppScaffolding\AppScaffolding.csproj" />
<ProjectReference Include="..\FileLiberator\FileLiberator.csproj" /> <ProjectReference Include="..\FileLiberator\FileLiberator.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Form1.*.cs"> <Compile Update="Form1.*.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
@ -46,7 +45,7 @@
<ItemGroup> <ItemGroup>
<Compile Update="Dialogs\SettingsDialog.*.cs"> <Compile Update="Dialogs\SettingsDialog.*.cs">
<DependentUpon>Dialogs\SettingsDialog.cs</DependentUpon> <DependentUpon>SettingsDialog.cs</DependentUpon>
</Compile> </Compile>
</ItemGroup> </ItemGroup>