OSDN Git Service

C# 8.0 のnull許容参照型を有効化
[opentween/open-tween.git] / OpenTween / Setting / SettingCommon.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      kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
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 #nullable enable
28
29 using System;
30 using System.Xml.Serialization;
31 using System.Collections.Generic;
32 using System.Windows.Forms;
33 using OpenTween.Thumbnail;
34
35 namespace OpenTween
36 {
37     public class SettingCommon : SettingBase<SettingCommon>
38     {
39         #region "Settingクラス基本"
40         public static SettingCommon Load()
41             => LoadSettings();
42
43         public void Save()
44             => SaveSettings(this);
45         #endregion
46
47         public List<UserAccount> UserAccounts = new List<UserAccount>();
48         public string UserName = "";
49
50         [XmlIgnore]
51         public string Password = "";
52         public string EncryptPassword
53         {
54             get => Encrypt(Password);
55             set => Password = Decrypt(value);
56         }
57
58         public string Token = "";
59         [XmlIgnore]
60         public string TokenSecret = "";
61         public string EncryptTokenSecret
62         {
63             get => Encrypt(TokenSecret);
64             set => TokenSecret = Decrypt(value);
65         }
66
67         private string Encrypt(string password)
68         {
69             if (string.IsNullOrEmpty(password)) password = "";
70             if (password.Length > 0)
71             {
72                 try
73                 {
74                     return MyCommon.EncryptString(password);
75                 }
76                 catch (Exception)
77                 {
78                     return "";
79                 }
80             }
81             else
82             {
83                 return "";
84             }
85         }
86         private string Decrypt(string password)
87         {
88             if (string.IsNullOrEmpty(password)) password = "";
89             if (password.Length > 0)
90             {
91                 try
92                 {
93                     password = MyCommon.DecryptString(password);
94                 }
95                 catch (Exception)
96                 {
97                     password = "";
98                 }
99             }
100             return password;
101         }
102
103         public long UserId = 0;
104         public List<string> TabList = new List<string>();
105         public int TimelinePeriod = 90;
106         public int ReplyPeriod = 180;
107         public int DMPeriod = 600;
108         public int PubSearchPeriod = 180;
109         public int ListsPeriod = 180;
110
111         /// <summary>
112         /// 起動時読み込み分を既読にするか。trueなら既読として処理
113         /// </summary>
114         public bool Read = true;
115
116         public bool ListLock = false;
117         public MyCommon.IconSizes IconSize = MyCommon.IconSizes.Icon16;
118         public bool NewAllPop = true;
119         public bool EventNotifyEnabled = true;
120         public MyCommon.EVENTTYPE EventNotifyFlag = MyCommon.EVENTTYPE.All;
121         public MyCommon.EVENTTYPE IsMyEventNotifyFlag = MyCommon.EVENTTYPE.All;
122         public bool ForceEventNotify = false;
123         public bool FavEventUnread = true;
124         public string TranslateLanguage = Properties.Resources.TranslateDefaultLanguage;
125         public string EventSoundFile = "";
126
127         /// <summary>
128         /// サウンド再生(タブ別設定より優先)
129         /// </summary>
130         public bool PlaySound = false;
131
132         /// <summary>
133         /// 未読管理。trueなら未読管理する
134         /// </summary>
135         public bool UnreadManage = true;
136
137         /// <summary>
138         /// 片思い表示。trueなら片思い表示する
139         /// </summary>
140         public bool OneWayLove = true;
141
142         public MyCommon.NameBalloonEnum NameBalloon = MyCommon.NameBalloonEnum.NickName;
143         public bool PostCtrlEnter = false;
144         public bool PostShiftEnter = false;
145         public int CountApi = 60;
146         public int CountApiReply = 40;
147         public bool PostAndGet = true;
148         public bool DispUsername = false;
149         public bool MinimizeToTray = false;
150         public bool CloseToExit = false;
151         public MyCommon.DispTitleEnum DispLatestPost = MyCommon.DispTitleEnum.Post;
152         public bool SortOrderLock = false;
153
154         /// <summary>
155         /// タブを下部に表示するかどうか
156         /// </summary>
157         public bool ViewTabBottom = true;
158
159         public bool TinyUrlResolve = true;
160         public bool StartupVersion = true;
161         public bool StartupFollowers = true;
162         public bool RestrictFavCheck = false;
163         public bool AlwaysTop = false;
164         public string CultureCode = "";
165         public bool UrlConvertAuto = false;
166         public int SortColumn = 3;
167         public int SortOrder = 1;
168         public bool IsMonospace = false;
169         public bool ReadOldPosts = false;
170         public string Language = "OS";
171         public bool Nicoms = false;
172         public List<string> HashTags = new List<string>();
173         public string HashSelected = "";
174         public bool HashIsPermanent = false;
175         public bool HashIsHead = false;
176         public bool HashIsNotAddToAtReply = true;
177         public bool PreviewEnable = true;
178         public bool StatusAreaAtBottom = true;
179
180         public MyCommon.UrlConverter AutoShortUrlFirst = MyCommon.UrlConverter.Uxnu;
181         public bool UseUnreadStyle = true;
182         public string DateTimeFormat = "yyyy/MM/dd H:mm:ss";
183         public int DefaultTimeOut = 20;
184
185         /// <summary>画像アップロードのタイムアウト設定 (秒)</summary>
186         public int UploadImageTimeout { get; set; } = 60;
187
188         public bool RetweetNoConfirm = false;
189         public bool LimitBalloon = false;
190         public bool TabIconDisp = true;
191         public MyCommon.REPLY_ICONSTATE ReplyIconState = MyCommon.REPLY_ICONSTATE.StaticIcon;
192         public bool WideSpaceConvert = true;
193         public bool ReadOwnPost = false;
194         public bool GetFav = true;
195         public string BilyUser = "";
196         public string BitlyPwd = "";
197
198         /// <summary>Bitly API アクセストークン</summary>
199         public string BitlyAccessToken { get; set; } = "";
200
201         public bool ShowGrid = false;
202         public bool UseAtIdSupplement = true;
203         public bool UseHashSupplement = true;
204
205         [XmlElement(ElementName = "TwitterUrl")]
206         public string TwitterApiHost = "api.twitter.com";
207
208         public bool HotkeyEnabled = false;
209         public Keys HotkeyModifier = Keys.None;
210         public Keys HotkeyKey = Keys.None;
211         public int HotkeyValue = 0;
212         public bool BlinkNewMentions = false;
213         public bool FocusLockToStatusText = false;
214         public bool UseAdditionalCount = false;
215         public int MoreCountApi = 200;
216         public int FirstCountApi = 100;
217         public int SearchCountApi = 100;
218         public int FavoritesCountApi = 40;
219         public string TrackWord = "";
220         public bool AllAtReply = false;
221         public bool UserstreamStartup = true;
222         public int UserstreamPeriod = 0;
223         public int UserTimelineCountApi = 20;
224         public int UserTimelinePeriod = 600;
225         public bool OpenUserTimeline = true;
226         public int ListCountApi = 100;
227         public int UseImageService = 0;
228         public string UseImageServiceName = "";
229         public int ListDoubleClickAction = 0;
230         public string UserAppointUrl = "";
231         public bool HideDuplicatedRetweets = false;
232         public bool EnableImgAzyobuziNet = true;
233         public bool ImgAzyobuziNetDisabledInDM = true;
234         public int MapThumbnailHeight = 200;
235         public int MapThumbnailWidth = 200;
236         public int MapThumbnailZoom = 15;
237         public MapProvider MapThumbnailProvider = MapProvider.OpenStreetMap;
238         public bool IsListsIncludeRts = false;
239         public bool TabMouseLock = false;
240         public bool IsRemoveSameEvent = false;
241         public bool IsUseNotifyGrowl = false;
242         public bool ForceIPv4 = false;
243         public bool ErrorReportAnonymous = true;
244
245         /// <summary>pic.twitter.com への画像アップロード時に JPEG への変換を回避する</summary>
246         public bool AlphaPNGWorkaround { get; set; } = false;
247
248         /// <summary>アップデート通知を無視するバージョン番号</summary>
249         [XmlIgnore]
250         public Version? SkipUpdateVersion
251         {
252             get => string.IsNullOrEmpty(this.SkipUpdateVersionStr) ? null : Version.Parse(this.SkipUpdateVersionStr);
253             set => this.SkipUpdateVersionStr = value == null ? "" : value.ToString();
254         }
255
256         [XmlElement(ElementName = nameof(SkipUpdateVersion))]
257         public string SkipUpdateVersionStr { get; set; } = "";
258     }
259
260     public class UserAccount
261     {
262         public string Username = "";
263         public long UserId = 0;
264         public string Token = "";
265         [XmlIgnore]
266         public string TokenSecret = "";
267         public string EncryptTokenSecret
268         {
269             get => Encrypt(TokenSecret);
270             set => TokenSecret = Decrypt(value);
271         }
272         private string Encrypt(string password)
273         {
274             if (string.IsNullOrEmpty(password)) password = "";
275             if (password.Length > 0)
276             {
277                 try
278                 {
279                     return MyCommon.EncryptString(password);
280                 }
281                 catch (Exception)
282                 {
283                     return "";
284                 }
285             }
286             else
287             {
288                 return "";
289             }
290         }
291         private string Decrypt(string password)
292         {
293             if (string.IsNullOrEmpty(password)) password = "";
294             if (password.Length > 0)
295             {
296                 try
297                 {
298                     password = MyCommon.DecryptString(password);
299                 }
300                 catch (Exception)
301                 {
302                     password = "";
303                 }
304             }
305             return password;
306         }
307
308         public override string ToString()
309             => this.Username;
310     }
311 }