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.
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.
32 using System.Windows.Forms;
36 public sealed class IconAssetsManager : IDisposable
38 public bool IsDisposed { get; private set; } = false;
40 /// <summary>ウィンドウ左上のアイコン</summary>
41 public Icon IconMain { get; }
43 /// <summary>タブ見出し未読表示アイコン</summary>
44 public Icon IconTab { get; }
46 /// <summary>タスクトレイ: 通常時アイコン</summary>
47 public Icon IconTray { get; }
49 /// <summary>タスクトレイ: エラー時アイコン</summary>
50 public Icon IconTrayError { get; }
52 /// <summary>タスクトレイ: オフライン時アイコン</summary>
53 public Icon IconTrayOffline { get; }
55 /// <summary>タスクトレイ: Reply通知アイコン</summary>
56 public Icon IconTrayReply { get; }
58 /// <summary>タスクトレイ: Reply通知アイコン(点滅時)</summary>
59 public Icon IconTrayReplyBlink { get; }
61 /// <summary>タスクトレイ: 更新中アイコン</summary>
62 public Icon[] IconTrayRefresh { get; }
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;
76 public IconAssetsManager()
77 : this(Path.Combine(Application.StartupPath, "Icons"))
81 public IconAssetsManager(string iconsDir)
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");
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;
101 if (this.iconReply != null && this.iconReplyBlink != null)
103 this.IconTrayReply = this.iconReply;
104 this.IconTrayReplyBlink = this.iconReplyBlink;
108 this.IconTrayReply = this.iconReply ?? this.iconReplyBlink ?? Properties.Resources.Reply;
109 this.IconTrayReplyBlink = this.IconTray;
112 if (this.iconRefresh1 == null)
114 this.IconTrayRefresh = new[]
116 Properties.Resources.Refresh, Properties.Resources.Refresh2,
117 Properties.Resources.Refresh3, Properties.Resources.Refresh4,
120 else if (this.iconRefresh2 == null)
122 this.IconTrayRefresh = new[] { this.iconRefresh1 };
124 else if (this.iconRefresh3 == null)
126 this.IconTrayRefresh = new[] { this.iconRefresh1, this.iconRefresh2 };
128 else if (this.iconRefresh4 == null)
130 this.IconTrayRefresh = new[] { this.iconRefresh1, this.iconRefresh2, this.iconRefresh3 };
132 else // iconRefresh1 から iconRefresh4 まで全て揃っている
134 this.IconTrayRefresh = new[] { this.iconRefresh1, this.iconRefresh2, this.iconRefresh3, this.iconRefresh4 };
138 private Icon? LoadIcon(string baseDir, string fileName)
140 var filePath = Path.Combine(baseDir, fileName);
141 if (!File.Exists(filePath))
146 return new(filePath);
154 public void Dispose()
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;