OSDN Git Service

地図サムネイルの設定画面を修正
[opentween/open-tween.git] / OpenTweenUp / MySpecialPath.vb
1 Imports System
2 Imports System.IO
3 Imports System.Windows.Forms
4 Imports Microsoft.Win32
5
6 Public Class MySpecialPath
7
8     Public Shared ReadOnly Property UserAppDataPath() As String
9         Get
10             Return GetFileSystemPath(Environment.SpecialFolder.ApplicationData)
11         End Get
12     End Property
13
14     Public Shared ReadOnly Property UserAppDataPath(ByVal productName As String) As String
15         Get
16             Return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName)
17         End Get
18     End Property
19
20     Public Shared ReadOnly Property CommonAppDataPath() As String
21         Get
22             Return GetFileSystemPath(Environment.SpecialFolder.CommonApplicationData)
23         End Get
24     End Property
25
26     Public Shared ReadOnly Property LocalUserAppDataPath() As String
27         Get
28             Return GetFileSystemPath(Environment.SpecialFolder.LocalApplicationData)
29         End Get
30     End Property
31
32     Public Shared ReadOnly Property CommonAppDataRegistry() As RegistryKey
33         Get
34             Return GetRegistryPath(Registry.LocalMachine)
35         End Get
36     End Property
37
38     Public Shared ReadOnly Property UserAppDataRegistry() As RegistryKey
39         Get
40             Return GetRegistryPath(Registry.CurrentUser)
41         End Get
42     End Property
43
44
45     Private Shared Function GetFileSystemPath(ByVal folder As Environment.SpecialFolder) As String
46         ' パスを取得
47         Dim path As String = String.Format("{0}{3]{1}{3}{2}", _
48             Environment.GetFolderPath(folder), _
49             Application.CompanyName, _
50             Application.ProductName,
51             System.IO.Path.DirectorySeparatorChar.ToString)
52
53         ' パスのフォルダを作成
54         SyncLock GetType(Application)
55             If Not Directory.Exists(path) Then
56                 Directory.CreateDirectory(path)
57             End If
58         End SyncLock
59         Return path
60     End Function 'GetFileSystemPath
61
62     Private Shared Function GetFileSystemPath(ByVal folder As Environment.SpecialFolder, ByVal productName As String) As String
63         ' パスを取得
64         Dim path As String = String.Format("{0}{3]{1}{3}{2}", _
65             Environment.GetFolderPath(folder), _
66             Application.CompanyName, _
67             productName,
68             System.IO.Path.DirectorySeparatorChar)
69
70         ' パスのフォルダを作成
71         SyncLock GetType(Application)
72             If Not Directory.Exists(path) Then
73                 Directory.CreateDirectory(path)
74             End If
75         End SyncLock
76         Return path
77     End Function 'GetFileSystemPath
78
79     Private Shared Function GetRegistryPath(ByVal key As RegistryKey) As RegistryKey
80         ' パスを取得
81         Dim basePath As String
82         If key Is Registry.LocalMachine Then
83             basePath = "SOFTWARE"
84         Else
85             basePath = "Software"
86         End If
87         Dim path As String = String.Format("{0}\{1}\{2}", _
88             basePath, _
89             Application.CompanyName, _
90             Application.ProductName)
91         ' パスのレジストリ・キーの取得(および作成)
92         Return key.CreateSubKey(path)
93     End Function 'GetRegistryPath
94 End Class