LboxUnzip

  コンストラクタ



UNZIP32.DLL と ZIP32J.DLL と ZIP32.DLL をインストールする必要があります

事前定義
  
#define FNAME_MAX32		512
typedef	HGLOBAL	HARC;
typedef struct {
	DWORD 			dwOriginalSize;
 	DWORD 			dwCompressedSize;
	DWORD			dwCRC;
	UINT			uFlag;
	UINT			uOSType;	
	WORD			wRatio;
	WORD			wDate;
	WORD 			wTime;
	char			szFileName[FNAME_MAX32 + 1];
	char			dummy1[3];
	char			szAttribute[8];
	char			szMode[8];
}	INDIVIDUALINFO, *LPINDIVIDUALINFO;

typedef HARC (WINAPI *LPFUNC_OPEN_ARC)
(const HWND _hwnd, LPCSTR _szFileName,const DWORD _dwMode);
typedef int (WINAPI *LPFUNC_CLOSE_ARC)
(HARC _harc);
typedef int (WINAPI *LPFUNC_FIND_FIRST)
(HARC _harc, LPCSTR _szWildName,INDIVIDUALINFO FAR *lpSubInfo);
typedef int (WINAPI *LPFUNC_FIND_NEXT)
(HARC _harc,INDIVIDUALINFO FAR *_lpSubInfo);

typedef int (WINAPI *LPFUNC_UNLHA)
(const HWND _hwnd,LPCSTR _szCmdLine,LPSTR _szOutput,const DWORD _dwSize);
typedef int (WINAPI *LPFUNC_UNZIP)
(const HWND _hwnd,LPCSTR _szCmdLine,LPSTR _szOutput,const DWORD _dwSize);
typedef int (WINAPI *LPFUNC_ZIP)
(const HWND _hwnd,LPCSTR _szCmdLine,LPSTR _szOutput,const DWORD _dwSize);
  

クラス定義
  
class LboxUnzip  
{
public:
	int MeltAll( int nType );
	BOOL CheckDll( void );
	int MeltPathRow( LboxListview *Lview, int nTargetRow, LboxString *LDir );
	int MeltPathRow( LboxListview *Lview, int nTargetRow, LPTSTR lpDir );
	int MeltDirectRow( LboxListview *Lview, int nTargetRow, LboxString *LDir );
	int MeltDirectRow( LboxListview *Lview, int nTargetRow, LPTSTR lpDir );
	int MeltDirect( LboxListview *Lview, LboxString *LDir );
	int MeltDirect( LboxListview *Lview, LPTSTR lpDir );
	int MeltPath( LboxListview *Lview, LboxString *LDir );
	int MeltPath( LboxListview *Lview, LPTSTR lpDir );
	int Zip( LboxString *LCmdLine );
	int Zip(LPTSTR szCmdLine,LPTSTR szOutput,const DWORD dwSize);
	int Melt( LboxListview *Lview, LboxString *LDir );
	int Melt( LboxListview *Lview, LPTSTR lpDir );
	int Delete( LboxListview *Lview );
	int Freeze( HDROP hDrop );
	int Freeze( LboxString *LPath );
	int Freeze( LPTSTR lpPath );
	int Unzip( LboxString *LCmdLine );
	int Unzip(LPTSTR szCmdLine,LPTSTR szOutput,const DWORD dwSize);
	BOOL Enum( LboxListview *Lview, LPTSTR szWildName );
	BOOL Enum( LboxListview *Lview, LboxString *LWildName );
	void CloseArchive( void );
	BOOL OpenArchive( void );
	BOOL OpenArchive( LboxString *LFileName );
	BOOL OpenArchive( LPTSTR szFileName );
	void Initialize2( void );
	void Initialize( void );

	LboxUnzip( HWND hOwner );
	LboxUnzip();
	virtual ~LboxUnzip();

	LPFUNC_UNZIP UnzipAction;
	LPFUNC_ZIP ZipAction;
	LPFUNC_FIND_NEXT UnzipFindNext;
	LPFUNC_FIND_FIRST UnzipFindFirst;
	LPFUNC_CLOSE_ARC UnzipCloseArchive;
	LPFUNC_OPEN_ARC UnzipOpenArchive;
	HINSTANCE	lib;
	HINSTANCE	lib2;
	HARC hArc;
	HWND hOwner;
	DWORD Mode;

