Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-05-17 22:26:39 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-05-18 00:41:57 +0300
commit7b98fe3d373f595cffa17df70fb6dcc335842285 (patch)
tree5f94f83f0240f14ec0a4dc4d39b6df8ca393b5e4 /Program.cs
parentc6bcd2bdfb9797a5d8b237b2c78ea61fc90f5783 (diff)
Using Win7 document libraries now, need to test it on XP
Diffstat (limited to 'Program.cs')
-rw-r--r--Program.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/Program.cs b/Program.cs
index 99957aa5..f1386bbb 100644
--- a/Program.cs
+++ b/Program.cs
@@ -7,8 +7,10 @@ using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
+using System.Security.Principal;
using System.Threading;
using System.Windows.Forms;
+using System.Xml;
namespace com.clusterrr.hakchi_gui
{
@@ -61,9 +63,24 @@ namespace com.clusterrr.hakchi_gui
{
BaseDirectoryInternal = Path.GetDirectoryName(Application.ExecutablePath);
if (ApplicationDeployment.IsNetworkDeployed)
+ {
+ // This is not correct way for Windows 7+...
BaseDirectoryExternal = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "hakchi2");
+ // So if it's not exists, lets try to get documents library path (Win7+)
+ try
+ {
+ if (!Directory.Exists(BaseDirectoryExternal))
+ BaseDirectoryExternal = Path.Combine(GetDocumentsLibraryPath(), "hakchi2");
+ }
+ catch (Exception ex)
+ {
+ // TODO: Test it on Windows XP
+ Debug.WriteLine(ex.Message);
+ }
+ }
else
BaseDirectoryExternal = BaseDirectoryInternal;
+ Debug.WriteLine("Base directory: " + BaseDirectoryExternal);
ConfigIni.Load();
try
{
@@ -172,5 +189,30 @@ namespace com.clusterrr.hakchi_gui
}
}
}
+
+ [DllImport("Shell32.dll")]
+ private static extern int SHGetKnownFolderPath([MarshalAs(UnmanagedType.LPStruct)]Guid rfid, uint dwFlags,
+ IntPtr hToken, out IntPtr ppszPath);
+ private static string GetDocumentsLibraryPath()
+ {
+ IntPtr outPath;
+ var documentsLibraryGuid = new Guid("7B0DB17D-9CD2-4A93-9733-46CC89022E7C");
+ int result = SHGetKnownFolderPath(documentsLibraryGuid, 0, WindowsIdentity.GetCurrent().Token, out outPath);
+ if (result >= 0)
+ {
+ var libConfigPath = Marshal.PtrToStringUni(outPath);
+ var libConfig = new XmlDocument();
+ libConfig.LoadXml(File.ReadAllText(libConfigPath));
+ var nsmgr = new XmlNamespaceManager(libConfig.NameTable);
+ nsmgr.AddNamespace("ns", libConfig.LastChild.NamespaceURI);
+ var docs = libConfig.SelectSingleNode("//ns:searchConnectorDescription[ns:isDefaultSaveLocation='true']/ns:simpleLocation/ns:url/text()", nsmgr);
+ return docs.Value;
+ }
+ else
+ {
+ throw new ExternalException("Cannot get the known folder path. It may not be available on this system.",
+ result);
+ }
+ }
}
}