OSDN Git Service

Port MySpecialPath.vb to C#
authorEgtra <yusuke.ichinohe@gmail.com>
Sat, 10 Dec 2011 13:40:33 +0000 (22:40 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Wed, 22 Feb 2012 10:47:45 +0000 (19:47 +0900)
Tween/MySpecialPath.vb [deleted file]
Tween/Tween.vbproj
TweenCS/MySpecialPath.cs [new file with mode: 0644]
TweenCS/TweenCS.csproj

diff --git a/Tween/MySpecialPath.vb b/Tween/MySpecialPath.vb
deleted file mode 100644 (file)
index 61a9079..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-Imports System.IO
-Imports Microsoft.Win32
-
-Public Class MySpecialPath
-
-    Public Shared ReadOnly Property UserAppDataPath() As String
-        Get
-            Return GetFileSystemPath(Environment.SpecialFolder.ApplicationData)
-        End Get
-    End Property
-
-    Public Shared ReadOnly Property UserAppDataPath(ByVal productName As String) As String
-        Get
-            Return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName)
-        End Get
-    End Property
-
-    Public Shared ReadOnly Property CommonAppDataPath() As String
-        Get
-            Return GetFileSystemPath(Environment.SpecialFolder.CommonApplicationData)
-        End Get
-    End Property
-
-    Public Shared ReadOnly Property LocalUserAppDataPath() As String
-        Get
-            Return GetFileSystemPath(Environment.SpecialFolder.LocalApplicationData)
-        End Get
-    End Property
-
-    Public Shared ReadOnly Property CommonAppDataRegistry() As RegistryKey
-        Get
-            Return GetRegistryPath(Registry.LocalMachine)
-        End Get
-    End Property
-
-    Public Shared ReadOnly Property UserAppDataRegistry() As RegistryKey
-        Get
-            Return GetRegistryPath(Registry.CurrentUser)
-        End Get
-    End Property
-
-
-    Private Shared Function GetFileSystemPath(ByVal folder As Environment.SpecialFolder) As String
-        ' パスを取得
-        Dim path As String = String.Format("{0}{3}{1}{3}{2}", _
-            Environment.GetFolderPath(folder), _
-            Application.CompanyName, _
-            Application.ProductName,
-            System.IO.Path.DirectorySeparatorChar.ToString())
-
-        ' パスのフォルダを作成
-        SyncLock GetType(Application)
-            If Not Directory.Exists(path) Then
-                Directory.CreateDirectory(path)
-            End If
-        End SyncLock
-        Return path
-    End Function 'GetFileSystemPath
-
-    Private Shared Function GetFileSystemPath(ByVal folder As Environment.SpecialFolder, ByVal productName As String) As String
-        ' パスを取得
-        Dim path As String = String.Format("{0}{3}{1}{3}{2}", _
-            Environment.GetFolderPath(folder), _
-            Application.CompanyName, _
-            productName,
-            System.IO.Path.DirectorySeparatorChar.ToString())
-
-        ' パスのフォルダを作成
-        SyncLock GetType(Application)
-            If Not Directory.Exists(path) Then
-                Directory.CreateDirectory(path)
-            End If
-        End SyncLock
-        Return path
-    End Function 'GetFileSystemPath
-
-    Private Shared Function GetRegistryPath(ByVal key As RegistryKey) As RegistryKey
-        ' パスを取得
-        Dim basePath As String
-        If key Is Registry.LocalMachine Then
-            basePath = "SOFTWARE"
-        Else
-            basePath = "Software"
-        End If
-        Dim path As String = String.Format("{0}\{1}\{2}", _
-            basePath, _
-            Application.CompanyName, _
-            Application.ProductName)
-        ' パスのレジストリ・キーの取得(および作成)
-        Return key.CreateSubKey(path)
-    End Function 'GetRegistryPath
-End Class
\ No newline at end of file
index 54ac547..30856b9 100644 (file)
     <Compile Include="MyLists.vb">
       <SubType>Form</SubType>
     </Compile>
