From 36d2a2b01a6b1be673a240b69961f91ef6578687 Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 3 Jun 2015 16:05:15 +0000 Subject: [PATCH] git-svn-id: svn://10.65.10.50/branches/R_10_00@23106 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- fd/fd0.cpp | 132 ++++++++++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 72 deletions(-) diff --git a/fd/fd0.cpp b/fd/fd0.cpp index bf0248768..161e9f38c 100644 --- a/fd/fd0.cpp +++ b/fd/fd0.cpp @@ -11,7 +11,6 @@ #include #include #include -#include /////////////////////////////////////////////////////////// // Utility @@ -261,6 +260,7 @@ class TEsigner protected: bool TestFile(const wxString& strFile) const; + void Backup(const wxString& strInput, const wxString& strBackup) const; public: bool Init(bool on); @@ -389,6 +389,26 @@ bool TEsigner::Init(bool bLoad) return ok; } +void TEsigner::Backup(const wxString& strInput, const wxString& strBackup) const +{ + int mode = 3; + if (strBackup.CmpNoCase("Cestino") == 0 || strBackup.CmpNoCase("NULL") == 0 || + strBackup.CmpNoCase("Basket") == 0 || strBackup.CmpNoCase("Trash") == 0) + mode = 1; + else + wxFileName::Mkdir(strBackup, 0777, wxPATH_MKDIR_FULL); + + if (mode & 2) + { + wxFileName fout = strInput; + fout.SetPath(strBackup); + if (!wxCopyFile(strInput, fout.GetFullPath())) + mode = 0; + } + if (mode & 1) + ::wxRemoveFile(strInput); +} + bool TEsigner::Sign(const wxString& strInput, wxString& strOutput, const wxString& strBackup, int mode) { if (m_strPin.Len() < 2) @@ -401,9 +421,9 @@ bool TEsigner::Sign(const wxString& strInput, wxString& strOutput, const wxStrin wxString strOperation = "S"; if (m_bMark && !m_strTSAurl.IsEmpty()) // Firma con marcatura temporale - strOperation += "+T"; else - if (wxDirExists(strInput)) - strOperation += "+D"; + strOperation += "+T"; + + const bool bIsDir = wxDirExists(strInput); wxString strMethod; if (!m_strDLL.IsEmpty()) // Token @@ -447,7 +467,7 @@ bool TEsigner::Sign(const wxString& strInput, wxString& strOutput, const wxStrin TSA_coding = (char*)(const char*)m_strTSAcoding; } - if (strOperation.Find("+D") > 0) + if (bIsDir) { if (strOutput.IsEmpty()) output = input; @@ -462,76 +482,43 @@ bool TEsigner::Sign(const wxString& strInput, wxString& strOutput, const wxStrin output = (char*)(const char*)strOutput; } - int res = _SignPDF(operation, method, + int res = 0; + + if (bIsDir) + { + wxArrayString files; + const size_t xmls = wxDir::GetAllFiles(strInput, &files, "*.xml", wxDIR_FILES); + + + wxProgressDialog pd(APPFULLNAME, "Firma dei file in " + strInput); + for (size_t i = 0; i < xmls && res == 0; i++) + { + input = (char*)(const char*)files[i]; + wxFileName fnOutput = files[i]; + fnOutput.SetPath(strOutput); + fnOutput.SetExt(""); + output = (char*)(const char*)fnOutput.GetFullPath(); + res = _SignPDF(operation, method, input, output, NULL, ext, cer, pem, pfx, dll, pin, NULL, idx, TSA_url, TSA_user, TSA_pwd, TSA_policy, TSA_coding, NULL); - - if (strOperation.Find("+D") > 0) // +D only + if (res == 0) + { + if (!strBackup.IsEmpty()) + Backup(files[i], strBackup); + if (!pd.Update(i+1)) + break; + } + } + } + else { - wxArrayString files; - const size_t results = wxDir::GetAllFiles(output, &files, "*.result", wxDIR_FILES); - if (results > 0) - { - res = 0; - for (size_t i = 0; i < results && res == 0; i++) - { - const wxXmlDocument xml(files[i]); - const wxXmlNode* pRoot = xml.GetRoot(); - if (pRoot != NULL) - { - const wxXmlNode* pImpronta = pRoot->GetChildren(); - if (pImpronta != NULL) - res = wxAtoi(pImpronta->GetAttribute(wxT("ESITO"), wxT("-1"))); - } - } - } - - if (mode == 2) - { - if (strBackup.IsEmpty()) - mode = 0; - else - { - if (strBackup.CmpNoCase("Cestino") == 0 || strBackup.CmpNoCase("NULL") == 0 || - strBackup.CmpNoCase("Basket") == 0 || strBackup.CmpNoCase("Trash") == 0) - mode = 1; - } - if (mode == 2) - wxFileName::Mkdir(strBackup, 0777, wxPATH_MKDIR_FULL); - } - - if (res == 0 && mode != 0) - { - files.Clear(); - const size_t n = wxDir::GetAllFiles(input, &files, "*.*", wxDIR_FILES); - if (n > 0) - { - wxString msg; - if (mode == 1) - msg << "Eliminazione file in " << strInput; - else - { - wxFileName::Mkdir(strBackup, 0777, wxPATH_MKDIR_FULL); - msg << "Copia file in " << strBackup; - } - - wxProgressDialog pd(APPFULLNAME, msg, n); - for (size_t i = 0; i < n; i++) - { - if (!pd.Update(i+1)) - break; - wxFileName fout = files[i]; - fout.SetPath(strBackup); - bool bRemove = true; - if (mode == 2) - bRemove = wxCopyFile(files[i], fout.GetFullPath()); - if (bRemove) - wxRemoveFile(files[i]); - } - } - } - + res = _SignPDF(operation, method, + input, output, NULL, ext, + cer, pem, pfx, dll, pin, NULL, idx, + TSA_url, TSA_user, TSA_pwd, TSA_policy, TSA_coding, NULL); + if (res == 0 && !strBackup.IsEmpty()) + Backup(strInput, strBackup); } if (res == 0) @@ -607,9 +594,10 @@ bool TMainDlg::TransferDataToWindow() { SetProperty("DIR_IN", IniGetString(m_strUser, "DIR_IN")); SetProperty("DIR_OUT", IniGetString(m_strUser, "DIR_OUT")); - + /* SetProperty("FILE_IN", IniGetString(m_strUser, "FILE_IN")); SetProperty("FILE_OUT", IniGetString(m_strUser, "FILE_OUT")); + */ } return ok; }