js:狗粮pro1.3.1,采集cd管理1.3.2,多层文件夹处理 (#1130)
This commit is contained in:
@@ -52,8 +52,6 @@ const DEFAULT_FIGHT_TIMEOUT_SECONDS = 120;
|
||||
// 检查记录文件是否存在
|
||||
let indexDoExist = false;
|
||||
for (const filePath of filesInSubFolder) {
|
||||
log.info(filePath);
|
||||
log.info(`records\\${accountName}.txt`);
|
||||
if (filePath === `records\\${accountName}.txt`) {
|
||||
indexDoExist = true;
|
||||
break;
|
||||
@@ -219,49 +217,6 @@ const DEFAULT_FIGHT_TIMEOUT_SECONDS = 120;
|
||||
runRouteA = Math.floor((now - epochTime) / (24 * 60 * 60 * 1000)) % 2 === 0;
|
||||
}
|
||||
|
||||
// 根据 runRouteA 的值给 runningRoute 赋值
|
||||
const runningRoute = runRouteA ? "A" : "B";
|
||||
const folderName = `${runningRoute}路线`;
|
||||
const filePathPreparation = `assets/ArtifactsPath/${folderName}/00准备`;
|
||||
// 运行准备路线
|
||||
prepare: {
|
||||
if (runnedToday) {
|
||||
break prepare;
|
||||
}
|
||||
//切换至好感队
|
||||
await switchPartyIfNeeded(friendshipPartyName);
|
||||
|
||||
// 读取文件夹中的文件名并处理
|
||||
const filePaths = file.readPathSync(filePathPreparation);
|
||||
const jsonFileNames = [];
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
const fileName = basename(filePath); // 提取文件名
|
||||
if (fileName.endsWith('.json')) { // 检查文件名是否以 .json 结尾
|
||||
jsonFileNames.push(fileName); // 存储文件名
|
||||
}
|
||||
}
|
||||
|
||||
let currentTask = 0; // 当前任务计数器
|
||||
|
||||
// 执行准备路线的地图追踪文件
|
||||
for (const fileName of jsonFileNames) {
|
||||
const fullPath = fileName;
|
||||
await fakeLog(fileName, false, true, 0);
|
||||
currentTask += 1; // 更新当前任务计数器
|
||||
log.info(`当前进度:${fullPath}为准备${folderName}第${currentTask}/${jsonFileNames.length}个`);
|
||||
await pathingScript.runFile(fullPath);
|
||||
//捕获任务取消的信息并跳出循环
|
||||
try {
|
||||
await sleep(10); // 假设 sleep 是一个异步函数,休眠 10 毫秒
|
||||
} catch (error) {
|
||||
log.error(`发生错误: ${error}`);
|
||||
return false; // 终止循环
|
||||
}
|
||||
await fakeLog(fileName, false, false, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// 启用自动拾取的实时任务
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
|
||||
@@ -446,7 +401,43 @@ async function runArtifactsPaths(runRouteA) {
|
||||
const filePathNormal = `assets/ArtifactsPath/${folderName}/01普通`;
|
||||
const filePathEnding = `assets/ArtifactsPath/${folderName}/02收尾`;
|
||||
const filePathExtra = `assets/ArtifactsPath/${folderName}/03额外`;
|
||||
const filePathPreparation = `assets/ArtifactsPath/${folderName}/00准备`;
|
||||
|
||||
// 运行准备路线(关闭拾取)
|
||||
dispatcher.ClearAllTriggers();
|
||||
{
|
||||
// 读取文件夹中的文件名并处理
|
||||
const filePaths = file.readPathSync(filePathPreparation);
|
||||
const jsonFileNames = [];
|
||||
|
||||
for (const filePath of filePaths) {
|
||||
const fileName = basename(filePath); // 提取文件名
|
||||
if (fileName.endsWith('.json')) { // 检查文件名是否以 .json 结尾
|
||||
jsonFileNames.push(fileName); // 存储文件名
|
||||
}
|
||||
}
|
||||
|
||||
let currentTask = 0; // 当前任务计数器
|
||||
|
||||
// 执行准备路线的地图追踪文件
|
||||
for (const fileName of jsonFileNames) {
|
||||
const fullPath = fileName;
|
||||
await fakeLog(fileName, false, true, 0);
|
||||
currentTask += 1; // 更新当前任务计数器
|
||||
log.info(`当前进度:${fullPath}为准备${folderName}第${currentTask}/${jsonFileNames.length}个`);
|
||||
await pathingScript.runFile(fullPath);
|
||||
//捕获任务取消的信息并跳出循环
|
||||
try {
|
||||
await sleep(10); // 假设 sleep 是一个异步函数,休眠 10 毫秒
|
||||
} catch (error) {
|
||||
log.error(`发生错误: ${error}`);
|
||||
return false; // 终止循环
|
||||
}
|
||||
await fakeLog(fileName, false, false, 0);
|
||||
}
|
||||
}
|
||||
// 启用自动拾取的实时任务
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
// 运行普通路线
|
||||
{
|
||||
// 读取文件夹中的文件名并处理
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "自动狗粮重制版",
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.1",
|
||||
"tags": ["好感", "盗宝团", "愚人众", "鳄鱼", "兽肉", "狗粮"],
|
||||
"description": "通过不同好感任务卡时间后运行狗粮任务以提高狗粮总收益,需要正确配置好感队伍的战斗策略,并在自定义配置中指定好感和狗粮队伍名称",
|
||||
"authors": [
|
||||
|
||||
0
repo/js/多层文件夹处理/assets/文件1.txt
Normal file
0
repo/js/多层文件夹处理/assets/文件1.txt
Normal file
0
repo/js/多层文件夹处理/assets/文件2.json
Normal file
0
repo/js/多层文件夹处理/assets/文件2.json
Normal file
0
repo/js/多层文件夹处理/assets/文件3.json
Normal file
0
repo/js/多层文件夹处理/assets/文件3.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/子文件夹1/文件6.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/子文件夹1/文件6.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件4.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件4.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件5.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹1/文件5.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹2/文件7.json
Normal file
0
repo/js/多层文件夹处理/assets/文件夹2/文件7.json
Normal file
73
repo/js/多层文件夹处理/main.js
Normal file
73
repo/js/多层文件夹处理/main.js
Normal file
@@ -0,0 +1,73 @@
|
||||
// 定义 readFolder 函数
|
||||
/*
|
||||
该函数可以实现输入要处理的文件夹路径后,将其中所有文件/仅json文件按照原顺序存储在一个对象中,具体使用参考主函数
|
||||
*/
|
||||
async function readFolder(folderPath, onlyJson) {
|
||||
log.info(`开始读取文件夹:${folderPath}`);
|
||||
|
||||
// 新增一个堆栈,初始时包含 folderPath
|
||||
const folderStack = [folderPath];
|
||||
|
||||
// 新增一个数组,用于存储文件信息对象
|
||||
const files = [];
|
||||
|
||||
// 当堆栈不为空时,继续处理
|
||||
while (folderStack.length > 0) {
|
||||
// 从堆栈中弹出一个路径
|
||||
const currentPath = folderStack.pop();
|
||||
|
||||
// 读取当前路径下的所有文件和子文件夹路径
|
||||
const filesInSubFolder = file.ReadPathSync(currentPath);
|
||||
|
||||
// 临时数组,用于存储子文件夹路径
|
||||
const subFolders = [];
|
||||
for (const filePath of filesInSubFolder) {
|
||||
if (file.IsFolder(filePath)) {
|
||||
// 如果是文件夹,先存储到临时数组中
|
||||
subFolders.push(filePath);
|
||||
} else {
|
||||
// 如果是文件,根据 onlyJson 判断是否存储
|
||||
if (onlyJson) {
|
||||
if (filePath.endsWith(".json")) {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到 JSON 文件:${filePath}`);
|
||||
}
|
||||
} else {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到文件:${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将临时数组中的子文件夹路径按原顺序压入堆栈
|
||||
folderStack.push(...subFolders.reverse()); // 反转子文件夹路径
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// 主函数
|
||||
(async function () {
|
||||
// 调用 readFolder 函数测试
|
||||
const folderPath = settings.folderPath; // 文件夹路径
|
||||
const onlyJson = settings.onlyJson; // 是否只返回 JSON 文件
|
||||
|
||||
const files = await readFolder(folderPath, onlyJson);
|
||||
log.info(`处理结果:`);
|
||||
files.forEach(file => {
|
||||
log.info(`完整路径:${file.fullPath}`);
|
||||
log.info(`文件名:${file.fileName}`);
|
||||
log.info(`文件夹路径数组:${file.folderPathArray.join(", ")}`);//允许通过访问该数组的不同层级,例如判断材料种类等
|
||||
});
|
||||
})();
|
||||
13
repo/js/多层文件夹处理/manifest.json
Normal file
13
repo/js/多层文件夹处理/manifest.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "多层文件夹处理",
|
||||
"version": "1.0",
|
||||
"description": "读取多层文件夹并进行处理的一种方法",
|
||||
"authors": [
|
||||
{
|
||||
"name": "mno"
|
||||
}
|
||||
],
|
||||
"settings_ui": "settings.json",
|
||||
"main": "main.js"
|
||||
}
|
||||
14
repo/js/多层文件夹处理/settings.json
Normal file
14
repo/js/多层文件夹处理/settings.json
Normal file
@@ -0,0 +1,14 @@
|
||||
[
|
||||
|
||||
{
|
||||
"name": "folderPath",
|
||||
"type": "input-text",
|
||||
"label": "要处理的文件夹在js文件夹中的路径",
|
||||
"default": "assets"
|
||||
},
|
||||
{
|
||||
"name": "onlyJson",
|
||||
"type": "checkbox",
|
||||
"label": "是否只处理json文件"
|
||||
}
|
||||
]
|
||||
@@ -86,7 +86,7 @@ async function fakeLog(name, isJs, isStart, duration) {
|
||||
|
||||
// 定义目标文件夹路径和记录文件路径
|
||||
const recordFolder = "record"; // 存储记录文件的文件夹路径
|
||||
const defaultTimeStamp = "2000-01-01T00:00:00.000Z"; // 固定的时间戳
|
||||
const defaultTimeStamp = "2023-10-13T00:00:00.000Z"; // 固定的时间戳
|
||||
|
||||
// 从 settings 中读取用户配置,并设置默认值
|
||||
const userSettings = {
|
||||
@@ -139,6 +139,62 @@ function removeJsonSuffix(fileName) {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
async function readFolder(folderPath, onlyJson) {
|
||||
log.info(`开始读取文件夹:${folderPath}`);
|
||||
|
||||
// 新增一个堆栈,初始时包含 folderPath
|
||||
const folderStack = [folderPath];
|
||||
|
||||
// 新增一个数组,用于存储文件信息对象
|
||||
const files = [];
|
||||
|
||||
// 当堆栈不为空时,继续处理
|
||||
while (folderStack.length > 0) {
|
||||
// 从堆栈中弹出一个路径
|
||||
const currentPath = folderStack.pop();
|
||||
|
||||
// 读取当前路径下的所有文件和子文件夹路径
|
||||
const filesInSubFolder = file.ReadPathSync(currentPath);
|
||||
|
||||
// 临时数组,用于存储子文件夹路径
|
||||
const subFolders = [];
|
||||
for (const filePath of filesInSubFolder) {
|
||||
if (file.IsFolder(filePath)) {
|
||||
// 如果是文件夹,先存储到临时数组中
|
||||
subFolders.push(filePath);
|
||||
} else {
|
||||
// 如果是文件,根据 onlyJson 判断是否存储
|
||||
if (onlyJson) {
|
||||
if (filePath.endsWith(".json")) {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到 JSON 文件:${filePath}`);
|
||||
}
|
||||
} else {
|
||||
const fileName = filePath.split('\\').pop(); // 提取文件名
|
||||
const folderPathArray = filePath.split('\\').slice(0, -1); // 提取文件夹路径数组
|
||||
files.push({
|
||||
fullPath: filePath,
|
||||
fileName: fileName,
|
||||
folderPathArray: folderPathArray
|
||||
});
|
||||
//log.info(`找到文件:${filePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将临时数组中的子文件夹路径按原顺序压入堆栈
|
||||
folderStack.push(...subFolders.reverse()); // 反转子文件夹路径
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
|
||||
(async function () {
|
||||
try {
|
||||
// 获取子文件夹路径
|
||||
@@ -166,7 +222,8 @@ function removeJsonSuffix(fileName) {
|
||||
if (!indexDoExist) {
|
||||
log.info("路径组1.txt 文件不存在,将尝试生成索引文件");
|
||||
}
|
||||
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
await fakeLog("采集cd管理", true, false, 1000);
|
||||
// 循环处理多个路径组
|
||||
for (let i = 1; ; i++) {
|
||||
// 检查当前路径组的 cdtype 是否为空
|
||||
@@ -177,14 +234,13 @@ function removeJsonSuffix(fileName) {
|
||||
}
|
||||
|
||||
const targetFolder = `pathing/路径组${i}`; // 动态生成目标文件夹路径
|
||||
const filePaths = file.ReadPathSync(targetFolder);
|
||||
|
||||
const files = await readFolder(targetFolder, true);
|
||||
const filePaths = files.map(file => file.fullPath);
|
||||
// 如果文件夹为空,退出循环
|
||||
if (filePaths.length === 0) {
|
||||
log.info(`路径组${i} 文件夹为空,停止处理`);
|
||||
break;
|
||||
}
|
||||
|
||||
// 用于存储符合条件的文件名的数组
|
||||
const jsonFileNames = [];
|
||||
const entryMap = {};
|
||||
@@ -241,21 +297,11 @@ function removeJsonSuffix(fileName) {
|
||||
} else {
|
||||
log.error(`写入文件失败: ${recordFilePath}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增逻辑:当选择“执行任务(若不存在索引文件则自动创建)”时,执行类似路径执行的逻辑
|
||||
//当选择“执行任务(若不存在索引文件则自动创建)”时,执行类似路径执行的逻辑
|
||||
if (userSettings.operationMode === "执行任务(若不存在索引文件则自动创建)") {
|
||||
log.info("启用自动拾取的实时任务");
|
||||
dispatcher.addTimer(new RealtimeTimer("AutoPick"));
|
||||
await fakeLog("采集cd管理", true, false, 1000);
|
||||
// 获取子文件夹内的所有文件路径
|
||||
const recordFiles = file.ReadPathSync(subFolderPath);
|
||||
// 直接获取文件数量作为路径组数量
|
||||
const totalPathGroups = recordFiles.length;
|
||||
|
||||
// 外层循环:依次处理每个路径组
|
||||
for (let groupNumber = 1; groupNumber <= totalPathGroups; groupNumber++) {
|
||||
let groupNumber = i;
|
||||
const pathGroupFilePath = `${subFolderPath}/路径组${groupNumber}.txt`; // 动态生成路径组文件路径
|
||||
|
||||
genshin.returnMainUi();
|
||||
@@ -274,8 +320,9 @@ function removeJsonSuffix(fileName) {
|
||||
const entryWithTimestamp = pathGroupEntries[i].trim();
|
||||
const [entryName, entryTimestamp] = entryWithTimestamp.split('::');
|
||||
|
||||
// 构造路径文件路径
|
||||
const pathingFilePath = `pathing/路径组${groupNumber}/${entryName}.json`;
|
||||
// 查找对应的完整路径
|
||||
const fileEntry = files.find(file => file.fileName === `${entryName}.json`);
|
||||
const pathingFilePath = fileEntry.fullPath;
|
||||
|
||||
// 获取开始时间
|
||||
const startTime = new Date();
|
||||
@@ -312,8 +359,6 @@ function removeJsonSuffix(fileName) {
|
||||
continue; // 跳过当前任务
|
||||
}
|
||||
|
||||
|
||||
|
||||
//捕获任务取消的信息并跳出循环
|
||||
try {
|
||||
await sleep(10); // 假设 sleep 是一个异步函数,休眠 10 毫秒
|
||||
@@ -432,12 +477,13 @@ function removeJsonSuffix(fileName) {
|
||||
log.error(`读取路径组文件 ${pathGroupFilePath} 时出错: ${error}`);
|
||||
}
|
||||
}
|
||||
log.info('所有路径组的任务运行完成');
|
||||
|
||||
//伪造js开始的日志
|
||||
await fakeLog("采集cd管路", true, true, 0);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
log.error(`操作失败: ${error}`);
|
||||
}
|
||||
|
||||
//伪造js开始的日志
|
||||
await fakeLog("采集cd管路", true, true, 0);
|
||||
})();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"manifest_version": 1,
|
||||
"name": "采集cd管理",
|
||||
"version": "1.2",
|
||||
"version": "1.3.2",
|
||||
"bgi_version": "0.44.8",
|
||||
"description": "仅面对会操作文件和读readme的用户,基于文件夹操作自动管理采集路线的cd,会按照路径组的顺序依次运行,直到指定的时间,并会按照给定的cd类型,自动跳过未刷新的路线",
|
||||
"authors": [
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"label": "选择操作模式",
|
||||
"options": [
|
||||
"执行任务(若不存在索引文件则自动创建)",
|
||||
"重新生成索引文件(用于强制刷新CD或更新文件)"
|
||||
"重新生成索引文件(用于强制刷新CD)"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user