• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 94, comments - 250, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            上一次熟悉了IO系統后, 寫個程序來練練手.

            正好這次看到App命名空間, 正好熟悉一下ConsoleApplication的用法. 因為Nebula3內置了ZipFileSystem, 但不支持壓縮, 只支持解壓縮, 就試著寫了一個命令行的unzip.exe, 算是對之前所學的一個總結.

            沒想解壓縮就像拷貝文件一樣簡單! 因為當zip文件掛載到IO系統后, 可以像本地文件一樣使用其中的文件, 呵呵.

             1: /********************************************************************
             2: 	created:	2008/07/08
             3: 	created:	8:7:2008   16:15
             4: 	filename: 	UnZip.cpp
             5: 	author:		xoyojank
             6: 	
             7: 	purpose:	zip file extract test
             8: *********************************************************************/
             9: 
            10: #include "stdneb.h"
            11: #include "UnZipApp.h"
            12: 
            13: using namespace Util;
            14: 
            15: //------------------------------------------------------------------------------
            16: /**
            17: */
            18: void __cdecl
            19: main(int argc, const char** argv)
            20: {
            21: 	CmdLineArgs args(argc, argv);
            22: 	UnZipApp app;
            23: 	app.SetCompanyName("Xoyojank");
            24: 	app.SetAppName("UnZip");
            25: 	app.SetCmdLineArgs(args);
            26: 	if (app.Open())
            27: 	{
            28: 		app.Run();
            29: 		app.Close();
            30: 	}
            31: 	system("pause");
            32: 	app.Exit();
            33: }
            
             1: /********************************************************************
             2: 	created:	2008/07/08
             3: 	created:	8:7:2008   16:16
             4: 	filename: 	UnZipApp.h
             5: 	author:		xoyojank
             6: 	
             7: 	purpose:	UnZip Application
             8: *********************************************************************/
             9: #pragma once
            10: #include "stdneb.h"
            11: #include "app/consoleapplication.h"
            12: 
            13: class UnZipApp : public App::ConsoleApplication
            14: {
            15: public:
            16: 	UnZipApp(void);
            17: 
            18: 	/// open the application
            19: 	virtual bool Open();
            20: 	/// run the application, return when user wants to exit
            21: 	virtual void Run();
            22: 
            23: private:
            24: 	/// a recursion method to unzip the files under "dir"
            25: 	void UnZipDir(Util::String& dir);
            26: private:
            27: 	Util::String zipFileName;
            28: 	Util::String sourcePath;
            29: 	Util::String targetPath;
            30: };
            
             1: /********************************************************************
             2: 	created:	2008/07/08
             3: 	created:	8:7:2008   16:19
             4: 	filename: 	UnZipApp.cpp
             5: 	author:		xoyojank
             6: 	
             7: 	purpose:	UnZip Application
             8: *********************************************************************/
             9: #include "UnZipApp.h"
            10: 
            11: 
            12: UnZipApp::UnZipApp(void)
            13: {
            14: }
            15: 
            16: bool UnZipApp::Open()
            17: {
            18: 	if (ConsoleApplication::Open())
            19: 	{
            20: 		// help info
            21: 		if (this->args.HasArg("-help"))
            22: 		{
            23: 			n_printf("-file: the .zip file to unzip.\n");
            24: 			n_printf("-path: where are the files unzip to, if this args is omitted, the file will be unzip into current directory.\n");
            25: 			return false;
            26: 		}
            27: 
            28: 		Util::String zipFile;
            29: 		zipFile = this->args.GetString("-file");
            30: 		// current .exe directory
            31: 		this->sourcePath = Util::String("bin:") + zipFile;
            32: 		bool fileValid = this->ioServer->MountZipArchive(this->sourcePath);
            33: 		if (!fileValid)
            34: 		{
            35: 			// absolute path
            36: 			this->sourcePath = Util::String("file:///") + zipFile;
            37: 			fileValid = this->ioServer->MountZipArchive(this->sourcePath);
            38: 			if (!fileValid)
            39: 			{
            40: 				n_error("Cannot open zip file.\n");
            41: 				return false;
            42: 			}
            43: 		}
            44: 		this->zipFileName = zipFile.ExtractFileName();
            45: 		this->zipFileName.StripFileExtension();
            46: 		this->sourcePath = this->sourcePath.ExtractDirName() + "/";
            47: 
            48: 		// target directory
            49: 		this->targetPath = this->args.GetString("-path");
            50: 		if (this->targetPath.Length() <= 1 || this->targetPath[1] != ':')
            51: 		{// relative path
            52: 			this->targetPath = Util::String("bin:") + this->targetPath;
            53: 		}
            54: 		else
            55: 		{// absolute path
            56: 			this->targetPath = Util::String("file:///") + this->targetPath;
            57: 		}
            58: 		this->targetPath += "/";
            59: 		if (this->sourcePath == this->targetPath)
            60: 		{
            61: 			n_printf("the source diretory cannot be the same with the destination!");
            62: 			return false;
            63: 		}
            64: 		return true;
            65: 	}
            66: 	return false;
            67: }
            68: 
            69: void UnZipApp::Run()
            70: {
            71: 	UnZipDir(this->zipFileName);
            72: }
            73: 
            74: void UnZipApp::UnZipDir( Util::String& dir )
            75: {
            76: 	// create a new directory
            77: 	this->ioServer->CreateDirectory(this->targetPath + dir);
            78: 	// unzip the files in this directory
            79: 	Util::Array<Util::String> listFile = this->ioServer->ListFiles(this->sourcePath + dir, "*");
            80: 	for (IndexT i = 0; i < listFile.Size(); i++)
            81: 	{
            82: 		Util::String curFile = this->targetPath + dir + "/" + listFile[i];
            83: 		this->ioServer->CopyFile(this->sourcePath + dir + "/" + listFile[i], curFile);
            84: 		n_printf("%s\n", curFile.AsCharPtr());
            85: 	}
            86: 	// unzip the sub directories
            87: 	Util::Array<Util::String> listDir = this->ioServer->ListDirectories(this->sourcePath + dir, "*");
            88: 	for (IndexT i = 0; i < listDir.Size(); i++)
            89: 	{
            90: 		Util::String curDir = dir + "/" + listDir[i];
            91: 		n_printf("%s\n", (this->targetPath + curDir).AsCharPtr());
            92: 		UnZipDir(curDir);
            93: 	}
            94: }
            

            調試參數:

            運行結果:

            婷婷久久综合| 久久综合给合综合久久| 中文无码久久精品| 久久久无码精品亚洲日韩京东传媒 | 久久久久久午夜成人影院| 99精品国产在热久久无毒不卡 | 久久香综合精品久久伊人| 久久人人爽爽爽人久久久| 91精品国产综合久久香蕉| 久久人人爽人人人人爽AV| 999久久久国产精品| 一本久久a久久精品亚洲| 狠狠人妻久久久久久综合| 奇米综合四色77777久久| 女同久久| 99久久国产亚洲高清观看2024 | 色综合久久88色综合天天 | 国产精品一久久香蕉产线看| 色播久久人人爽人人爽人人片AV| 一级做a爰片久久毛片人呢| 日产精品久久久久久久性色| 欧美亚洲国产精品久久久久| 国产真实乱对白精彩久久| 狠狠色丁香婷综合久久| 国产亚洲色婷婷久久99精品| 精品伊人久久大线蕉色首页| 人妻无码久久精品| 91精品久久久久久无码| 99久久精品免费看国产一区二区三区 | 久久亚洲AV无码西西人体| 久久最近最新中文字幕大全| 亚洲av成人无码久久精品| 精品国产99久久久久久麻豆| 亚洲国产天堂久久综合| 欧美精品丝袜久久久中文字幕| 韩国三级中文字幕hd久久精品 | 久久精品国产亚洲精品| 久久久久国产成人精品亚洲午夜| 国产精品美女久久久久av爽| 狠狠色丁香婷婷综合久久来来去| 国产ww久久久久久久久久|