	LboxString TargetPath;
	LboxString Output;
	LboxString Command;
	LboxString ErrMessage;
};
  

  
// *********************************************************
// コンストラクタ
// *********************************************************
LboxUnzip::LboxUnzip()
{
	this->ErrMessage.SetChar( 0, 0 );
	this->hArc = NULL;
	this->hOwner = NULL;
	this->Mode = M_REGARDLESS_INIT_FILE;
	this->Output.Resize( MAX_PATH );
	this->lib = NULL;
	this->lib2 = NULL;
	this->Initialize();
	this->Initialize2();
}
LboxUnzip::LboxUnzip( HWND hOwner )
{
	this->ErrMessage.SetChar( 0, 0 );
	this->hArc = NULL;
	this->hOwner = hOwner;
	this->Mode = M_REGARDLESS_INIT_FILE;
	this->Output.Resize( MAX_PATH );
	this->lib = NULL;
	this->lib2 = NULL;
	this->Initialize();
	this->Initialize2();
}

// *********************************************************
// デストラクタ
// *********************************************************
LboxUnzip::~LboxUnzip()
{
	if ( this->hArc != NULL ) {
		UnzipCloseArchive( this->hArc );
	}
	if ( this->lib != NULL ) {
		FreeLibrary( this->lib ); 
	}
	if ( this->lib2 != NULL ) {
		FreeLibrary( this->lib2 ); 
	}

}

// *********************************************************
// 初期化
// 戻り値 : 無し
// *********************************************************
void LboxUnzip::Initialize( void )
{
	if ( this->lib != NULL ) {
		return;
	}

	this->lib = LoadLibrary( "UNZIP32.DLL" );
	if ( this->lib == NULL ) {
		return;
	}

	this->UnzipOpenArchive =
		(LPFUNC_OPEN_ARC)GetProcAddress(
			this->lib, "UnZipOpenArchive" 
		);

	this->UnzipCloseArchive =
		(LPFUNC_CLOSE_ARC)GetProcAddress(
			this->lib, "UnZipCloseArchive" 
		);

	this->UnzipFindFirst =
		(LPFUNC_FIND_FIRST)GetProcAddress(
			this->lib, "UnZipFindFirst" 
		);

	this->UnzipFindNext =
		(LPFUNC_FIND_NEXT)GetProcAddress(
			this->lib, "UnZipFindNext" 
		);

	this->UnzipAction =
		(LPFUNC_UNZIP)GetProcAddress(
			this->lib, "UnZip" 
		);
}

// *********************************************************
// 初期化2
// 戻り値 : 無し
// *********************************************************
void LboxUnzip::Initialize2( void )
{
	if ( this->lib2 != NULL ) {
		return;
	}

	this->lib2 = LoadLibrary( "ZIP32J.DLL" );
	if ( this->lib2 == NULL ) {
		return;
	}

	this->ZipAction =
		(LPFUNC_ZIP)GetProcAddress(
			this->lib2, "Zip" 
		);
}

  



  OpenArchive



  
// *********************************************************
// アーカイブ オープン
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxUnzip::OpenArchive( void )
{
	return LboxUnzip::OpenArchive(
		&(this->TargetPath)
	);
}
BOOL LboxUnzip::OpenArchive( LboxString *LFileName )
{
	return LboxUnzip::OpenArchive(
		LFileName->szLboxString
	);
}
BOOL LboxUnzip::OpenArchive( LPTSTR szFileName )
{
	if ( *szFileName == 0x00 ) {
		this->ErrMessage.operator = (
			"書庫が指定されていません"
		);
		return false;
	}

	if ( LboxUnzip::lib == NULL ) {
		this->ErrMessage.operator = (
			"Unzip32.dll がインストールされていません"
		);
		return false;;
	}

	if ( LboxUnzip::hArc != NULL ) {
		LboxUnzip::CloseArchive( );
	}

	LboxUnzip::hArc = UnzipOpenArchive(
		LboxUnzip::hOwner,
		szFileName,
		LboxUnzip::Mode
	);
	if ( LboxUnzip::hArc == NULL ) {
		this->ErrMessage.operator = (
			"書庫を開く事ができませんでした"
		);
		return false;
	}

	this->TargetPath.operator = (szFileName);

	return true;
}
  



  CloseArchive

  
// *********************************************************
// アーカイブ クローズ
// 戻り値 : 無し
// *********************************************************
void LboxUnzip::CloseArchive( void )
{
	if ( LboxUnzip::lib == NULL ) {
		return;
	}
	if ( LboxUnzip::hArc == NULL ) {
		return;
	}

	UnzipCloseArchive( LboxUnzip::hArc );
	LboxUnzip::hArc = NULL;
}
  



  Enum

  
// *********************************************************
// リストビューに列挙
// 戻り値 : 成功 true, 失敗 false
// *********************************************************
BOOL LboxUnzip::Enum( LboxListview *Lview, LboxString *LWildName )
{
	return LboxUnzip::Enum(
		Lview,
		LWildName->szLboxString
	);
}
BOOL LboxUnzip::Enum( LboxListview *Lview, LPTSTR szWildName )
{
	if ( LboxUnzip::lib == NULL ) {
		this->ErrMessage.operator = (
			"Unzip32.dll がインストールされていません"
		);
		return false;
	}
	if ( LboxUnzip::hArc == NULL ) {
		this->ErrMessage.operator = (
			"書庫が開かれていません"
		);
		return false;
	}

	Lview->Initialize();
	Lview->AddColumn( LVCFMT_LEFT, 100, "" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "ファイル名" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "サイズ" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "圧縮サイズ" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "圧縮率" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "タイムスタンプ" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "属性" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "モード" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "ディレクトリ" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "フルパス" );
	Lview->AddColumn( LVCFMT_LEFT, 100, "ソート" );

	INDIVIDUALINFO ivinfo;
	int ret;

	ret = UnzipFindFirst(
		LboxUnzip::hArc,
		szWildName,
		&ivinfo
	);

	FILETIME ft;
	SYSTEMTIME st;
	int nCount;
	LboxString LString;

	while( ret == 0 ) {

		Lview->AddRow();

		LString.operator = (ivinfo.szFileName );
		LString.Replace( "/", "\\" );
		LString.StripPath( );
		LString.Replace( "\\", "/" );
		Lview->SetColumnText( 1, &LString );

		Lview->SetColumnPrintf( 2, "%d", ivinfo.dwOriginalSize );
		Lview->SetColumnPrintf( 3, "%d", ivinfo.dwCompressedSize );
		LString.Printf( "%d", ivinfo.wRatio );
		if ( LString.Length() > 0 ) {
			LString.Insert( ".", LString.Length()-1 );
			Lview->SetColumnText( 4, &LString );
		}

		DosDateTimeToFileTime( ivinfo.wDate, ivinfo.wTime, &ft );
		FileTimeToSystemTime( &ft, &st );
		Lview->SetColumnPrintf( 5,
			"%04d/%02d/%02d %02d:%02d:%02d",
			st.wYear,
			st.wMonth,
			st.wDay,
			st.wHour,
			st.wMinute,
			st.wSecond
		);
		Lview->SetColumnText( 6, ivinfo.szAttribute );
		Lview->SetColumnText( 7, ivinfo.szMode );

		LString.operator = (ivinfo.szFileName );
		LString.Replace( "/", "\\" );
		LString.RemoveFileSpec( );
		LString.Replace( "\\", "/" );
		Lview->SetColumnText( 8, &LString );
		if ( LString.operator == ( "" ) ) {
			LString.operator = (" ");
			LString.operator += (ivinfo.szFileName);
			Lview->SetColumnText( 10, &(LString) );
		}
		else {
			Lview->SetColumnText( 10, ivinfo.szFileName );
		}

		Lview->SetColumnText( 9, ivinfo.szFileName );

		ret = UnzipFindNext(
			LboxUnzip::hArc,
			&ivinfo
		);
	}

	Lview->Sort( 10, 0 );
	nCount = -1;
	while( Lview->FindNextRow( &nCount ) ) {
		Lview->SetColumnPrintf( 0, "%d", nCount+1 );
	}
	Lview->Fit();
	Lview->SetColumnWidth( 10, 0 );
	return true;
}
  



  Unzip

  
// *********************************************************
// 書庫解凍
// 戻り値 : 0 正常終了, それ以外はエラー
// *********************************************************
int LboxUnzip::Unzip( LboxString *LCmdLine )
{
	return LboxUnzip::Unzip(
		LCmdLine->szLboxString,
		this->Output.szLboxString,
		this->Output.nLboxString
	);
}
int LboxUnzip::Unzip(
LPTSTR szCmdLine, LPTSTR szOutput, const DWORD dwSize )
{
	if ( LboxUnzip::lib == NULL ) {
		this->ErrMessage.operator = (
			"Unzip32.dll がインストールされていません"
		);
		return 1;
	}

	int nRet;

	nRet = UnzipAction(
		LboxUnzip::hOwner,
		szCmdLine,
		szOutput,
		dwSize
	);

	if ( nRet != 0 ) {
		this->ErrMessage.operator = (
			"Unzip32.dll のエラーです"
		);
	}

	return nRet;
}
  



  Freeze

  
