Skip to content

Commit 87bd6e2

Browse files
authored
Merge pull request #1 from KrxkGit/dev
Version 1.0.5
2 parents de7f4a6 + 8b49191 commit 87bd6e2

File tree

6 files changed

+190
-1
lines changed

6 files changed

+190
-1
lines changed

Diff for: HelpUploadFiles/CMainDlg.cpp

+171
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ void CMainDlg::OnCommand()
6666
case IDM_INJECT:
6767
OnInject();
6868
break;
69+
case IDM_IMPORT:
70+
OnImportSetting();
71+
break;
72+
case IDM_EXPORT:
73+
OnExportSetting();
74+
break;
6975
case IDM_SETPROCESS:
7076
OnSetProcessId();
7177
break;
@@ -256,3 +262,168 @@ void CMainDlg::OnSetProcessId()
256262
this->haveInject = true;
257263

258264
}
265+
266+
267+
void CMainDlg::OnImportSetting()
268+
{
269+
if (!isHaveInject()) {
270+
return;
271+
}
272+
// 导入配置文件:忽略列表
273+
OPENFILENAME ofn; // 使用OPENFILENAMEW结构体,它是OPENFILENAME的Unicode版本
274+
TCHAR szFile[MAX_PATH]; // 使用WCHAR数组来存储Unicode字符串
275+
szFile[0] = '\0';
276+
277+
// 初始化OPENFILENAMEW结构体
278+
ZeroMemory(&ofn, sizeof(ofn));
279+
ofn.lStructSize = sizeof(ofn);
280+
ofn.hwndOwner = hDlg;
281+
ofn.lpstrFile = szFile;
282+
ofn.nMaxFile = _countof(szFile);
283+
ofn.lpstrFilter = _T("HUFS Files\0*.hufs\0All Files\0*.*\0");
284+
ofn.nFilterIndex = 1;
285+
ofn.lpstrFileTitle = NULL;
286+
ofn.nMaxFileTitle = 0;
287+
ofn.lpstrInitialDir = NULL;
288+
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
289+
290+
// 显示打开文件对话框
291+
if (GetOpenFileNameW(&ofn) == TRUE && MessageBox(hDlg, _T("是否追加配置?"),_T("提示"), MB_ICONQUESTION | MB_OKCANCEL) == IDOK) {
292+
// 文件路径为 ofn.lpstrFile
293+
SettingSerialize(TRUE, ofn.lpstrFile);
294+
}
295+
else {
296+
// 用户取消了操作
297+
return;
298+
}
299+
}
300+
301+
302+
void CMainDlg::OnExportSetting()
303+
{
304+
// 导出配置文件:忽略列表
305+
OPENFILENAME ofn; // 使用OPENFILENAMEW结构体,它是OPENFILENAME的Unicode版本
306+
TCHAR szFile[MAX_PATH]; // 使用WCHAR数组来存储Unicode字符串
307+
szFile[0] = '\0';
308+
TCHAR szFileName[MAX_PATH]; // 存储用户选择的文件名
309+
310+
// 初始化OPENFILENAMEW结构体
311+
ZeroMemory(&ofn, sizeof(ofn));
312+
ofn.lStructSize = sizeof(ofn);
313+
ofn.hwndOwner = NULL;
314+
ofn.lpstrFile = szFile;
315+
ofn.nMaxFile = _countof(szFile); // 确保nMaxFile是字符数,而不是字节数
316+
ofn.lpstrDefExt = L"hufs"; // 默认扩展名
317+
ofn.lpstrFilter = L"HUFS Files\0*.hufs\0All Files\0*.*\0";
318+
ofn.nFilterIndex = 1;
319+
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_EXPLORER;
320+
321+
// 显示保存文件对话框
322+
if (GetSaveFileNameW(&ofn) == TRUE) {
323+
// 用户选择了文件名并点击了“保存”按钮
324+
// szFile中包含了选择的文件的完整路径
325+
wcscpy_s(szFileName, ofn.lpstrFile); // 复制选择的文件名
326+
// 这里可以进行文件保存操作
327+
SettingSerialize(FALSE, szFileName);
328+
}
329+
else {
330+
// 用户取消了操作
331+
return;
332+
}
333+
}
334+
335+
336+
void CMainDlg::SettingSerialize(bool bReadPattern, LPTSTR filename)
337+
{
338+
/*
339+
* 文件格式:
340+
* 第一行为 版本号
341+
* 每一行都为 TCHAR[MAX_PATH]
342+
*/
343+
double version = 1.05;
344+
double versionRead = 0;
345+
DWORD dwCreationDisposition = bReadPattern ? OPEN_EXISTING : CREATE_ALWAYS;
346+
347+
// 读写配置文件
348+
HANDLE hFile = CreateFile(
349+
filename, // 文件路径
350+
GENERIC_READ | GENERIC_WRITE, // 打开文件用于读取与写入
351+
0, // 不共享(独占)
352+
NULL, // 安全属性
353+
dwCreationDisposition, // 打开已存在的文件
354+
FILE_ATTRIBUTE_NORMAL,// 正常文件属性
355+
NULL); // 不使用模板
356+
357+
if (hFile == INVALID_HANDLE_VALUE) {
358+
MessageBox(hDlg, _T("配置文件打开或写入失败!"), _T("严重错误"), MB_ICONERROR);
359+
return;
360+
}
361+
362+
HWND hwndListBox = GetDlgItem(hDlg, IDC_LIST1); // 获取列表框控件的句柄
363+
364+
__try {
365+
if (bReadPattern) {
366+
// 读模式
367+
//
368+
// 读取版本号
369+
DWORD dwSize = 0;
370+
if (ReadFile(hFile, &versionRead, sizeof(versionRead), &dwSize, NULL)) {
371+
if (dwSize == sizeof(versionRead)) {
372+
if (versionRead != version) {
373+
MessageBox(hDlg, _T("配置文件版本号不一致"), _T("提示"), MB_ICONERROR);
374+
return;
375+
}
376+
}
377+
}
378+
else {
379+
MessageBox(hDlg, _T("读取配置文件失败"), _T("提示"), MB_ICONERROR);
380+
return;
381+
}
382+
383+
// 读取每一行
384+
TCHAR szBuffer[MAX_PATH];
385+
DWORD bufferSize = sizeof(szBuffer);
386+
dwSize = 0;
387+
while (ReadFile(hFile, szBuffer, bufferSize, &dwSize, NULL)) {
388+
if (dwSize > 0) {
389+
// 添加
390+
_tcscpy_s(this->szInput, _countof(this->szInput), szBuffer);
391+
DoAdd();
392+
}
393+
else {
394+
break;
395+
}
396+
}
397+
398+
MessageBox(hDlg, _T("导入配置文件完成"), _T("提示"), MB_ICONINFORMATION);
399+
}
400+
else {
401+
// 写模式
402+
// 写入版本号
403+
DWORD bytesWritten = sizeof(version);
404+
BOOL bSuccess = WriteFile(hFile, &version, bytesWritten, &bytesWritten, NULL);
405+
if (!bSuccess) {
406+
MessageBox(hDlg, _T("写入版本号失败"), _T("提示"), MB_ICONERROR);
407+
return;
408+
}
409+
410+
// 写入每一行
411+
int count = ListBox_GetCount(hwndListBox); // 获取列表框中的项数
412+
413+
for (int i = 0; i < count; ++i) {
414+
TCHAR buffer[MAX_PATH]; // 每个项的文本不超过255个字符
415+
ListBox_GetText(hwndListBox, i, buffer); // 获取第i项的文本
416+
417+
418+
bSuccess = WriteFile(hFile, buffer, sizeof(buffer), &bytesWritten, NULL);
419+
if (!bSuccess) {
420+
MessageBox(hDlg, _T("写入版本号失败"), _T("提示"), MB_ICONERROR);
421+
return;
422+
}
423+
424+
}
425+
}
426+
} __finally {
427+
CloseHandle(hFile);
428+
}
429+
}

