OSDN Git Service

graphqlエンドポイント使用時にツイート検索の言語指定が効かない不具合を修正
[opentween/open-tween.git] / OpenTween / IconAssetsManager.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.Drawing;
31 using System.IO;
32 using System.Windows.Forms;
33
34 namespace OpenTween
35 {
36     public sealed class IconAssetsManager : IDisposable
37     {
38         public bool IsDisposed { get; private set; } = false;
39
40         /// <summary>ウィンドウ左上のアイコン</summary>
41         public Icon IconMain { get; }
42
43         /// <summary>タブ見出し未読表示アイコン</summary>
44         public Icon IconTab { get; }
45
46         /// <summary>タスクトレイ: 通常時アイコン</summary>
47         public Icon IconTray { get; }
48
49         /// <summary>タスクトレイ: エラー時アイコン</summary>
50         public Icon IconTrayError { get; }
51
52         /// <summary>タスクトレイ: オフライン時アイコン</summary>
53         public Icon IconTrayOffline { get; }
54
55         /// <summary>タスクトレイ: Reply通知アイコン</summary>
56         public Icon IconTrayReply { get; }
57
58         /// <summary>タスクトレイ: Reply通知アイコン(点滅時)</summary>
59         public Icon IconTrayReplyBlink { get; }
60
61         /// <summary>タスクトレイ: 更新中アイコン</summary>
62         public Icon[] IconTrayRefresh { get; }
63
64         private readonly Icon? iconMain;
65         private readonly Icon? iconTab;
66         private readonly Icon? iconAt;
67         private readonly Icon? iconAtRed;
68         private readonly Icon? iconAtSmoke;
69         private readonly Icon? iconReply;
70         private readonly Icon? iconReplyBlink;
71         private readonly Icon? iconRefresh1;
72         private readonly Icon? iconRefresh2;
73         private readonly Icon? iconRefresh3;
74         private readonly Icon? iconRefresh4;
75
76         public IconAssetsManager()
77             : this(Path.Combine(Application.StartupPath, "Icons"))
78         {
79         }
80
81         public IconAssetsManager(string iconsDir)
82         {
83             this.iconMain = this.LoadIcon(iconsDir, "MIcon.ico");
84             this.iconTab = this.LoadIcon(iconsDir, "Tab.ico");
85             this.iconAt = this.LoadIcon(iconsDir, "At.ico");
86             this.iconAtRed = this.LoadIcon(iconsDir, "AtRed.ico");
87             this.iconAtSmoke = this.LoadIcon(iconsDir, "AtSmoke.ico");
88             this.iconReply = this.LoadIcon(iconsDir, "Reply.ico");
89             this.iconReplyBlink = this.LoadIcon(iconsDir, "ReplyBlink.ico");
90             this.iconRefresh1 = this.LoadIcon(iconsDir, "Refresh.ico");
91             this.iconRefresh2 = this.LoadIcon(iconsDir, "Refresh2.ico");
92             this.iconRefresh3 = this.LoadIcon(iconsDir, "Refresh3.ico");
93             this.iconRefresh4 = this.LoadIcon(iconsDir, "Refresh4.ico");
94
95             this.IconMain = this.iconMain ?? Properties.Resources.MIcon;
96             this.IconTab = this.iconTab ?? Properties.Resources.TabIcon;
97             this.IconTray = this.iconAt ?? this.iconMain ?? Properties.Resources.At;
98             this.IconTrayError = this.iconAtRed ?? Properties.Resources.AtRed;
99             this.IconTrayOffline = this.iconAtSmoke ?? Properties.Resources.AtSmoke;
100
101             if (this.iconReply != null && this.iconReplyBlink != null)
102             {
103                 this.IconTrayReply = this.iconReply;
104                 this.IconTrayReplyBlink = this.iconReplyBlink;
105             }
106             else
107             {
108                 this.IconTrayReply = this.iconReply ?? this.iconReplyBlink ?? Properties.Resources.Reply;
109                 this.IconTrayReplyBlink = this.IconTray;
110             }
111
112             if (this.iconRefresh1 == null)
113             {
114                 this.IconTrayRefresh = new[]
115                 {
116                     Properties.Resources.Refresh, Properties.Resources.Refresh2,
117                     Properties.Resources.Refresh3, Properties.Resources.Refresh4,
118                 };
119             }
120             else if (this.iconRefresh2 == null)
121             {
122                 this.IconTrayRefresh = new[] { this.iconRefresh1 };
123             }
124             else if (this.iconRefresh3 == null)
125             {
126                 this.IconTrayRefresh = new[] { this.iconRefresh1, this.iconRefresh2 };
127             }
128             else if (this.iconRefresh4 == null)
129             {
130                 this.IconTrayRefresh = new[] { this.iconRefresh1, this.iconRefresh2, this.iconRefresh3 };
131             }
132             else // iconRefresh1 から iconRefresh4 まで全て揃っている
133             {
134                 this.IconTrayRefresh = new[] { this.iconRefresh1, this.iconRefresh2, this.iconRefresh3, this.iconRefresh4 };
135             }
136         }
137
138         private Icon? LoadIcon(string baseDir, string fileName)
139         {
140             var filePath = Path.Combine(baseDir, fileName);
141             if (!File.Exists(filePath))
142                 return null;
143
144             try
145             {
146                 return new(filePath);
147             }
148             catch
149             {
150                 return null;
151             }
152         }
153
154         public void Dispose()
155         {
156             if (this.IsDisposed)
157                 return;
158
159             this.iconMain?.Dispose();
160             this.iconTab?.Dispose();
161             this.iconAt?.Dispose();
162             this.iconAtRed?.Dispose();
163             this.iconAtSmoke?.Dispose();
164             this.iconReply?.Dispose();
165             this.iconReplyBlink?.Dispose();
166             this.iconRefresh1?.Dispose();
167             this.iconRefresh2?.Dispose();
168             this.iconRefresh3?.Dispose();
169             this.iconRefresh4?.Dispose();
170             this.IsDisposed = true;
171         }
172     }
173 }