1 // OpenTween - Client of Twitter
2 // Copyright (c) 2007-2012 kiri_feather (@kiri_feather) <kiri.feather@gmail.com>
3 // (c) 2008-2012 Moz (@syo68k)
4 // (c) 2008-2012 takeshik (@takeshik) <http://www.takeshik.org/>
5 // (c) 2010-2012 anis774 (@anis774) <http://d.hatena.ne.jp/anis774/>
6 // (c) 2010-2012 fantasticswallow (@f_swallow) <http://twitter.com/f_swallow>
7 // (c) 2012 Egtra (@egtra) <http://dev.activebasic.com/egtra/>
8 // (c) 2012 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
9 // All rights reserved.
11 // This file is part of OpenTween.
13 // This program is free software; you can redistribute it and/or modify it
14 // under the terms of the GNU General public License as published by the Free
15 // Software Foundation; either version 3 of the License, or (at your option)
18 // This program is distributed in the hope that it will be useful, but
19 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
23 // You should have received a copy of the GNU General public License along
24 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
25 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
26 // Boston, MA 02110-1301, USA.
30 using System.Diagnostics;
31 using System.Windows.Forms;
32 using System.Threading;
33 using System.Globalization;
34 using System.Reflection;
38 internal class MyApplication
41 /// アプリケーションのメイン エントリ ポイントです。
46 CheckSettingFilePath();
49 string pt = Application.ExecutablePath.Replace("\\", "/") + "/" + Application.ProductName;
50 using (Mutex mt = new Mutex(false, pt))
52 if (!mt.WaitOne(0, false))
54 var text = string.Format(MyCommon.ReplaceAppName(Properties.Resources.StartupText1), MyCommon.GetAssemblyName());
55 MessageBox.Show(text, MyCommon.ReplaceAppName(Properties.Resources.StartupText2), MessageBoxButtons.OK, MessageBoxIcon.Information);
61 Application.ThreadException += MyApplication_UnhandledException;
63 Application.EnableVisualStyles();
64 Application.SetCompatibleTextRenderingDefault(false);
65 Application.Run(new TweenMain());
73 private static void ShowPreviousWindow()
75 // 実行中の同じアプリケーションのウィンドウ・ハンドルの取得
76 var prevProcess = Win32Api.GetPreviousProcess();
77 if (prevProcess == null)
80 if (prevProcess.MainWindowHandle != IntPtr.Zero)
82 // 起動中のアプリケーションを最前面に表示
83 Win32Api.WakeupWindow(prevProcess.MainWindowHandle);
87 //プロセス特定は出来たが、ウィンドウハンドルが取得できなかった(アイコン化されている)
88 //タスクトレイアイコンのクリックをエミュレート
89 //注:アイコン特定はTooltipの文字列で行うため、多重起動時は先に見つけた物がアクティブになる
90 Win32Api.ClickTasktrayIcon(Application.ProductName);
94 private static void MyApplication_UnhandledException(object sender, ThreadExceptionEventArgs e)
97 if (e.Exception.Message != "A generic error occurred in GDI+." &&
98 e.Exception.Message != "GDI+ で汎用エラーが発生しました。")
100 if (MyCommon.ExceptionOut(e.Exception))
107 private static bool IsEqualCurrentCulture(string CultureName)
109 return Thread.CurrentThread.CurrentUICulture.Name.StartsWith(CultureName);
112 public static string CultureCode
116 if (MyCommon.cultureStr == null)
118 var cfgCommon = SettingCommon.Load();
119 MyCommon.cultureStr = cfgCommon.Language;
120 if (MyCommon.cultureStr == "OS")
122 if (!IsEqualCurrentCulture("ja") &&
123 !IsEqualCurrentCulture("en") &&
124 !IsEqualCurrentCulture("zh-CN"))
126 MyCommon.cultureStr = "en";
130 return MyCommon.cultureStr;
134 public static void InitCulture(string code)
138 Thread.CurrentThread.CurrentUICulture = new CultureInfo(code);
144 public static void InitCulture()
148 if (CultureCode != "OS") Thread.CurrentThread.CurrentUICulture = new CultureInfo(CultureCode);
155 private static void CheckSettingFilePath()
157 if (File.Exists(Path.Combine(Application.StartupPath, "roaming")))
159 MyCommon.settingPath = MySpecialPath.UserAppDataPath();
163 MyCommon.settingPath = Application.StartupPath;