OSDN Git Service

プロフィール画面へのD&Dによるアイコン変更時に確認ダイアログを表示するように変更
[opentween/open-tween.git] / OpenTween / MySpecialPath.cs
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.
9 //
10 // This file is part of OpenTween.
11 //
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)
15 // any later version.
16 //
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
20 // for more details.
21 //
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.
26
27 using System;
28 using System.Collections.Generic;
29 using System.Linq;
30 using System.Text;
31 using Microsoft.Win32;
32 using System.Windows.Forms;
33 using System.IO;
34
35 namespace OpenTween
36 {
37     public static class MySpecialPath
38     {
39         //public static string UserAppDataPath
40         //{
41         //    get
42         //    {
43         //        return GetFileSystemPath(Environment.SpecialFolder.ApplicationData);
44         //    }
45         //}
46         public static string UserAppDataPath()
47         {
48             return GetFileSystemPath(Environment.SpecialFolder.ApplicationData);
49         }
50
51         //public static string UserAppDataPath(string productName)
52         //{
53         //    get
54         //    {
55         //        return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName);
56         //    }
57         //}
58         public static string UserAppDataPath(string productName)
59         {
60             return GetFileSystemPath(Environment.SpecialFolder.ApplicationData, productName);
61         }
62
63         public static string CommonAppDataPath
64         {
65             get
66             {
67                 return GetFileSystemPath(Environment.SpecialFolder.CommonApplicationData);
68             }
69         }
70
71         public static string LocalUserAppDataPath
72         {
73             get
74             {
75                 return GetFileSystemPath(Environment.SpecialFolder.LocalApplicationData);
76             }
77         }
78
79         public static RegistryKey CommonAppDataRegistry
80         {
81             get
82             {
83                 return GetRegistryPath(Registry.LocalMachine);
84             }
85         }
86
87         public static RegistryKey UserAppDataRegistry
88         {
89             get
90             {
91                 return GetRegistryPath(Registry.CurrentUser);
92             }
93         }
94
95
96         private static string GetFileSystemPath(Environment.SpecialFolder folder)
97         {
98             // パスを取得
99             var path = string.Format("{0}{3}{1}{3}{2}",
100                 Environment.GetFolderPath(folder),
101                 Application.CompanyName,
102                 Application.ProductName,
103                 Path.DirectorySeparatorChar.ToString());
104
105             // パスのフォルダを作成
106             lock (typeof(Application))
107             {
108                 if (!Directory.Exists(path))
109                 {
110                     Directory.CreateDirectory(path);
111                 }
112             }
113             return path;
114         }
115
116         private static string GetFileSystemPath(Environment.SpecialFolder folder, string productName)
117         {
118             // パスを取得
119             var path = string.Format("{0}{3}{1}{3}{2}",
120                 Environment.GetFolderPath(folder),
121                 Application.CompanyName,
122                 productName,
123                 Path.DirectorySeparatorChar.ToString());
124
125             // パスのフォルダを作成
126             lock (typeof(Application))
127             {
128                 if (!Directory.Exists(path))
129                 {
130                     Directory.CreateDirectory(path);
131                 }
132             }
133             return path;
134         }
135
136         private static RegistryKey GetRegistryPath(RegistryKey key)
137         {
138             // パスを取得
139             string basePath;
140             if (key == Registry.LocalMachine)
141             {
142                 basePath = "SOFTWARE";
143             }
144             else
145             {
146                 basePath = "Software";
147             }
148             var path = string.Format(@"{0}\{1}\{2}",
149                 basePath,
150                 Application.CompanyName,
151                 Application.ProductName);
152             // パスのレジストリ・キーの取得(および作成)
153             return key.CreateSubKey(path);
154         }
155     }
156 }