📄 fes.h
字号:
/***
* fes.h
*
* superStar, 2004.2
***/
static char pathSrc[MAXPATH]; /* 源文件全路径名 */
static char pathDst[MAXPATH]; /* 目标文件全路径名 */
static char drive[MAXDRIVE]; /* 文件所在驱动器名 */
static char dir[MAXDIR]; /* 文件所在目录名 */
static char file[MAXFILE]; /* 文件名 */
static char ext[MAXEXT]; /* 文件扩展名 */
static char tmpext[MAXEXT];
static char fnChosen[FILENAMELENGTH]; /* 从文件列表中选择的文件名 */
static struct ffblk srcFileInfo; /* 源文件的相关文件属性 */
static struct ffblk dstFileInfo; /* 目标文件的相关文件属性 */
static struct ffblk fileInfo; /* 列表文件时某个已搜寻到文件的文件属性 */
static struct ftime fileTime;
BYTE *buf;
KEYINFO key;
/**
* void SysMainFun(void);
* - 本函数中使用全局变量
* - key(type: KEYINFO)
**/
void
SysMainFun(void)
{
/* 获取密钥并扩展出子密钥,如果
* 失败则返回,并释放可能已经申
* 请的堆空间 */
if (FALSE == Key(&key))
{
FreeKey(&key);
return;
}
/* 如果输入的路径合法,则可
* 选择文件进行加解密 */
if (TRUE == GetFilePath())
{
/* 文件选取,然后加密或解密 */
FileENDE();
}
FreeKey(&key);
}
/**
* BOOL GetFilePath(void);
* - 输入路径并判断合法性以及调整后缀名
* - 成功返回TRUE,若取消则返回FALSE
* - 本函数中使用全局变量
* - filePath(type: WINDOWHANDLE)
* - message(type: WINDOWHANDLE)
* - key(type: KEYINFO)
* - pathSrc(type: char[])
* - dir(type: char[])
* - file(type: char[])
* - ext(type: char[])
* - tmpext(type: char[])
* - fileInfo(type: struct ffblk)
**/
BOOL
GetFilePath(void)
{
int done;
char drAnddir[MAXDRIVE+MAXDIR];
GETPATHSTART:
/* 输入文件路径名 */
filePath.retStrLen = MAXPATH-1;
if (ENCRYPT == key.flag)
{
strcpy(filePath.title, "[ENCRYPT: load file...]");
}
else if (DECRYPT == key.flag)
{
strcpy(filePath.title, "[DECRYPT: load file...]");
}
if (FALSE == Window(&filePath)) /* 如果取消输入则返回FALSE */
{
FreeWindow(&filePath);
return FALSE;
}
CopyTo(pathSrc, filePath.retStr,
filePath.retStrLen);
pathSrc[filePath.retStrLen] = '\0';
FreeWindow(&filePath);
strcpy(tmpext, ".*");
fnsplit(pathSrc, drive, dir, file, ext); /* 调整后缀名 */
ToLower(ext);
if (strcmp(ext, ".*") != 0)
{
strcpy(tmpext, ext);
strcpy(ext, ".*");
fnmerge(pathSrc, drive, dir, file, ext);
}
done = findfirst(pathSrc, &fileInfo, ALLFILES);
if (0 != done) /* 判断当前输入的路径是否合法 */
{
strcpy(message.displayStr, "[!]\n\n No such directory or file \n");
Message(&message);
getch();
FreeMessage(&message);
goto GETPATHSTART;
}
else
{
/* 调整当前目录为输入的目录 */
fnsplit(pathSrc, drive, dir, file, ext);
if (0 != strcmp(dir, "\\"))
{
dir[strlen(dir)-1] = '\0';
}
strcpy(drAnddir, drive);
strcat(drAnddir, dir);
if (chdir(drAnddir))
{
/* 如果调整目录到输入的目录失败,则给出提示 */
strcpy(message.displayStr, "[!]\n\n Unable to UPDATE the directory \n");
Message(&message);
getch();
FreeMessage(&message);
goto GETPATHSTART;
}
}
return TRUE;
}
/**
* void FileENDE(void);
* - 载入文件并加密或解密
* - 如果载入失败或取消该操作,则返回
* - 本函数中使用全局变量
* - message(type: WINDOWHANDLE)
* - pathSrc(type: char[])
* - drive(type: char[])
* - dir(type: char[])
* - file(type: char[])
* - ext(type: char[])
* - tmpext(type: char[])
* - fileInfo(type: struct ffblk)
* - fnChosen(type: char [])
**/
void
FileENDE(void)
{
FILEHANDLE srcFileHandle,
dstFileHandle;
int done, i, j, k, pageNum;
FILEATTRIB fnAttrib[MAXFILENUMS];
char drAnddir[MAXDRIVE+MAXDIR];
/*strcpy(pathSrc, "c:\\superc\\*.sea"); 调试用 */
i = pageNum = done = 0;
while (0 == done)
{
/* 列出当前目录下的所有文件 */
if (0 != strcmp(fileInfo.ff_name, ".")
&& 0 != strcmp(fileInfo.ff_name, ".."))
{
/* 判断当前找到的是文件还是子目录 */
if (FA_DIREC == (fileInfo.ff_attrib & FA_DIREC))
{
fnAttrib[i].flag = ISDIR;
strcpy(fnAttrib[i].fnStr, fileInfo.ff_name);
i++;
}
else
{
fnsplit(fileInfo.ff_name, drive, dir, file, ext);
ToLower(ext);
if ( 0 == strcmp(tmpext, ".*")
||(0 != strcmp(tmpext, ".*")
&& 0 == strcmp(tmpext, ext)))
{
fnAttrib[i].flag = ISFILE;
strcpy(fnAttrib[i].fnStr, fileInfo.ff_name);
i++;
}
}
}
done = findnext(&fileInfo);
/* 文件列表中一屏最多列出MAXFILENUMS-3个文件,
* 并根据搜索情况在列表中添加翻页菜单项和退回
* 上一级目录菜单项 */
if (MAXFILENUMS-3 == i || 0 != done)
{
/* 如果当前页还没有列完所有文件和目录则
* 在列表的最后添加翻页标记(向上和向下)*/
if (MAXFILENUMS-3 == i && 0 == done)
{
fnAttrib[i].flag = ISPAGEDOWN;
strcpy(fnAttrib[i].fnStr, "...>>");
i++;
if (pageNum > 0)
{
fnAttrib[i].flag = ISPAGEUP;
strcpy(fnAttrib[i].fnStr, "...<<");
i++;
}
}
/* 如果刚好列完,但页号大于0时则也需要
* 添加向上翻页标记 */
else if (0 < i
&& i <= MAXFILENUMS-3
&& 0 != done)
{
if (pageNum > 0)
{
fnAttrib[i].flag = ISPAGEUP;
strcpy(fnAttrib[i].fnStr, "...<<");
i++;
}
}
/* 判断是否要加上返回上一级目录的标记 */
fnsplit(pathSrc, drive, dir, file, ext);
dir[strlen(dir)-1] = '\0';
if (0 != strcmp(dir, ""))
{
fnAttrib[i].flag = ISRETURN;
strcpy(fnAttrib[i].fnStr, "..\\");
i++;
}
/* ViewFiles()返回-1时表示取消当前选择
* 否则返回的是所选项的编号值(>0) */
if (-1 ==
(j = ViewFiles(fnAttrib, i)))
{
return;
}
else
{
switch (fnAttrib[j].flag)
{
case ISFILE: /* 如果选择项是文件 */
strcpy(fnChosen, fnAttrib[j].fnStr);
/* 获取被选择文件和目标文件的句柄号 */
if (TRUE ==
GetFileHandle(&srcFileHandle,
&dstFileHandle))
{
/* 如果成功获取到句柄号则
* 进行加密或解密操作 */
SeaENDE(&srcFileHandle,
&dstFileHandle);
}
/* 刷新当前目录 */
fnsplit(pathSrc, drive, dir, file, ext);
strcpy(file, "*");
strcpy(ext, ".*");
fnmerge(pathSrc, drive, dir, file, ext);
done = findfirst(pathSrc, &fileInfo, ALLFILES);
pageNum = 0;
break;
case ISDIR : /* 如果选择项是子目录 */
/* 将pathSrc改为进入子目录后的路径 */
fnsplit(pathSrc, drive, dir, file, ext);
strcat(dir, fnAttrib[j].fnStr);
strcat(dir, "\\");
fnmerge(pathSrc, drive, dir, file, ext);
dir[strlen(dir)-1] = '\0';
strcpy(drAnddir, drive);
strcat(drAnddir, dir);
if (strlen(pathSrc) < MAXPATH)
{
/* 将子目录设定为当前目录 */
if (chdir(drAnddir))
{
strcpy(message.displayStr, "[!]\n\n Unable to get into the child directory \n");
Message(&message);
getch();
FreeMessage(&message);
return;
}
pageNum = 0;
done = findfirst(pathSrc, &fileInfo, ALLFILES);
}
else
{
strcpy(message.displayStr, "[!]\n\n Too long file path... \n");
Message(&message);
getch();
FreeMessage(&message);
return;
}
break;
case ISPAGEDOWN: /* 如果选择项是向下翻页 */
pageNum++;
break;
case ISPAGEUP: /* 如果选择项是向上翻页 */
done = PassPages(pageNum-1);
if (pageNum > 0)pageNum--;
break;
case ISRETURN: /* 如果选择项是返回上一级目录 */
/* 将pathSrc改为返回上一级目录后的路径 */
fnsplit(pathSrc, drive, dir, file, ext);
k = strlen(dir)-2;
while (dir[k] != '\\') k--;
dir[k+1] = '\0';
fnmerge(pathSrc, drive, dir, file, ext);
if (0 != strcmp(dir, "\\"))
{
dir[k] = '\0';
}
strcpy(drAnddir, drive);
strcat(drAnddir, dir);
if (chdir(drAnddir))
{
strcpy(message.displayStr, "[!]\n\n Unable to return the father directory \n");
Message(&message);
getch();
FreeMessage(&message);
return;
}
pageNum = 0;
done = findfirst(pathSrc, &fileInfo, ALLFILES);
break;
default:
break;
}/* end of switch */
}/* end of if (-1 ==..) else(... */
i = 0;
} /* end of if (MAXFILE... */
}/* end of while */
}
/**
* int PassPages(int p);
* - 将当前目录下的文件列表翻过p页
* - 返回done
* - 本函数中使用全局变量
* - pathSrc(type: char[])
* - fileInfo(type: struct ffblk)
**/
int
PassPages(int p)
{
int k, done;
k = 0;
done = findfirst(pathSrc, &fileInfo, ALLFILES);
while (k < p*(MAXFILENUMS-3))
{
if (0 == done
&& 0 != strcmp(fileInfo.ff_name, ".")
&& 0 != strcmp(fileInfo.ff_name, ".."))
{
if (FA_DIREC ==
(fileInfo.ff_attrib & FA_DIREC))
{
k++;
}
else
{
fnsplit(fileInfo.ff_name,
drive, dir, file, ext);
ToLower(ext);
if (0 == strcmp(tmpext, ".*")
||(0 != strcmp(tmpext, ".*")
&& 0 == strcmp(tmpext, ext)))
{
k++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -