?? autooper.c
字號:
///////////////////////////////////////////////////////////////////////////////
//
// 文 件: AutoOper.c
// 自動加密函數(自動搜索合法文件)
//
// 作 者: 江南孤峰
// 聯 系:QQ: 403324669
// 時 間: 2007--3--3
//
///////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <direct.h>
#include <conio.h>
#include <stdlib.h>
#include "FilePass.h"
// 自動對當前目錄里的文件加密
int AutoAddPassForCurrentDirFile(
char *strAddFileSuffix,
char *strFreeFileSuffix,
int nFileDealMethod,
char *strPass,
char *strDES
){
char strDestFileName[FILE_LENGTH + 2] = {""};
char strFileSuffixForFind[FILE_LENGTH + 2] = {""};
FILE *fpSourceFile = NULL;
FILE *fpDestFile = NULL;
long lHandle = 0;
struct _finddata_t FileInfo;
int nAddPassSuccess = 0;
sprintf(strFileSuffixForFind,"*%s",strAddFileSuffix);
if((lHandle = _findfirst(strFileSuffixForFind,&FileInfo))==-1L){
printf("當前目錄下沒有可加密文件 !\n");
return nAddPassSuccess;
}
do{
if( AddPassForFile(
FileInfo.name,
strAddFileSuffix,
strFreeFileSuffix,
strPass,
strDES
) == SUCCESS
){
printf("文件 %s 加密完成\n",FileInfo.name);
MyDeleteFile(FileInfo.name,nFileDealMethod,ADD_PASS);
nAddPassSuccess ++;
}
else
printf("文件 %s 加密失敗\n",FileInfo.name);
printf("\n");
}while(!_findnext(lHandle,&FileInfo));
_findclose(lHandle);
return nAddPassSuccess;
}
// 自動對當前目錄里的文件解密
int AutoFreePassForCurrentDirFile(
char *strFreeFileSuffix,
int nFileDealMethod,
char *strPass,
char *strDES
){
char strTempDES[DES_LENGTH+2] = {""};
char strDestFileName[FILE_LENGTH+2] = {""};
char strDestFileSuffix[FILE_LENGTH+2] = {""};
char strFileSuffixForFind[FILE_LENGTH+2] = {""};
FILE *fpSourceFile = NULL;
FILE *fpDestFile = NULL;
int nFreePassSuccess = 0;
long lHandle = 0;
struct _finddata_t FileInfo;
sprintf(strFileSuffixForFind,"*%s",strFreeFileSuffix);
if((lHandle = _findfirst(strFileSuffixForFind,&FileInfo))==-1L){
printf("當前目錄下沒有可解密文件 !\n");
return nFreePassSuccess;
}
do{
if( FreePassForFile(
FileInfo.name,
strFreeFileSuffix,
strPass,
strDES
) == SUCCESS
){
printf("文件 %s 解密完成\n",FileInfo.name);
MyDeleteFile(FileInfo.name,nFileDealMethod,FREE_PASS);
nFreePassSuccess ++;
}
else
printf("文件 %s 解密失敗\n",FileInfo.name);
printf("\n");
}while(!_findnext(lHandle,&FileInfo));
_findclose(lHandle);
return nFreePassSuccess;
}
// 自動加密指定目錄下的所有文件
int AutoAddPassForUserDefDirFile(
char *strAddFileSuffix,
char *strFreeFileSuffix,
int nFileDealMethod,
char *strPass,
char *strDES
){
long lHandle = 0L;
int count = 0;
struct _finddata_t FileInfo;
int iSearchYes = FALSE;
char Directory[_MAX_PATH];
if(_getcwd(Directory,_MAX_PATH) != NULL){
printf("\n進入目錄: %s\n",Directory);
if(!strcmp(Directory,strBackupDirect)){
puts("該目錄為文件備分目錄");
return count;
}
}
else
printf("\n進入目錄: 獲取失敗 !\n");
if((lHandle = _findfirst("*",&FileInfo)) == -1L){
_findclose(lHandle);
return count;
}
do{
if( iSearchYes == FALSE){
count += AutoAddPassForCurrentDirFile(
strAddFileSuffix,
strFreeFileSuffix,
nFileDealMethod,
strPass,
strDES
);
iSearchYes = TRUE;
}
if(FileInfo.attrib == FILE_ATTRIBUTE_DIRECTORY){
if( FileInfo.name[0] != '.') { // . 或 .. 目錄終止
_chdir(FileInfo.name);
count += AutoAddPassForUserDefDirFile(
strAddFileSuffix,
strFreeFileSuffix,
nFileDealMethod,
strPass,
strDES
);
_chdir(".."); // 返回上一級目錄
}
}
}while(!_findnext(lHandle,&FileInfo));
_findclose(lHandle);
return count;
}
// 自動解密指定目錄下的所有文件
int AutoFreePassForUserDefDirFile(
char *strFreeFileSuffix,
int nFileDealMethod,
char *strPass,
char *strDES
){
long lHandle = 0L;
struct _finddata_t FileInfo;
int iSearchYes = FALSE;
char Directory[_MAX_PATH];
int count = 0;
if(_getcwd(Directory,_MAX_PATH) != NULL){
printf("\n進入目錄: %s\n",Directory);
if(!strcmp(Directory,strBackupDirect)){
puts("該目錄為文件備分目錄");
return count;
}
}
else
printf("\n進入目錄: 獲取失敗 !\n");
if((lHandle = _findfirst("*",&FileInfo)) == -1L){
_findclose(lHandle);
return count;
}
do{
if( iSearchYes == FALSE){
count += AutoFreePassForCurrentDirFile(
strFreeFileSuffix,
nFileDealMethod,
strPass,
strDES
);
iSearchYes = TRUE;
}
if(FileInfo.attrib == FILE_ATTRIBUTE_DIRECTORY){
if( FileInfo.name[0] != '.') {
_chdir(FileInfo.name);
count += AutoFreePassForUserDefDirFile(
strFreeFileSuffix,
nFileDealMethod,
strPass,
strDES
);
_chdir("..");
}
}
}while(!_findnext(lHandle,&FileInfo));
_findclose(lHandle);
return count ;
}
// 自動加密我的電腦下的所有文件
int AutoAddPassForAllFile(
char *strAddFileSuffix,
char *strFreeFileSuffix,
int nFileDealMethod,
char *strPass,
char *strDES
){
int iDrivers = 0;
int count = 0;
char strPartition[10] = {""};
// iDrivers = 1則從 A 盤開始搜索,但如果A盤沒準備好程序就會崩潰
// pc機最多可以有 26個驅動器
for(iDrivers = 3; iDrivers < 27; iDrivers ++)
if(!_chdrive(iDrivers)){
sprintf(strPartition,"%c:\\",iDrivers+'A'-1);
if(!_chdir(strPartition))
count += AutoAddPassForUserDefDirFile(
strAddFileSuffix,
strFreeFileSuffix,
nFileDealMethod,
strPass,
strDES
);
}
return count;
}
// 自動解密我的電腦下的所有文件
int AutoFreePassForAllFile(
char *strFreeFileSuffix,
int nFileDealMethod,
char *strPass,
char *strDES
){
int iDrivers = 0;
int count = 0;
char strPartition[10] = {""};
for(iDrivers = 3; iDrivers < 27; iDrivers ++)
if(!_chdrive(iDrivers)){
sprintf(strPartition,"%c:\\",iDrivers+'A'-1);
if(!_chdir(strPartition))
count += AutoFreePassForUserDefDirFile(
strFreeFileSuffix,
nFileDealMethod,
strPass,
strDES
);
}
return count;
}
// 改變當前的工作目錄
int ChangeCurrentDirect(void){
char buffer[_MAX_PATH] = {127};
char *strDirectory;
printf("請輸入指定目錄的絕對路徑:");
strDirectory = _cgets(buffer);
if(strlen(strDirectory) > _MAX_PATH){
printf("錯誤: 路徑長度超過 %d\n",_MAX_PATH);
return FAILED;
}
if(_chdir(strDirectory) == -1){
printf("錯誤: 目錄 %s 不存在\n",strDirectory);
return FAILED;
}
return SUCCESS;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -