OSDN Git Service

32f90ef4f0f2a232de94fd5fad5bcfd8dcd87069
[tpi/lychee.git] / src / lychee / lychee.cpp
1 /*******************************************************************************\r
2   TPI - flexible but useless plug-in framework.\r
3   Copyright (C) 2002-2009 Silky\r
4 \r
5   This library is free software; you can redistribute it and/or modify it under\r
6   the terms of the GNU Lesser General Public License as published by the Free\r
7   Software Foundation; either version 2.1 of the License, or (at your option)\r
8   any later version.\r
9 \r
10   This library is distributed in the hope that it will be useful, but WITHOUT\r
11   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
12   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License\r
13   for more details.\r
14 \r
15   You should have received a copy of the GNU Lesser General Public License along\r
16   with this library; if not, write to the Free Software Foundation, Inc.,\r
17   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
18 \r
19   $Id$\r
20 *******************************************************************************/\r
21 \r
22 #include "lychee.h"\r
23 #include "frm_main.h"\r
24 #include <wx/cmdline.h>\r
25 \r
26 //******************************************************************************\r
27 // Lychee\r
28 //******************************************************************************\r
29 \r
30 IMPLEMENT_APP(Lychee)\r
31 \r
32 bool Lychee::OnInit()\r
33 {\r
34         wxInitAllImageHandlers();\r
35         ::wxXmlResource::Get()->InitAllHandlers();\r
36 \r
37         // 作業パスを設定。\r
38         wxString szCwd;\r
39         {\r
40                 wxChar cSep = wxFileName::GetPathSeparator();\r
41                 szCwd = ::wxGetCwd() + cSep;\r
42                 wxStandardPaths p;\r
43                 ::wxSetWorkingDirectory(::wxPathOnly(p.GetExecutablePath()) + cSep);\r
44         }\r
45 \r
46         // 言語ファイルのパスを指定。\r
47         this->lc.AddCatalogLookupPathPrefix(L_DIR_S_LOC);\r
48         this->lc.AddCatalog(wxT("lychee"));\r
49 \r
50         MainFrame * frm_main = new MainFrame();\r
51         if (! ::wxXmlResource::Get()->Load(L_DIR_S_XRC wxT("frm_main.xrc")))\r
52         {\r
53                 wxLogError(_("Unable to find XRC!"));\r
54                 return false;\r
55         }\r
56 \r
57         ::wxXmlResource::Get()->LoadFrame(frm_main, NULL, wxT("frame_main"));\r
58         ::wxXmlResource::Get()->Unload(L_DIR_S_XRC wxT("frm_main.xrc"));\r
59         frm_main->InitDialog();\r
60 \r
61         // コマンドライン読み込み。\r
62         wxCmdLineParser cmdLine(this->argc, this->argv);\r
63         cmdLine.SetSwitchChars(wxT("-"));\r
64         cmdLine.AddSwitch(wxT("a"), wxEmptyString, _("(command) Add to archive."));\r
65         cmdLine.AddSwitch(wxT("x"), wxEmptyString, _("(command) Extract archive."));\r
66         cmdLine.AddSwitch(wxT("t"), wxEmptyString, _("(command) Test archive."));\r
67         cmdLine.AddSwitch(wxT("l"), wxEmptyString, _("(command) List archive(default)."));\r
68         cmdLine.AddParam(_("archive"),   wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL);\r
69         cmdLine.AddParam(_("filenames"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL | wxCMD_LINE_PARAM_MULTIPLE);\r
70         if (cmdLine.Parse() != 0)\r
71         {\r
72                 frm_main->Close(true);\r
73                 return true;\r
74         }\r
75 \r
76         if (cmdLine.GetParamCount() == 0)\r
77         {\r
78                 // コマンドラインがなければウインドウを表示。\r
79                 frm_main->Show();\r
80                 return true;\r
81         }\r
82 \r
83         // 書庫を開く。\r
84         wxCommandEvent e;\r
85         frm_main->fnArchive = wxFileName(cmdLine.GetParam(0));\r
86         frm_main->fnArchive.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE | wxPATH_NORM_LONG, szCwd);\r
87         frm_main->OnArcOpen(e);\r
88         if (cmdLine.Found(wxT("a")))\r
89         {\r
90                 // 書庫に追加。\r
91                 frm_main->OnArcAdd(e);\r
92         }\r
93         else if (cmdLine.Found(wxT("t")))\r
94         {\r
95                 // 書庫を検査。\r
96                 frm_main->OnArcTest(e);\r
97         }\r
98         else if (cmdLine.Found(wxT("x")))\r
99         {\r
100                 // 書庫を展開。\r
101                 frm_main->OnArcExtract(e);\r
102         }\r
103         else\r
104         {\r
105                 // 閲覧モード。\r
106                 frm_main->Show();\r
107                 // スプリッター設定(OnInitでは効かないことがあるため)。\r
108                 frm_main->window_splitter->SetSashPosition(frm_main->conf.ReadId(CONF_WINDOW_SPLITTER_POS, 200l));\r
109                 return true;\r
110         }\r
111 \r
112         // 何かコマンドを実行していればこのまま終了。\r
113         frm_main->Close(true);\r
114         return true;\r
115 }\r