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

            調試參數:

            運行結果:

            国产午夜免费高清久久影院| 婷婷久久综合九色综合九七| 一本一本久久A久久综合精品| 亚洲国产欧洲综合997久久| 国内精品久久久久| 99久久精品国产一区二区 | 2021少妇久久久久久久久久| 国产—久久香蕉国产线看观看| 久久久久精品国产亚洲AV无码| 97超级碰碰碰碰久久久久| 久久久久亚洲av无码专区导航| 色8激情欧美成人久久综合电| 亚洲va中文字幕无码久久| 亚洲国产二区三区久久| 久久狠狠爱亚洲综合影院| 久久黄视频| 天天影视色香欲综合久久| 久久夜色精品国产噜噜麻豆| 欧美丰满熟妇BBB久久久| 99久久精品国产毛片| 精品熟女少妇av免费久久| 国产精品久久久久久久久软件| 亚洲欧美成人久久综合中文网| 青草久久久国产线免观| 成人妇女免费播放久久久| 久久www免费人成看片| 久久久精品久久久久特色影视| 国产亚洲婷婷香蕉久久精品| 无码人妻久久一区二区三区免费| 久久精品亚洲欧美日韩久久| 2020最新久久久视精品爱| 久久精品国产99久久久| 久久99国产综合精品免费| 99久久国产综合精品麻豆| 国产成人精品白浆久久69| 久久精品国产亚洲AV大全| 亚洲综合熟女久久久30p| 久久夜色精品国产噜噜噜亚洲AV | 久久亚洲精品成人AV| 久久久久久午夜成人影院 | 久久久精品无码专区不卡|