Diff for: HelpUploadFiles/CMainDlg.h

+3
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@ class CMainDlg
4747
void OnLButtonUp();
4848
bool isHaveInject();
4949
void OnSetProcessId();
50+
void OnImportSetting();
51+
void OnExportSetting();
52+
void SettingSerialize(bool bReadPattern, LPTSTR filename);
5053
};
5154

Diff for: HelpUploadFiles/HelpUploadFiles.rc

320 Bytes
Binary file not shown.

Diff for: HelpUploadFiles/Resource.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#define IDM_INJECT 32775
2020
#define ID_32776 32776
2121
#define IDM_SETPROCESS 32777
22+
#define ID_32778 32778
23+
#define ID_32779 32779
24+
#define IDM_IMPORT 32780
25+
#define IDM_EXPORT 32781
2226
#define IDC_STATIC -1
2327

2428
// Next default values for new objects
@@ -27,7 +31,7 @@
2731
#ifndef APSTUDIO_READONLY_SYMBOLS
2832
#define _APS_NO_MFC 1
2933
#define _APS_NEXT_RESOURCE_VALUE 134
30-
#define _APS_NEXT_COMMAND_VALUE 32778
34+
#define _APS_NEXT_COMMAND_VALUE 32782
3135
#define _APS_NEXT_CONTROL_VALUE 1006
3236
#define _APS_NEXT_SYMED_VALUE 110
3337
#endif

Diff for: HelpUploadFiles/framework.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <windowsx.h>
1212
#include <strsafe.h>
1313
#include <process.h>
14+
#include <commdlg.h>
1415
// C 运行时头文件
1516
#include <stdlib.h>
1617
#include <malloc.h>

Diff for: README.md

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
Since there are no special rules required to ignore uploading for individual files, HelpUploadFiles is primarily aimed at scenarios involving folder uploads.
1414

15+
## 🧡Star History
16+
17+
[![Star History Chart](https://api.star-history.com/svg?repos=KrxkGit/HelpUploadFiles&type=Date)](https://star-history.com/#KrxkGit/HelpUploadFiles&Date)
18+
1519
## 🔥软件包的获取
1620

1721
1. 可前往 *Actions* 区下载最新特性 **HelpUploadFiles** 包。
@@ -385,6 +389,12 @@ Choose the appropriate version (x86/x64) of **HelpUploadFiles** to complete the
385389

386390
![image-20240509222322638](https://github.com/KrxkGit/HelpUploadFiles/blob/main/documents/imgs/11.jpg)
387391

392+
## 🧊v1.0.5 新增功能 - v1.0.5 New Features
393+
394+
此版本新增忽略列表导入与导出功能。
395+
396+
This version adds the functionality of importing and exporting an ignore list.
397+
388398

389399
## 🟡已发现的不完全适用情况 - Known Partially Incompatible Situations
390400

0 commit comments

Comments
 (0)