Update to version 2.42.1

Some changes
Removed FutureAccesList code as it works only with UWP
This commit is contained in:
Geoffroy BONNEVILLE
2019-07-26 18:28:53 +02:00
parent 85b0e9f321
commit 26e8e5c223
52 changed files with 1373 additions and 506 deletions

View File

@@ -22,6 +22,12 @@ namespace ModernKeePassLib.Native
{
return Environment.OSVersion.Platform;
}
internal static string DecodeArgsToPath(string strApp)
{
if (!string.IsNullOrEmpty(strApp)) return strApp;
return string.Empty;
}
}
internal static class NativeMethods

View File

@@ -234,16 +234,16 @@ namespace ModernKeePassLib.Native
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = EncodePath(strAppPath);
if(!string.IsNullOrEmpty(strParams)) psi.Arguments = strParams;
psi.CreateNoWindow = true;
psi.FileName = strAppPath;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.UseShellExecute = false;
psi.RedirectStandardOutput = bStdOut;
if(strStdInput != null) psi.RedirectStandardInput = true;
if(!string.IsNullOrEmpty(strParams)) psi.Arguments = strParams;
Process p = Process.Start(psi);
pToDispose = p;
@@ -291,7 +291,7 @@ namespace ModernKeePassLib.Native
#if !ModernKeePassLib
if((f & AppRunFlags.DoEvents) != AppRunFlags.None)
{
List<Form> lDisabledForms = new List<Form>();
List<Form> lDisabledForms = new List<Form>();
if((f & AppRunFlags.DisableForms) != AppRunFlags.None)
{
foreach(Form form in Application.OpenForms)
@@ -456,5 +456,76 @@ namespace ModernKeePassLib.Native
// https://referencesource.microsoft.com/#mscorlib/system/runtime/interopservices/windowsruntime/winrtclassactivator.cs
return Type.GetType(strType + ", Windows, ContentType=WindowsRuntime", false);
}
internal static string EncodeDataToArgs(string strData)
{
if(strData == null) { Debug.Assert(false); return string.Empty; }
// Cf. EncodePath and DecodeArgsToPath
if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
{
string str = strData;
str = str.Replace("\\", "\\\\");
str = str.Replace("\"", "\\\"");
// Whether '\'' needs to be encoded depends on the context
// (e.g. surrounding quotes); as we do not know what the
// caller does with the returned string, we assume that
// it will be used in a context where '\'' must not be
// encoded; this behavior is documented
// str = str.Replace("\'", "\\\'");
return str;
}
// See SHELLEXECUTEINFO structure documentation
return strData.Replace("\"", "\"\"\"");
}
/// <summary>
/// Encode a path for <c>Process.Start</c>.
/// </summary>
internal static string EncodePath(string strPath)
{
if(strPath == null) { Debug.Assert(false); return string.Empty; }
// Cf. EncodeDataToArgs and DecodeArgsToPath
if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
{
string str = strPath;
str = str.Replace("\\", "\\\\");
str = str.Replace("\"", "\\\"");
// '\'' must not be encoded in paths (only in args)
// str = str.Replace("\'", "\\\'");
return str;
}
return strPath; // '\"' is not allowed in paths on Windows
}
/// <summary>
/// Decode command line arguments to a path for <c>Process.Start</c>.
/// </summary>
internal static string DecodeArgsToPath(string strArgs)
{
if(strArgs == null) { Debug.Assert(false); return string.Empty; }
string str = strArgs;
// Cf. EncodeDataToArgs and EncodePath
// if(MonoWorkarounds.IsRequired(3471228285U) && IsUnix())
// {
// string strPlh = Guid.NewGuid().ToString();
// str = str.Replace("\\\\", strPlh);
// str = str.Replace("\\\'", "\'");
// str = str.Replace(strPlh, "\\\\"); // Restore
// }
return str; // '\"' is not allowed in paths on Windows
}
}
}

View File

@@ -39,6 +39,9 @@ namespace ModernKeePassLib.Native
internal const uint FILE_SUPPORTS_TRANSACTIONS = 0x00200000;
internal const int MAX_TRANSACTION_DESCRIPTION_LENGTH = 64;
internal static readonly Guid FOLDERID_SkyDrive = new Guid(
"A52BBA46-E9E1-435F-B3D9-28DAA648C0F6");
// internal const uint TF_SFT_SHOWNORMAL = 0x00000001;
// internal const uint TF_SFT_HIDDEN = 0x00000008;
@@ -179,6 +182,10 @@ namespace ModernKeePassLib.Native
string lpNewFileName, IntPtr lpProgressRoutine, IntPtr lpData,
UInt32 dwFlags, IntPtr hTransaction);
[DllImport("Shell32.dll")]
private static extern int SHGetKnownFolderPath(ref Guid rfid, uint dwFlags,
IntPtr hToken, out IntPtr ppszPath);
#if (!KeePassLibSD && !KeePassUAP)
[DllImport("ShlWApi.dll", CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
@@ -256,5 +263,29 @@ namespace ModernKeePassLib.Native
return strRtDir;
#endif
}
internal static string GetKnownFolderPath(Guid g)
{
if(Marshal.SystemDefaultCharSize != 2) { Debug.Assert(false); return string.Empty; }
IntPtr pszPath = IntPtr.Zero;
try
{
if(SHGetKnownFolderPath(ref g, 0, IntPtr.Zero, out pszPath) == 0)
{
if(pszPath != IntPtr.Zero)
return Marshal.PtrToStringUni(pszPath);
else { Debug.Assert(false); }
}
}
catch(Exception) { Debug.Assert(false); }
finally
{
try { if(pszPath != IntPtr.Zero) Marshal.FreeCoTaskMem(pszPath); }
catch(Exception) { Debug.Assert(false); }
}
return string.Empty;
}
}
}