1 /*******************************************************************************
\r
2 TPI - flexible but useless plug-in framework.
\r
3 Copyright (C) 2002-2009 Silky
\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
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
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
20 *******************************************************************************/
\r
22 //******************************************************************************
\r
24 //******************************************************************************
\r
27 #include "frm_main.h"
\r
28 #include "dlg_make.h"
\r
29 #include "functions.h"
\r
31 //******************************************************************************
\r
33 //******************************************************************************
\r
35 bool TreeView_CheckNewerItem(wxTreeCtrl * tree_ctrl, const wxTreeItemId & idParent, const wxString & szDirPath, bool bReallyMake)
\r
38 wxTreeItemIdValue idv;
\r
39 wxTreeItemId idChild = tree_ctrl->GetFirstChild(idParent, idv);
\r
40 wxChar cSep = wxFileName::GetPathSeparator();
\r
41 while (idChild.IsOk())
\r
44 if (tree_ctrl->GetItemText(idChild) == szDirPath.BeforeFirst(cSep))
\r
47 if (szDirPath.Find(cSep) == wxNOT_FOUND)
\r
53 return TreeView_CheckNewerItem(tree_ctrl, idChild, szDirPath.AfterFirst(cSep), bReallyMake);
\r
56 idChild = tree_ctrl->GetNextSibling(idChild);
\r
60 if (! szDirPath.IsEmpty())
\r
69 wxString szTemp = szDirPath;
\r
70 wxTreeItemId idTemp = idParent;
\r
74 idTemp = tree_ctrl->AppendItem(idTemp, szTemp.BeforeFirst(cSep), 0, 1);
\r
75 szTemp = szTemp.AfterFirst(cSep);
\r
77 while (szTemp.Find(cSep) != wxNOT_FOUND);
\r
79 // 最後に空でない場合にはもう1階層作成。
\r
80 if (! szTemp.IsEmpty())
\r
82 tree_ctrl->AppendItem(idTemp, szTemp, 0, 1);
\r
89 wxString TreeView_GetItemPath(wxTreeCtrl * tree_ctrl, wxTreeItemId idItem)
\r
91 wxString szItemName = tree_ctrl->GetItemText(idItem), szNodePath = wxEmptyString;
\r
92 wxChar cSep = wxFileName::GetPathSeparator();
\r
95 while (! szItemName.IsEmpty())
\r
97 if (szItemName == wxT("-----"))
\r
103 szNodePath = szItemName + cSep + szNodePath;
\r
106 idItem = tree_ctrl->GetItemParent(idItem);
\r
107 if (idItem == tree_ctrl->GetRootItem())
\r
110 szNodePath = wxT("*");
\r
113 szItemName = tree_ctrl->GetItemText(idItem);
\r
116 return (szNodePath.Find(cSep) == wxNOT_FOUND) ? szNodePath : szNodePath.BeforeLast(cSep);
\r
119 //******************************************************************************
\r
121 //******************************************************************************
\r
124 wxFileName MakeDirPath(const wxFileName & fnPath, const wxString & szBase, bool bAct)
\r
127 wxFileName fnDir = fnPath;
\r
128 fnDir.AppendDir(szBase);
\r
129 if (! fnDir.DirExists() && ! ::wxFileExists(fnDir.GetPath()))
\r
131 if (! bAct || fnDir.Mkdir())
\r
137 // ダメなら"_%d"を付加して試行。
\r
138 for (int i = 0; i < 255; i++)
\r
141 fnDir.AppendDir(szBase + wxString::Format(wxT("_%d"), i));
\r
142 if (! fnDir.DirExists() && ! ::wxFileExists(fnDir.GetPath()))
\r
144 if (! bAct || fnDir.Mkdir())
\r
156 wxArrayString MakeTargetFileList(MainFrame * frm, bool fOnlyOneFile)
\r
159 const int nState = frm->list_ctrl->GetSelectedItemCount() == 0 ? wxLIST_STATE_DONTCARE : wxLIST_STATE_SELECTED;
\r
160 long nId = frm->list_ctrl->GetNextItem(-1, wxLIST_NEXT_ALL, nState);
\r
163 as.Add(((TPI_FILEINFO *) frm->list_ctrl->apShowFile[nId])->szStoredName);
\r
168 nId = frm->list_ctrl->GetNextItem(nId, wxLIST_NEXT_ALL, nState);
\r
174 bool WillMakeDirByArcName(MainFrame * frm, MakeDialog * mk)
\r
176 if (mk->chDirMake->GetSelection() != 2)
\r
178 return mk->chDirMake->GetSelection() == 1;
\r
181 // ルートにディレクトリとファイル合わせて2個以上あるとき、ディレクトリを作成。
\r
182 wxTreeItemId tiArcRoot = frm->tree_ctrl->GetLastChild(frm->tree_ctrl->GetRootItem());
\r
183 switch (frm->tree_ctrl->GetChildrenCount(tiArcRoot, false))
\r
187 // ディレクトリがないので、ルートにファイルが2個以上あるかどうかを判定。
\r
188 bool fFlag = false;
\r
189 for (size_t i = 0; i < frm->fileinfo.GetCount(); i++)
\r
191 if (frm->fileinfo[i].fnFileName.GetPath().IsEmpty())
\r
205 // ディレクトリが1個なので、ルートにファイルがないかどうかを判定。
\r
206 for (size_t i = 0; i < frm->fileinfo.GetCount(); i++)
\r
208 // ディレクトリメンバが格納されている場合には、その名前がツリービューのアイテム名に一致した場合はカウントしない。
\r
209 if (frm->fileinfo[i].fnFileName.GetPath().IsEmpty() && frm->fileinfo[i].fnFileName.GetFullName() != frm->tree_ctrl->GetItemText(frm->tree_ctrl->GetLastChild(tiArcRoot)))
\r
216 // ディレクトリだけで2個以上あるので、自動的に展開先ディレクトリを作成。
\r
223 wxString GetFileTypeName(const wxFileName & fn)
\r
225 wxString szExt = fn.GetExt().MakeUpper();
\r
226 wxString sz = szExt + (szExt.IsEmpty() ? wxEmptyString : wxT(" ")) + _("file");
\r
227 wxFileType * ftFile = wxTheMimeTypesManager->GetFileTypeFromExtension(szExt);
\r
230 ftFile->GetDescription(& sz);
\r
235 wxIcon GetFileTypeIcon(const wxFileName & fn)
\r
238 wxIconLocation ilFile;
\r
239 wxFileType * ftFile = wxTheMimeTypesManager->GetFileTypeFromExtension(fn.GetExt());
\r
240 if (ftFile && ftFile->GetIcon(& ilFile))
\r
242 if (! ::wxFileExists(ilFile.GetFileName()))
\r
244 icon.CopyFromBitmap(wxBitmap((ilFile.GetFileName() == wxT("%1") || ilFile.GetFileName() == wxT("\"%1\"")) ? L_DIR_S_ICO wxT("exe.png") : L_DIR_S_ICO wxT("file.png"), wxBITMAP_TYPE_ANY));
\r
248 icon = wxIcon(ilFile);
\r
253 icon.CopyFromBitmap(wxBitmap(L_DIR_S_ICO wxT("file.png"), wxBITMAP_TYPE_ANY));
\r
258 wxString QuoteString(const wxString & s)
\r
260 return wxT('"') + s + wxT('"');
\r
263 //******************************************************************************
\r
265 //******************************************************************************
\r
267 void myProcess::OnTerminate(int, int)
\r
269 chmod(this->szFile.ToUTF8(), 0600);
\r
270 ::wxRemoveFile(this->szFile);
\r
271 ::wxRmdir(this->szDir);
\r