⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kiutil.cpp

📁 一个解压程序,只要设定了解压路径和解压文件的种类,就可以随意解压
💻 CPP
字号:

#include "stdafx.h"
#include "kiutil.h"
//added by uema2.
#include "ueutil.h"
#include "conv.h"

///////////////

void kiutil::timeSet( const char* fname, FILETIME* pft )
{
	//fname傪TCHAR偵
	TCHAR* t_fname;

	t_fname = (TCHAR *)LocalAlloc(LPTR, (strlen(fname)+1)*sizeof(TCHAR));
	_MultiByteToWideChar(CP_ACP, 0, fname, strlen(fname)+1,
		t_fname, strlen(fname)+1);

//	HANDLE han = CreateFile( fname,
	HANDLE han = CreateFile( t_fname, // by uema2.
							 GENERIC_READ | GENERIC_WRITE,
							 FILE_SHARE_READ,NULL,
							 OPEN_EXISTING,
							 FILE_ATTRIBUTE_NORMAL,
							 NULL );
	if( han==INVALID_HANDLE_VALUE )
		return;

	SetFileTime( han,pft,NULL,pft );

	CloseHandle( han );
}

void kiutil::timeSet( const char* fname, DWORD sec )
{
	//localtime傪巊偆丅偱丄gmtime偲崌傢偣傞偨傔丄
	//帪娫傪9帪娫尭傜偡丅by uema2.
	sec -= 60*60*9;
//	struct tm* time=gmtime((long*)&sec);
	struct tm* time=ueutil::localtime(&sec);
	if( time!=NULL )
	{
		FILETIME ft;
		SYSTEMTIME sys;

		sys.wYear =      time->tm_year+1900;
		sys.wMonth =     time->tm_mon+1;
		sys.wDayOfWeek = time->tm_wday;
		sys.wDay =       time->tm_mday;
		sys.wHour =      time->tm_hour;
		sys.wMinute =    time->tm_min;
		sys.wSecond =    time->tm_sec;
		sys.wMilliseconds = 0;
		SystemTimeToFileTime(&sys,&ft);
		timeSet( fname,&ft );
	}
}

void kiutil::timeSet( const char* fname,WORD date,WORD time )
{
	FILETIME ft,lc;
//	if( DosDateTimeToFileTime( date, time, &lc ) )
	if( ueutil::DosDateTimeToFileTime( date, time, &lc ) )//by uema2
	{
		if( LocalFileTimeToFileTime( &lc, &ft ) )
			timeSet( fname,&ft );
	}
}

//////////////

void kiutil::wndFront( HWND wnd )
{
/*
	static DWORD Ver = GetVersion();

	if( ( (Ver&0x80000000) && LOBYTE(LOWORD(Ver))>=4 && HIBYTE(LOWORD(Ver))>=10 ) ||
	    (!(Ver&0x80000000) && LOBYTE(LOWORD(Ver))>=5 )) // 怴偟偄Windows
	{
		DWORD pid;
		DWORD thread1 = GetWindowThreadProcessId( GetForegroundWindow(),&pid );
		DWORD thread2 = GetCurrentThreadId();
		AttachThreadInput( thread2, thread1, TRUE );
		SetForegroundWindow( wnd );
		AttachThreadInput( thread2, thread1, FALSE );
		BringWindowToTop( wnd );
	}
	else  // 屆偄Windows
*/		SetForegroundWindow( wnd );
}

///////////////

char kiutil::lb[256];

void kiutil::pathInit()
{
	lb[0] = 0;
	for( int c=1; c!=256; c++ )
//		lb[c] = (IsDBCSLeadByte(c) ? 2 : 1);
		lb[c] = (_IsDBCSLeadByte(c) ? 2 : 1); // for kctrl.dll
}

#define isdblb(c) (lb[(unsigned char)(c)]==2)
#define step(p) (p+=lb[(unsigned char)*(p)])

