📄 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 + -