// *********************************************************
// ドラッグドロップされたファイルを書庫へ登録または更新
// 戻り値 : 0 正常終了, それ以外はエラー
// *********************************************************
int LboxUnzip::Freeze( HDROP hDrop )
{
	int i,nFiles;
	LboxString LFile;

	LFile.Resize( MAX_PATH );

	nFiles = DragQueryFile(
		hDrop,
		0xFFFFFFFF,
		LFile.szLboxString,
		LFile.nLboxString
	);

	this->Command.SetChar( 0, 0 );
	this->Command.operator = ( "-rD " );
	LFile.operator = (&(this->TargetPath));
	LFile.Enclose('"');
	this->Command.operator += ( &(LFile) );
	this->Command.operator += ( " " );
	for( i = 0; i < nFiles; i++ ) {
		if ( i != 0 ) {
			this->Command.operator += ( " " );
		}
		DragQueryFile(
			hDrop,
			i,
			LFile.szLboxString,
			LFile.nLboxString
		);
		LFile.RemoveFileSpec();
		LFile.AddBackslash();
		LFile.Enclose( '"' );
		this->Command.operator += ( &LFile );
		this->Command.operator += ( " " );

		DragQueryFile(
			hDrop,
			i,
			LFile.szLboxString,
			LFile.nLboxString
		);
		LFile.StripPath();
		LFile.Enclose( '"' );
		this->Command.operator += ( &LFile );
	}

	return LboxUnzip::Zip(
		&(this->Command)
	);

}
// *********************************************************
// 複数のファイルを書庫登録または更新
// 戻り値 : 0 正常終了, それ以外はエラー
// LPath は、フルパスファイルリスト ( タブ区切り )
// *********************************************************
int LboxUnzip::Freeze( LboxString *LPath )
{
	return LboxUnzip::Freeze(
		LPath->szLboxString
	);
}
int LboxUnzip::Freeze( LPTSTR lpPath )
{
	LboxToken LToken;
	LboxString LString;
	
	LToken.CreateToken( lpPath, "\t" );

	int i;

	this->Command.operator = ( "-rD " );
	LString.operator = (&(this->TargetPath));
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );
	for( i = 0; i < LToken.nCount; i++ ) {
		if ( i != 0 ) {
			this->Command.operator += ( " " );
		}
		LString.operator = (LToken.Token[i]);
		LString.RemoveFileSpec();
		LString.AddBackslash();
		LString.Enclose('"');
		this->Command.operator += (&LString);
		this->Command.operator += ( " " );
		LString.operator = (LToken.Token[i]);
		LString.StripPath();
		LString.Enclose('"');
		this->Command.operator += (&LString);
	}

	return LboxUnzip::Zip(
		&(this->Command)
	);
}
  



  Delete

  
// *********************************************************
// リストビューの選択されている行のファイルを削除
// 戻り値 : 0 正常終了, それ以外はエラー
// *********************************************************
int LboxUnzip::Delete( LboxListview *Lview )
{
	LboxString LString;
	int nRow;
	BOOL bFirst;

	this->Command.operator = ( "-d " );
	LString.operator = (&(this->TargetPath));
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );


	nRow = -1;
	bFirst = true;
	while( Lview->FindNextSelectedRow( &nRow ) ) {
		if ( bFirst ) {
			bFirst = false;
		}
		else {
			this->Command.operator += ( " " );
		}
		Lview->GetColumnText( 9, &LString );
		if ( LString.szLboxString[LString.Length()-1] == '/' ) {
			LString.operator += ("\*");
			LString.Enclose('"');
		}
		else {
			LString.Enclose('"');
		}
		this->Command.operator += ( &(LString) );
	}


	return LboxUnzip::Zip(
		&(this->Command)
	);
}
  



  Melt

  
// *********************************************************
// リストビューの選択されている行のファイルを解凍
// 戻り値 : 0 正常終了, それ以外はエラー
// 解凍先にパス情報を反映しない
// *********************************************************
int LboxUnzip::Melt( LboxListview *Lview, LboxString *LDir )
{
	return LboxUnzip::Melt(
		Lview,
		LDir->szLboxString
	);
}
int LboxUnzip::Melt( LboxListview *Lview, LPTSTR lpDir )
{
	LboxString LString;
	int nRow;
	BOOL bFirst;

	this->Command.operator = ( "-x " );
	LString.operator = (&(this->TargetPath));
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );
	LString.operator = (lpDir);
	LString.AddBackslash();
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );

	nRow = -1;
	bFirst = true;
	while( Lview->FindNextSelectedRow( &nRow ) ) {
		if ( bFirst ) {
			bFirst = false;
		}
		else {
			this->Command.operator += ( " " );
		}
		Lview->GetColumnText( 9, &LString );
		LString.Enclose('"');
		this->Command.operator += ( &(LString) );
	}

	return LboxUnzip::Unzip(
		&(this->Command)
	);
}
  



  Zip

  
