• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            上一次熟悉了IO系統(tǒng)后, 寫個程序來練練手.

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

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

             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: }
            

            調(diào)試參數(shù):

            運行結(jié)果:


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久国产色av免费看| 热综合一本伊人久久精品| 麻豆一区二区99久久久久| 久久精品成人免费网站| 国内精品久久久久久不卡影院| 久久久这里有精品中文字幕| 亚洲欧洲日产国码无码久久99| 精品久久无码中文字幕| 久久99精品久久久久久野外| 久久精品国产亚洲av麻豆蜜芽| 亚洲国产精品人久久| 久久久一本精品99久久精品88| 51久久夜色精品国产| 久久人人爽人人人人爽AV| 99久久免费国产精品| 精品久久久无码人妻中文字幕豆芽 | 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产精品久久久久久久久| 精品久久久久久久国产潘金莲| 久久777国产线看观看精品| 久久亚洲AV无码精品色午夜麻豆| 国产精品99久久久久久人| 婷婷久久五月天| 久久久久国产精品麻豆AR影院| 国产精品美女久久久m| 亚洲中文字幕无码久久综合网 | 人妻精品久久久久中文字幕69| 91精品国产高清久久久久久国产嫩草 | 麻豆一区二区99久久久久| 久久婷婷色综合一区二区| 人妻系列无码专区久久五月天| 久久综合狠狠综合久久激情 | 久久综合丁香激情久久| 国产精品久久久久久久久免费| 青草国产精品久久久久久| 伊人久久大香线蕉综合影院首页| 亚洲国产精品无码久久九九| 一级a性色生活片久久无| 欧美大战日韩91综合一区婷婷久久青草| 久久99精品国产麻豆婷婷| 久久伊人五月天论坛|