デースケドガーソフトウェア part2 Copy Move Wrapper

part1 http://d.hatena.ne.jp/studiokingyo/20050215#p4
デースケドガー騒動があった頃に作っていたソフトをお蔵だし。
コンパイルには最新版のdKingyo Utility Toolkitが必要です。2005年8月29日現在はまだアップロードしていません。ごめんなさい。


/**
@mainpage Dacekeadgar filecopy


@section 概要
デースケドガーなファイルコピーコマンドラインツールです。
主に、コンパイルし終わったライブラリファイルを移動するときに使います。

@section 開発に使われてたライブラリ
<ul>
<li>dkutil_c
<li>dkutil (command line parser)
<li>dKingyo Utility Toolkit Helper Functions
</ul>

*/
#include <helper/console_app_frame.hpp>
#include <dkutil_c/dkc.h>


//#include <dkutil/filesystem/path_string.hpp>

#include <helper/pause.hpp>
#include <iostream>


namespace dkutil{
using namespace std;

class CDacekeadgarFileCopy : public IConsoleApplication
{
public:
CDacekeadgarFileCopy()
{
}
virtual ~CDacekeadgarFileCopy(){

}
typedef IConsoleApplication base_type;
typedef base_type::cmdline_iterator cmdline_iterator;

virtual bool usage()
{
cout << " usage: dacekeadgar_copy <switches> <(src)> <(dest)>" << endl;
cout << " <switches>" << endl;
cout << " -help view help" << endl;
cout << " -copy copy mode" << endl;
cout << " -move move mode" << endl;
//cout << " -fw force write" << endl;
cout << " -nosw security warning is not displayed" << endl;

return true;
}


virtual bool process()
{
using namespace std;
//状態変数
//1:copy 2:move
UINT mode = 1;
bool fw = false;
bool sec_print = true;
std::string src,dest;

//コマンドラインチェック
cmdline_iterator it = begin_cmdline();

for(;it != end_cmdline();it++)
{
if( (*it)==mine_path() )
continue;

if((*it)=="-copy"){
mode = 1;
}
else if((*it)=="-move"){
mode = 2;
}
else if((*it)=="-fw"){
fw = true;
}else if((*it)=="-nosw"){
sec_print = false;
}
else
{
if(src.empty())
{
src = (*it);
}
else if(dest.empty())
{
dest = (*it);
}
else
{
cout << "なんかコマンドライン長すぎなんですけど・・・○| ̄|_" << endl;
return false;
}
}
}

if(mode >= 3)
{
cout << "moveかcopyかはっきりするべし" << endl;
return false;
}
if(sec_print){
cout << "このプログラムは簡単なcopyとmoveのラッパーのためサブシェル( system() )を使用しています" << endl;
cout << "ネットワークにつながっていない安全な環境でお使いください。" << endl;
cout << "詳しくは以下のURL先を見てください。" << endl;
cout << "http://www.ipa.go.jp/security/awareness/vendor/programming/b06_04_main.html" << endl;
}

//コピー処理

return copy_process(src,dest,mode,fw);
}

bool copy_process(parm_string src,parm_string dest,UINT mode,bool fw)
{

std::string cmd;
switch(mode){
case 1:

cmd = "COPY /B ";
cmd += src;
cmd += " /B ";
cmd += dest;
cmd +=" /B /V ";
break;
case 2:
cmd = "MOVE ";
cmd += src;
cmd += " ";
cmd += dest;
break;
case 0:
default:
usage();
return false;
}
//http://www.ipa.go.jp/security/awareness/vendor/programming/b06_04_main.html
int r = system(cmd.c_str());
if(0==r) return true;

return false;
}

};



}//end of namespace



int main(int argc,const char *argv[] )
{
using namespace std;
dkcCheckMemoryLeak(TRUE);
if(argc <= 1){
goto End;
}
{

dkutil::CDacekeadgarFileCopy a;
a.reset(argc,argv);

a.auto_process();
}
End:
dkutil::ConsoleDebugPause();
return 0;
}