// *********************************************************
// 書庫圧縮
// 戻り値 : 0 正常終了, それ以外はエラー
// *********************************************************
int LboxUnzip::Zip( LboxString *LCmdLine )
{
	return LboxUnzip::Zip(
		LCmdLine->szLboxString,
		this->Output.szLboxString,
		this->Output.nLboxString
	);
}
int LboxUnzip::Zip(
LPTSTR szCmdLine, LPTSTR szOutput, const DWORD dwSize )
{
	if ( LboxUnzip::lib2 == NULL ) {
		this->ErrMessage.operator = (
			"Zip32j.dll がインストールされていません"
		);
		return 1;
	}

	int nRet;

	nRet = ZipAction(
		LboxUnzip::hOwner,
		szCmdLine,
		szOutput,
		dwSize
	);

	if ( nRet != 0 ) {
		this->ErrMessage.operator = (
			"Zip32j.dll のエラーです"
		);
	}

	return nRet;
}
  



  MeltDirect

  
// *********************************************************
// リストビューの選択されている行のファイルを解凍
// 戻り値 : 0 正常終了, それ以外はエラー
// 解凍先にパス情報を反映しない
// *********************************************************
int LboxUnzip::MeltDirect( LboxListview *Lview, LboxString *LDir )
{
	return LboxUnzip::MeltDirect(
		Lview,
		LDir->szLboxString
	);
}
int LboxUnzip::MeltDirect( LboxListview *Lview, LPTSTR lpDir )
{
	LboxString LString;
	int nRow;
	BOOL bFirst;

	this->Command.operator = ( "-u -j " );
	LString.operator = (&(this->TargetPath));
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );
	LString.operator = (lpDir);
	LString.AddBackslash();
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );

	if ( Lview != NULL ) {
		this->Command.operator += ( " " );

		nRow = -1;
		bFirst = true;
		while( Lview->FindNextSelectedRow( &nRow ) ) {
			if ( bFirst ) {
				bFirst = false;
			}
			else {
				this->Command.operator += ( " " );
			}
			Lview->GetColumnText( 10, &LString );
			LString.Enclose('"');
			this->Command.operator += ( &(LString) );
		}
	}

	return LboxUnzip::Unzip(
		&(this->Command)
	);
}
  



  MeltDirectRow

  
int LboxUnzip::MeltDirectRow( LboxListview *Lview, int nTargetRow, LboxString *LDir )
{
	return LboxUnzip::MeltDirectRow(
		Lview,
		nTargetRow,
		LDir->szLboxString
	);
}
int LboxUnzip::MeltDirectRow( LboxListview *Lview, int nTargetRow, LPTSTR lpDir )
{
	LboxString LString;

	this->Command.operator = ( "-u -j " );
	LString.operator = (&(this->TargetPath));
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );
	LString.operator = (lpDir);
	LString.AddBackslash();
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );

	Lview->SetCurrentRow( nTargetRow );
	Lview->GetColumnText( 10, &LString );
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );

	return LboxUnzip::Unzip(
		&(this->Command)
	);
}
  



  MeltPathRow

  
int LboxUnzip::MeltPathRow( LboxListview *Lview, int nTargetRow, LboxString *LDir )
{
	return LboxUnzip::MeltPathRow(
		Lview,
		nTargetRow,
		LDir->szLboxString
	);
}
int LboxUnzip::MeltPathRow( LboxListview *Lview, int nTargetRow, LPTSTR lpDir )
{
	LboxString LString;

	this->Command.operator = ( "-u " );
	LString.operator = (&(this->TargetPath));
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );
	LString.operator = (lpDir);
	LString.AddBackslash();
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );
	this->Command.operator += ( " " );

	Lview->SetCurrentRow( nTargetRow );
	Lview->GetColumnText( 10, &LString );
	LString.Enclose('"');
	this->Command.operator += ( &(LString) );

	return LboxUnzip::Unzip(
		&(this->Command)
	);
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