1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 2/// Name: Main wxBase App 3/// 4/// Purpose: aMule ed2k link creator 5/// 6/// Author: ThePolish <thepolish@vipmail.ru> 7/// 8/// Copyright (c) 2004-2011 ThePolish ( thepolish@vipmail.ru ) 9/// 10/// This program is free software; you can redistribute it and/or modify 11/// it under the terms of the GNU General Public License as published by 12/// the Free Software Foundation; either version 2 of the License, or 13/// (at your option) any later version. 14/// 15/// This program is distributed in the hope that it will be useful, 16/// but WITHOUT ANY WARRANTY; without even the implied warranty of 17/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18/// GNU General Public License for more details. 19/// 20/// You should have received a copy of the GNU General Public License 21/// along with this program; if not, write to the 22/// Free Software Foundation, Inc., 23/// 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 24////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 25 26 27#ifdef __BORLANDC__ 28 #pragma hdrstop 29#endif 30 31// For all others, include the necessary headers 32#ifndef WX_PRECOMP 33 #include "wx/wx.h" 34#endif 35 36#ifdef HAVE_CONFIG_H 37#include "config.h" // Needed for PACKAGE 38#else 39#define PACKAGE "amule" 40#endif 41 42 43#include "alcc.h" 44#include "ed2khash.h" 45 46// Application implementation 47IMPLEMENT_APP (alcc) 48 49/// Running Alcc 50int alcc::OnRun () 51{ 52 // Used to tell alcc to use aMule catalog 53 m_locale.Init(); 54 m_locale.AddCatalog(wxT(PACKAGE)); 55 56 wxLog::DontCreateOnDemand(); 57 wxLogStderr * stderrLog = new wxLogStderr; 58 wxLogStderr * stdoutLog = new wxLogStderr(stdout); 59 delete wxLog::SetActiveTarget(stderrLog); // Log on Stderr 60#if wxCHECK_VERSION(2, 9, 0) 61 wxLog::SetTimestamp(""); // Disable timestamp on messages 62#else 63 wxLog::SetTimestamp(NULL); // Disable timestamp on messages 64#endif 65 66 Ed2kHash hash; 67 size_t i; 68 for (i=0;i<(m_filesToHash.GetCount());++i) 69 { 70 if (wxFileExists(m_filesToHash[i])) 71 { 72 if (m_flagVerbose) 73 { 74 wxLogMessage(_("Processing file number %u: %s"),i+1,m_filesToHash[i].c_str()); 75 76 if (m_flagPartHashes) 77 { 78 wxLogMessage(_("You have asked for part hashes (Only used for files > 9.5 MB)")); 79 } 80 } 81 82 if (hash.SetED2KHashFromFile(m_filesToHash[i], NULL)) 83 { 84 // Print the link to stdout 85 wxLog::SetActiveTarget(stdoutLog); 86 wxLogMessage(wxT("%s"), hash.GetED2KLink(m_flagPartHashes).c_str()); 87 // Everything else goes to stderr 88 wxLog::SetActiveTarget(stderrLog); 89 } 90 } 91 else 92 { 93 if (m_flagVerbose) 94 { 95 wxLogMessage(_("%s ---> Non existant file !\n"),m_filesToHash[i].c_str()); 96 } 97 } 98 } 99 return 0; 100} 101 102// On exit 103int 104alcc::OnExit() 105{ 106 delete wxLog::SetActiveTarget(NULL); 107 return 0; 108} 109 110/// Parse command line 111void alcc::OnInitCmdLine(wxCmdLineParser& cmdline) 112{ 113 cmdline.AddSwitch(wxT("h"), wxT("help"), wxT("show this help message"), wxCMD_LINE_OPTION_HELP); 114 cmdline.AddSwitch(wxT("v"), wxT("verbose"), wxT("be verbose")); 115 cmdline.AddSwitch(wxT("p"), wxT("parthashes"), wxT("add part-hashes to ed2k link")); 116 cmdline.AddParam(wxT("input files"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_MULTIPLE); 117} 118 119/// Command line preocessing 120bool alcc::OnCmdLineParsed(wxCmdLineParser& cmdline) 121{ 122 123 wxFileName filename; 124 size_t i; 125 126 m_flagVerbose = cmdline.Found(wxT("v")); 127 m_flagPartHashes = cmdline.Found(wxT("p")); 128 129 m_filesToHash.Clear(); 130 for (i = 0; i < cmdline.GetParamCount(); ++i) 131 { 132 filename.Assign(cmdline.GetParam(i)); 133 m_filesToHash.Add(filename.GetFullPath()); 134 } 135 m_filesToHash.Shrink(); 136 137 return true; 138} 139// File_checked_for_headers 140