char* kiutil::pathMake( char* path )
{
	char* st = path;
	TCHAR* t_st;  //by uema2.

	while( *st=='/' || *st=='\\' || *st=='?' )
		st++;
	if( st[0]!='\0' && st[1]==':' )
		st+=2;
	while( *st=='/' || *st=='\\' || *st=='?' )
		st++;

	for( unsigned char *p=(unsigned char*)st; *p!='\0'; step(p) )
	{
		if( isdblb(*p) )
			continue;

		if( *p=='\\' || *p=='/' )
		{
			*p='\0';
			//st傪TCHAR偵 by uema2.
			char* absPath;
			absPath = (char*)LocalAlloc(LPTR, MAX_PATH*sizeof(char));
			sprintf(absPath, "%s\\%s", ueutil::GetExtractPath(), st);
			DWORD charlength =  _MultiByteToWideChar(CP_ACP, 0, absPath, MAX_PATH, NULL, 0);
			t_st = (TCHAR *)LocalAlloc(LPTR, (charlength+1)*sizeof(TCHAR));
			_MultiByteToWideChar(CP_ACP, 0, absPath, charlength,
				t_st, charlength);
//			CreateDirectory( st, NULL );
			CreateDirectory( t_st, NULL );
			LocalFree(t_st);
			LocalFree(absPath);
			*p='\\';
		}
		else if( *p<' ' || ( *p>'~' && !( 0xa0<=*p && *p<=0xdf ) ) || strchr(":*?\"<>|",*p) )
			*p = '_';
	}

	return st;
}

void kiutil::pathMakeAbs( char* path )
{
	int i=0;
	TCHAR* t_path;// by uema2.
	for( char* p=path; *p!='\0'; step(p) )
	{
//		if( i++ < 4 ) // 嵟弶偺係暥帤埲撪偺 \ 偼僪儔僀僽傪昞偡丄偲偄偆偙偲偵偟偰偍偔丅
		if( i++ < 3 ) // CE偵偼僪儔僀僽偲偄偆奣擮偑側偄偺偱3暥帤偖傜偄傑偱偵偟偰偍偔 by uema2.
			continue;

		if( *p=='\\' )
		{
			*p='\0';
			//path傪TCHAR偵 by uema2.
			DWORD charlength = _MultiByteToWideChar(CP_ACP, 0, path, MAX_PATH, NULL, 0);
			t_path = (TCHAR *)LocalAlloc(LPTR, (charlength+1)*sizeof(TCHAR));
			_MultiByteToWideChar(CP_ACP, 0, path, charlength,
				t_path, charlength);
//			CreateDirectory( path, NULL );
//			MessageBox(NULL, t_path, L"pathMakeAbs", MB_OK);
			CreateDirectory( t_path, NULL );
			LocalFree(t_path);
			*p='\\';
		}
	}
}

void kiutil::pathSplit( const char* path, int* y, int* d )
{
	*y=-1, *d=-1;
	for( const char* x=path; *x!='\0'; step(x) ) 
	{
		if( *x=='\\' || *x=='/' )	*y=x-path,*d=-1;
		else if( *x=='.' )			*d=x-path;
	}
}

const char* kiutil::pathExt( const char* path )
{
	int y,d;
	kiutil::pathSplit( path,&y,&d );
	return (d!=-1) ? path+d+1 : path+strlen(path);
}

const char* kiutil::pathName( const char* path )
{
	int y,d;
	kiutil::pathSplit( path,&y,&d );
	return path+y+1;
}

#undef step
#undef isdblb

//////////////

char* kiutil::getline( char* str, int size, FILE* fp )
{
	if( size>0 )
	{
		char* p=str;

		while( --size )
		{
			int c = fgetc(fp);

			if( c<=0 ) // EOF || '\0'
				break;
			else if( c=='\n' )
				break;
			else if( c=='\r' )
			{
				c = fgetc(fp);
				if( c!=EOF && c!='\n' )
					ungetc( c,fp );
				break;
			}
			else
				*(p++) = c;
		}

		*p='\0';
	}

	return feof(fp) ? NULL : str;
}

void kiutil::getOriginalName( char* nw, const char* od, char* ext )
{
	int y,d;
	kiutil::pathSplit( od,&y,&d );
	strcpy( nw,od+y+1 );

	if( ext )
	{
		strcat( nw,"." );
		strcat( nw,ext );
	}
	else
		nw[d-y-1]='\0';
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -