[PR]

水無瀬の部屋 > Programming > sample > sendsend > sendsend.cpp
最終更新日: 2007/10/23

   1: //*********************************************************
   2: // プロジェクト: Send to 'SendTo'
   3: //   ファイル名: sendsend.cpp
   4: //*********************************************************
   5: #include "sendsend.h"
   6: #include "custom.h"
   7: #include "select.h"
   8: #include "sendto.h"
   9: #include "pathlist.h"
  10: #include "cmdline.h"
  11: 
  12: 
  13: //---------------------------------------------------------
  14: // テスト関数 の 宣言
  15: //---------------------------------------------------------
  16: DECLARE_TESTPROC( test_ApplicationMainProc );
  17: 
  18: 
  19: //---------------------------------------------------------
  20: // マクロ定数 の 定義
  21: //---------------------------------------------------------
  22: //
  23: #define MUTEX_INSTALLDLG  ( "sendsend.InstallDlg" )
  24: //
  25: #define MODE_SENDSEND  ( 1 )  // 
  26: #define MODE_INSTALL   ( 2 )  // インストール
  27: 
  28: 
  29: //---------------------------------------------------------
  30: // ファイルスコープ関数 の 宣言
  31: //---------------------------------------------------------
  32: static int GetApplicationMode( int argc, char **argv );
  33: static int CommandLineApplicationMainProc( HINSTANCE hInstance, int argc, char **argv );
  34: static int ApplicationInstallMainProc( HINSTANCE hInstance, int argc, char **argv );
  35: 
  36: 
  37: //*********************************************************
  38: // ApplicationMainProc
  39: //*********************************************************
  40: int
  41: ApplicationMainProc
  42: 	(
  43: 		HINSTANCE   hInstance,
  44: 		int         argc,
  45: 		char      **argv
  46: 	)
  47: {
  48: 	CALLONCE_TESTPROC( test_ApplicationMainProc ); // [テスト]
  49: 
  50: 	// パラメタの仮定
  51: 	ASSERT( IsValidInstanceHandle( hInstance ) );
  52: 	ASSERT( IsValidArgcArgv( argc, argv ) );
  53: 	ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
  54: 
  55: 	//
  56: 	const int mode = GetApplicationMode( argc, argv );
  57: 	switch( mode )
  58: 	{
  59: 		default:            return EXIT_FAILURE;
  60: 		case MODE_SENDSEND: return CommandLineApplicationMainProc( hInstance, argc, argv );
  61: 		case MODE_INSTALL:  return ApplicationInstallMainProc( hInstance, argc, argv );
  62: 	}
  63: }//ApplicationMainProc
  64: 
  65: 
  66: //******************************************************************************************************************
  67: // private
  68: //******************************************************************************************************************
  69: //*********************************************************
  70: // GetApplicationMode
  71: //*********************************************************
  72: static
  73: int
  74: GetApplicationMode
  75: 	(
  76: 		int    argc,
  77: 		char **argv
  78: 	)
  79: {
  80: 	// パラメタの仮定
  81: 	ASSERT( IsValidArgcArgv( argc, argv ) );
  82: 	ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
  83: 
  84: 	// 引数が無ければ 設定 モード
  85: 	return (1 < argc) ? MODE_SENDSEND : MODE_INSTALL ;
  86: }//GetApplicationMode
  87: 
  88: 
  89: //******************************************************************************************************************
  90: // private - MODE_INSTALL
  91: //******************************************************************************************************************
  92: //*********************************************************
  93: // ApplicationInstallMainProc
  94: //*********************************************************
  95: static
  96: int
  97: ApplicationInstallMainProc
  98: 	(
  99: 		HINSTANCE   hInstance,
 100: 		int         argc,
 101: 		char      **argv
 102: 	)
 103: {
 104: 	// パラメタの仮定
 105: 	ASSERT( IsValidInstanceHandle( hInstance ) );
 106: 	ASSERT( IsValidArgcArgv( argc, argv ) );
 107: 	ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
 108: 
 109: 	//
 110: 	HANDLE hMutex = CreateMutexOnce( MUTEX_INSTALLDLG );
 111: 	if ( hMutex )
 112: 	{
 113: 		CustomBox( HWND_DESKTOP );
 114: 		VERIFY( CloseHandle( hMutex ) );
 115: 	}
 116: 
 117: 	return EXIT_SUCCESS;
 118: }//ApplicationInstallMainProc
 119: 
 120: 
 121: //******************************************************************************************************************
 122: // private - MODE_SENDSEND
 123: //******************************************************************************************************************
 124: static bool send_target( ptrlist_t *folder, int argc, char **argv, bool bNoExt );
 125: 
 126: 
 127: //*********************************************************
 128: // CommandLineApplicationMainProc
 129: //*********************************************************
 130: static
 131: int
 132: CommandLineApplicationMainProc
 133: 	(
 134: 		HINSTANCE   hInstance,
 135: 		int         argc,
 136: 		char      **argv
 137: 	)
 138: {
 139: 	// パラメタの仮定
 140: 	ASSERT( IsValidInstanceHandle( hInstance ) );
 141: 	ASSERT( IsValidArgcArgv( argc, argv ) );
 142: 	ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
 143: 
 144: 	// 有効な引数が指定されていなければ
 145: 	// [関連づけ] ダイアログとして起動
 146: 	SENDPARAM_t param;
 147: 	if ( !ParseCmdLineOption( &param, argc, argv ) )
 148: 	{
 149: 		VERIFY( DestroyPathList( param.folder ) );
 150: 		return EXIT_SUCCESS; // 終了
 151: 	}
 152: 
 153: 	// ファイル名が指定されているが
 154: 	// 登録先が指定されていない場合
 155: 	if ( PtrList_IsEmpty( param.folder )
 156: 		&& (0 == param.flags)
 157: 		&& !SelectBox( HWND_DESKTOP, &param ) )
 158: 	{
 159: 		VERIFY( DestroyPathList( param.folder ) );
 160: 		return EXIT_SUCCESS; // キャンセルされた
 161: 	}
 162: 
 163: 	//
 164: #pragma memo( "ParseCmdLineOption() 内部に移動すべきでは?" )
 165: 	ASSERT( param.folder );
 166: 	PathList_AddSpecialFolderPath( param.folder, param.flags );
 167: 
 168: 	// ファイルを指定のフォルダに登録
 169: 	send_target( param.folder, argc, argv, param.bNoExt );
 170: 
 171: 	// フォルダを開く
 172: 	if ( param.bOpenFolder )
 173: 	{
 174: 		PathList_OpenFolder( param.folder );
 175: 	}
 176: 
 177: 	//
 178: 	VERIFY( DestroyPathList( param.folder ) );
 179: 
 180: 	return EXIT_SUCCESS;
 181: }//CommandLineApplicationMainProc
 182: 
 183: 
 184: //******************************************************************************************************************
 185: // private
 186: //******************************************************************************************************************
 187: //*********************************************************
 188: // send_target
 189: //*********************************************************
 190: static
 191: bool
 192: send_target
 193: 	(
 194: 		ptrlist_t  *folder,
 195: 		int         argc,
 196: 		char      **argv,
 197: 		bool        bNoExt
 198: 	)
 199: {
 200: 	// パラメタの仮定
 201: 	ASSERT( IsValidArgcArgv( argc, argv ) );
 202: 	ASSERT( IsPathMyself( argv[ 0 ] ) ); // 自分自身
 203: 	ASSERT( IsValidPtrListHandle( folder ) );
 204: 
 205: 	// ショートカットを作成する
 206: 	{for( int i = 1; i < argc; ++i )
 207: 	{
 208: 		ASSERT( IsValidStringPtr( argv[ i ] ) );
 209: 
 210: 		if ( IsPathExist( argv[ i ] ) )
 211: 		{
 212: 			const bool bTopdown = true;
 213: 			{for( ptritem_t *item = PtrList_GetBegin( folder, bTopdown );
 214: 				item; 
 215: 				item = PtrItem_GetNext( item, bTopdown ) )
 216: 			{
 217: 				const char *path = (char *)PtrItem_GetPtr( item );
 218: 				if ( path && IsPathDirectory( path ) )
 219: 				{
 220: 					SendToPath( argv[i], path, bNoExt );
 221: 				}
 222: 			}}
 223: 		}
 224: 	}}
 225: 
 226: 	return true;
 227: }//send_target
 228: 
 229: 
 230: //******************************************************************************************************************
 231: // TEST
 232: //******************************************************************************************************************
 233: 
 234: 
 235: #ifdef _DEBUG // デバッグ時のみ
 236: 
 237: 
 238: #include "mkcmdln.h"
 239: 
 240: 
 241: //*********************************************************
 242: // test_GetApplicationMode
 243: //*********************************************************
 244: DEFINE_TESTPROC( test_ApplicationMainProc )
 245: {
 246: 	//---------------------------------------------------------
 247: 	// 定数 の テスト
 248: 	//---------------------------------------------------------
 249: 
 250: 	// MUTEX_INSTALLDLG
 251: 	ASSERT( IsValidMutexName( MUTEX_INSTALLDLG ) );
 252: 
 253: 
 254: 	//---------------------------------------------------------
 255: 	// ファイルスコープ関数 の テスト
 256: 	//---------------------------------------------------------
 257: 
 258: 	// GetApplicationMode()
 259: 	{
 260: 		// MODE_INSTALL
 261: 		{
 262: 			char *argv[] = { "", null };
 263: 			argv[ 0 ] = __argv[ 0 ]; // 自分自身へのパス
 264: 			VERIFY( MODE_INSTALL == GetApplicationMode( numof(argv)-1, argv ) );
 265: 		}
 266: 
 267: 		// MODE_ATLNK
 268: 		{
 269: 			char *argv[] = { "", "", null };
 270: 			argv[ 0 ] = __argv[ 0 ]; // 自分自身へのパス
 271: 			VERIFY( MODE_SENDSEND == GetApplicationMode( numof(argv)-1, argv ) );
 272: 		}
 273: 	}
 274: 
 275: 
 276: 	//---------------------------------------------------------
 277: 	// 公開関数 の テスト
 278: 	//---------------------------------------------------------
 279: 	void *ptr = commandline_replace_param( "0 0", "-", "-" );
 280: 	free( ptr );
 281: 
 282: 
 283: }//test_GetApplicationMode
 284: 
 285: 
 286: #endif // #ifdef _DEBUG
 287: 
 288: 
 289: //** end **
 290: 

参照:


Google
ご意見・ご感想をお聞かせ下さい。匿名で送信できます。

 * 返信が必要な場合には postmaster@katsura-kotonoha.sakura.ne.jp へ直接メールしてください。

水無瀬の部屋 > sample > sendsend > sendsend.cpp

このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/sendsend/sendsend_cpp.shtml
>> Amazon.co.jp 『たまゆら童子』 へ
>> 楽天ブックス 『たまゆら童子』 へ