-    <Compile Include="MySpecialPath.vb" />
     <Compile Include="nicoms.vb" />
     <Compile Include="Setting\SettingAtIdList.vb" />
     <Compile Include="Setting\SettingLocal.vb" />
diff --git a/TweenCS/MySpecialPath.cs b/TweenCS/MySpecialPath.cs
new file mode 100644 (file)
index 0000000..7f206ab
--- /dev/null
@@ -0,0 +1,130 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Microsoft.Win32;
+using System.Windows.Forms;
+using System.IO;
+
+namespace Tween
+{
+    public class MySpecialPath
+    {
+        //public static string UserAppDataPath
+        //{
+        //    get
+        //    {
+        //        return GetFileSystemPath(Environment.SpecialFolder.ApplicationData);
+        //    }
+        //}
+        public static string UserAppDataPath()
+        {
+            return GetFileSystemPath(Environment.SpecialFolder.ApplicationData);
+        }
+
+        //public static string UserAppDataPath(string productName)
+        //{
+        //    get
+        //    {
+        //        return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName);
+        //    }
+        //}
+        public static string UserAppDataPath(string productName)
+        {
+            return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName);
+        }
+
+        public static string CommonAppDataPath
+        {
+            get
+            {
+                return GetFileSystemPath(Environment.SpecialFolder.CommonApplicationData);
+            }
+        }
+
+        public static string LocalUserAppDataPath
+        {
+            get
+            {
+                return GetFileSystemPath(Environment.SpecialFolder.LocalApplicationData);
+            }
+        }
+
+        public static RegistryKey CommonAppDataRegistry
+        {
+            get
+            {
+                return GetRegistryPath(Registry.LocalMachine);
+            }
+        }
+
+        public static RegistryKey UserAppDataRegistry
+        {
+            get
+            {
+                return GetRegistryPath(Registry.CurrentUser);
+            }
+        }
+
+
+        private static string GetFileSystemPath(Environment.SpecialFolder folder)
+        {
+            // パスを取得
+            var path = string.Format("{0}{3}{1}{3}{2}",
+                Environment.GetFolderPath(folder),
+                Application.CompanyName,
+                Application.ProductName,
+                Path.DirectorySeparatorChar.ToString());
+
+            // パスのフォルダを作成
+            lock (typeof(Application))
+            {
+                if (!Directory.Exists(path))
+                {
+                    Directory.CreateDirectory(path);
+                }
+            }
+            return path;
+        }
+
+        private static string GetFileSystemPath(Environment.SpecialFolder folder, string productName)
+        {
+            // パスを取得
+            var path = string.Format("{0}{3}{1}{3}{2}",
+                Environment.GetFolderPath(folder),
+                Application.CompanyName,
+                productName,
+                Path.DirectorySeparatorChar.ToString());
+
+            // パスのフォルダを作成
+            lock (typeof(Application))
+            {
+                if (!Directory.Exists(path))
+                {
+                    Directory.CreateDirectory(path);
+                }
+            }
+            return path;
+        }
+
+        private static RegistryKey GetRegistryPath(RegistryKey key)
+        {
+            // パスを取得
+            string basePath;
+            if (key == Registry.LocalMachine)
+            {
+                basePath = "SOFTWARE";
+            }
+            else
+            {
+                basePath = "Software";
+            }
+            var path = string.Format(@"{0}\{1}\{2}",
+                basePath,
+                Application.CompanyName,
+                Application.ProductName);
+            // パスのレジストリ・キーの取得(および作成)
+            return key.CreateSubKey(path);
+        }
+    }
+}
index 4fdebb5..a50c850 100644 (file)
@@ -72,6 +72,7 @@
     <Compile Include="DoubleClickCopyCanceller.cs" />
     <Compile Include="Growl.cs" />
     <Compile Include="MyCommon.cs" />
+    <Compile Include="MySpecialPath.cs" />
     <Compile Include="OpenURL.cs">
       <SubType>Form</SubType>
     </Compile>