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
26 #include "library.h"
\r
28 //******************************************************************************
\r
30 //******************************************************************************
\r
32 wxString ProcessBoolLoop(bool b, const wxString & szCommandLine, size_t * nPos, const wxString & szVal, bool fIf)
\r
34 wxString szCommandLineSend;
\r
36 for (i++; i < szCommandLine.Len() && szCommandLine[i] != (fIf ? wxT('|') : wxT('}')); i++)
\r
40 szCommandLineSend += szCommandLine[i] == wxT('#') ? szVal : szCommandLine[i];
\r
44 return szCommandLineSend;
\r
47 wxString ProcessBool(bool b, const wxString & szCommandLine, size_t * nPos, const wxString & szVal = wxEmptyString)
\r
49 wxString szCommandLineSend;
\r
51 if (szCommandLine[++i] == wxT('{'))
\r
54 szCommandLineSend += ProcessBoolLoop(b, szCommandLine, & i, szVal, true);
\r
55 szCommandLineSend += ProcessBoolLoop(b, szCommandLine, & i, szVal, false);
\r
60 szCommandLineSend += b ? wxT('1') : wxT('0');
\r
64 return szCommandLineSend;
\r
67 wxString MakeCommandLineSend(const wxString & szCommandLine, TPI_SWITCHES * swInfo, const wxArrayString & asFiles, const wxString & szResponceFileName)
\r
70 wxString szCommandLineSend;
\r
71 for (size_t i = 0; i < szCommandLine.Len(); i++)
\r
73 if (szCommandLine[i] == wxT('%'))
\r
76 switch ((wxChar) szCommandLine[++i])
\r
80 szCommandLineSend += szCommandLine[i];
\r
83 switch ((wxChar) szCommandLine[++i])
\r
92 case wxT('0'): szCommandLineSend += swInfo->szArcName; break;
\r
93 case wxT('1'): szCommandLineSend += swInfo->fnDestinationDirectory.GetPathWithSep(); break;
\r
94 case wxT('2'): szCommandLineSend += szResponceFileName; break;
\r
96 for (size_t j = 0; j < asFiles.GetCount(); j++)
\r
98 szCommandLineSend += wxT("\"") + asFiles[j] + wxT("\" ");
\r
101 case wxT('4'): szCommandLineSend += wxString::Format(wxT("%d"), swInfo->nCompressLevel); break;
\r
102 case wxT('5'): szCommandLineSend += wxString::Format(wxT("%d"), swInfo->nRecoveryRecord); break;
\r
103 case wxT('6'): szCommandLineSend += swInfo->szComment; break;
\r
107 switch ((wxChar) szCommandLine[++i])
\r
118 case wxT('0'): szCommandLineSend += ProcessBool(swInfo->fStoreDirectoryPathes, szCommandLine, & i); break;
\r
119 case wxT('1'): szCommandLineSend += ProcessBool(swInfo->fMakeSFX, szCommandLine, & i); break;
\r
120 case wxT('2'): szCommandLineSend += ProcessBool(swInfo->fSolid, szCommandLine, & i); break;
\r
121 case wxT('3'): szCommandLineSend += ProcessBool(swInfo->fMMOptimize, szCommandLine, & i); break;
\r
122 case wxT('4'): szCommandLineSend += ProcessBool(swInfo->fEncryptHeader, szCommandLine, & i); break;
\r
123 case wxT('5'): szCommandLineSend += ProcessBool(! swInfo->szPassword.IsEmpty(), szCommandLine, & i, swInfo->szPassword); break;
\r
124 case wxT('6'): szCommandLineSend += ProcessBool(! swInfo->szKeyFile.IsEmpty(), szCommandLine, & i, swInfo->szKeyFile); break;
\r
125 case wxT('7'): szCommandLineSend += ProcessBool(swInfo->nSplitSize != 0, szCommandLine, & i, wxString::Format(wxString("%" wxLongLongFmtSpec "u"), swInfo->nSplitSize)); break;
\r
126 case wxT('8'): szCommandLineSend += ProcessBool(swInfo->fCompressHeader, szCommandLine, & i); break;
\r
133 szCommandLineSend += szCommandLine[i];
\r
137 return szCommandLineSend;
\r
140 wxString MakeResponceFile(const wxArrayString & asFiles, bool bQuote, bool bUnicode)
\r
143 wxString szFileName = wxFileName::CreateTempFileName(wxT("__listfile"), & fListFile), szBuffer;
\r
144 if (szFileName.IsEmpty())
\r
146 return wxEmptyString;
\r
150 if (asFiles.IsEmpty())
\r
152 szBuffer = wxT("*");
\r
156 for (size_t i = 0; i < asFiles.GetCount(); i++)
\r
158 szBuffer += bQuote ? (wxT("\"") + asFiles[i] + wxT("\"")) : asFiles[i];
\r
160 szBuffer += wxT("\r\n");
\r
162 szBuffer += wxT("\n");
\r
166 fListFile.Write(szBuffer, bUnicode ? (const wxMBConv&) wxMBConvUTF16LE() : (const wxMBConv&) wxMBConvUTF8());
\r
172 wxString MB2String(const char * sz)
\r
174 return wxString(sz, wxConvLibc);
\r
177 wxString UTF82String(const char * sz)
\r
179 wxString s = wxString(sz, wxConvUTF8);
\r
180 return s.IsEmpty() ? MB2String(sz) : s;
\r
183 wxString WC2String(const wchar_t * sz)
\r
185 return wxString(sz);
\r