1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2011 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2011 Moz (@syo68k)
4 // (c) 2008-2011 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2011 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2011 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2011 Egtra (@egtra) <http://dev.activebasic.com/egtra/>
8 // All rights reserved.
10 // This file is part of OpenTween.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 3 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 // You should have received a copy of the GNU General Public License along
23 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
24 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
25 // Boston, MA 02110-1301, USA.
28 using System.Collections.Generic;
31 using Microsoft.Win32;
32 using System.Windows.Forms;
37 public static class MySpecialPath
39 //public static string UserAppDataPath
43 // return GetFileSystemPath(Environment.SpecialFolder.ApplicationData);
46 public static string UserAppDataPath()
48 return GetFileSystemPath(Environment.SpecialFolder.ApplicationData);
51 //public static string UserAppDataPath(string productName)
55 // return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName);
58 public static string UserAppDataPath(string productName)
60 return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName);
63 public static string CommonAppDataPath
67 return GetFileSystemPath(Environment.SpecialFolder.CommonApplicationData);
71 public static string LocalUserAppDataPath
75 return GetFileSystemPath(Environment.SpecialFolder.LocalApplicationData);
79 public static RegistryKey CommonAppDataRegistry
83 return GetRegistryPath(Registry.LocalMachine);
87 public static RegistryKey UserAppDataRegistry
91 return GetRegistryPath(Registry.CurrentUser);
96 private static string GetFileSystemPath(Environment.SpecialFolder folder)
99 var path = string.Format("{0}{3}{1}{3}{2}",
100 Environment.GetFolderPath(folder),
101 Application.CompanyName,
102 Application.ProductName,
103 Path.DirectorySeparatorChar.ToString());
106 lock (typeof(Application))
108 if (!Directory.Exists(path))
110 Directory.CreateDirectory(path);
116 private static string GetFileSystemPath(Environment.SpecialFolder folder, string productName)
119 var path = string.Format("{0}{3}{1}{3}{2}",
120 Environment.GetFolderPath(folder),
121 Application.CompanyName,
123 Path.DirectorySeparatorChar.ToString());
126 lock (typeof(Application))
128 if (!Directory.Exists(path))
130 Directory.CreateDirectory(path);
136 private static RegistryKey GetRegistryPath(RegistryKey key)
140 if (key == Registry.LocalMachine)
142 basePath = "SOFTWARE";
146 basePath = "Software";
148 var path = string.Format(@"{0}\{1}\{2}",
150 Application.CompanyName,
151 Application.ProductName);
152 // パスのレジストリ・キーの取得(および作成)
153 return key.CreateSubKey(path);