{"Log " + logNumber + "/" + getLogList().length}
+{"Log " + logNumber + "/" + getInOutSettings().logList.length}
{status}
diff --git a/src/components/blenderController.ts b/src/components/blenderController.ts
index 4fc8d9e..398265c 100644
--- a/src/components/blenderController.ts
+++ b/src/components/blenderController.ts
@@ -4,7 +4,7 @@ import logger from "./logger";
import { setBlenderLoading, setBlenderStatus } from "./ui/menu";
import { setLogNumber, setPastTime, setRemainingTime, setRenderDisplayProgress, setStatus, setPastTimeNow, setRemainingTimeNow } from "./ui/renderingPage";
import {imageLoading, imageLoaded} from "./ui/settingsPage";
-import { getLogList, getLogSize, settingList } from "./settings";
+import { getLogSize, getInOutSettings } from "./settings";
import isValid from "is-valid-path";
import { pageSetRendering, setProgress, openPage, Page } from "../renderer";
import { ipcRenderer } from "electron";
@@ -198,15 +198,15 @@ function blender(command:blenderCmd) {
}
} else if(command === blenderCmd.startRendering) {
if(readyToAcceptCommand) {
- if(settingList.log == "") {
+ if(getInOutSettings().log == "") {
logger.warningMSG("No log selected!");
- } else if(!isValid(settingList.log)) {
+ } else if(!isValid(getInOutSettings().log)) {
logger.warningMSG("Output path is invalid!");
} else {
currentLogPortion = 0;
const logSizeList:number[] = [];
- getLogList().forEach(function (value, index) {
+ getInOutSettings().logList.forEach(function (value, index) {
logSizeList.push(getLogSize(index));
});
diff --git a/src/components/logReader.ts b/src/components/logReader.ts
index 9890691..0c7dfc9 100644
--- a/src/components/logReader.ts
+++ b/src/components/logReader.ts
@@ -1,8 +1,9 @@
import logger from "./logger";
import {parse as csvParse} from "csv-parse";
-import {settingList} from "./settings";
+import {getInOutSettings} from "./settings";
import {platformCharacter} from "./paths";
import {formatDate} from "./dateFormat";
+import fs from "fs";
async function openLogFile(filePath:string, rawData:boolean) {
const data = await fetch(filePath).then(function(response) {
@@ -162,8 +163,8 @@ async function getLogTime(filePath:string) {
async function getAllLogs() {
const loadList = [];
- if(settingList.log.length > 0) {
- const logs = settingList.log.substring(1).slice(0, -1).split('""');
+ if(getInOutSettings().log.length > 0) {
+ const logs = getInOutSettings().log.substring(1).slice(0, -1).split('""');
for(const log of logs) {
loadList.push({
@@ -184,8 +185,8 @@ async function reloadAllLogs() {
}
async function updateLogs() {
- if(settingList.log.length > 0) {
- const logs = settingList.log.substring(1).slice(0, -1).split('""');
+ if(getInOutSettings().log.length > 0) {
+ const logs = getInOutSettings().log.substring(1).slice(0, -1).split('""');
for(const log of logs) {
if(!logList.some(x => x.path === log)) {
logList.push({
@@ -206,8 +207,20 @@ async function updateLogs() {
}
}
+function getLogList() {
+ return getInOutSettings().log.split("\"\"");
+}
+
+function getLogSize(index:number) {
+ const logList = getInOutSettings().log.substring(1).slice(0, -1).split('""');
+
+ return fs.statSync(logList[index]).size;
+}
+
export {
reloadAllLogs,
logList,
- updateLogs
+ updateLogs,
+ getLogList,
+ getLogSize
};
\ No newline at end of file
diff --git a/src/components/paths.ts b/src/components/paths.ts
index ab53202..928b97c 100644
--- a/src/components/paths.ts
+++ b/src/components/paths.ts
@@ -4,7 +4,8 @@ import { platformFolder, platform, Platform } from './platform';
export const dataPath = app.getPath('userData');
export const appPath = app.getAppPath().replace("app.asar", "");
-export const SettingPath = path.join(dataPath, "settings.xml");
+export const SettingPath = path.join(dataPath, "settings.json");
+export const OLDSettingPath = path.join(dataPath, "settings.xml");
export const defaultOutputPath = path.join(app.getPath('videos'), "StickExporterTX");
diff --git a/src/components/settings.ts b/src/components/settings.ts
index c7c92b0..f24252a 100644
--- a/src/components/settings.ts
+++ b/src/components/settings.ts
@@ -1,11 +1,6 @@
-import formatXML from "xml-formatter";
-import {SettingPath, defaultOutputPath} from './paths';
-import fs from "fs";
+import {SettingPath, defaultOutputPath, OLDSettingPath} from './paths';
import logger from "./logger";
-
-function getXMLChild(doc:Document, child:string) {
- return String(doc.getElementsByTagName(child)[0].childNodes[0].nodeValue);
-}
+import fs from "fs";
enum VideoFormat {
mp4="mp4",
@@ -15,125 +10,219 @@ enum VideoFormat {
mkv="mkv",
}
-const defaultSettings = {
- fps: 30,
- width: 540,
- stickDistance: 5,
- stickMode2: true,
- videoFormat: VideoFormat.webm,
- log: '',
- output: defaultOutputPath
+type JSONProfile = {
+ profileName: string,
+ fps: number,
+ width: number,
+ stickDistance: number,
+ stickMode2: boolean,
+ videoFormat: VideoFormat
+};
+
+type JSONSettings = {
+ activeProfile: string,
+ profiles: JSONProfile[],
+ log: string,
+ output: string,
}
-let allSettingsFound = true;
+const defaultSettings:JSONSettings = {
+ activeProfile: "Default",
+ profiles: [
+ {
+ profileName: "Default",
+ fps: 30,
+ width: 540,
+ stickDistance: 5,
+ stickMode2: true,
+ videoFormat: VideoFormat.webm
+ }
+ ],
+ log: '',
+ output: defaultOutputPath
+};
+
function catchSetting(tryFunc:()=>string, catchFunc:()=>string) {
let val;
try {
val = tryFunc();
} catch(err) {
logger.info("Failed to get setting value. Using default value:" + String(err));
- allSettingsFound = false;
val = catchFunc();
}
return val;
}
+
+function getXMLChild(doc:Document, child:string) {
+ return String(doc.getElementsByTagName(child)[0].childNodes[0].nodeValue);
+}
+
const settingList = await fetch(SettingPath).then(function(response) {
return response.text();
}).catch(function(err) {
logger.info(err);
return "fileLoadFailed";
-}).then(function(data) {
+}).then(async function(data) {
if(data === "fileLoadFailed") {
- allSettingsFound = false;
- return defaultSettings;
+
+ return await fetch(OLDSettingPath).then(function(response) {
+ return response.text();
+ }).catch(function(err) {
+ logger.info(err);
+ return "fileLoadFailed";
+ }).then(function(data) {
+ if(data === "fileLoadFailed") {
+ return defaultSettings;
+ }
+
+ const parser = new DOMParser();
+ const xmlDoc = parser.parseFromString(data, 'text/xml');
+
+ return {
+ activeProfile: defaultSettings.activeProfile,
+ profiles: [
+ {
+ profileName: defaultSettings.profiles[0].profileName,
+ fps: parseInt(catchSetting(function() {return getXMLChild(xmlDoc, "fps");},function() {return defaultSettings.profiles[0].fps.toString();})),
+ width: parseInt(catchSetting(function() {return getXMLChild(xmlDoc, "width");},function() {return defaultSettings.profiles[0].width.toString();})),
+ stickDistance: parseInt(catchSetting(function() {return getXMLChild(xmlDoc, "stickDistance");},function() {return defaultSettings.profiles[0].stickDistance.toString();})),
+ stickMode2: catchSetting(function() {return getXMLChild(xmlDoc, "stickMode2");},function() {return defaultSettings.profiles[0].stickMode2.toString();}) === "true",
+ videoFormat: catchSetting(function() {return getXMLChild(xmlDoc, "videoFormat");},function() {return defaultSettings.profiles[0].videoFormat.toString();}) as VideoFormat as VideoFormat
+ }
+ ],
+ log: catchSetting(function() {return (getXMLChild(xmlDoc, "log") === "None")? "":getXMLChild(xmlDoc, "log");},function() {return defaultSettings.log;}),
+ output: catchSetting(function() {return getXMLChild(xmlDoc, "output");},function() {return defaultSettings.output;})
+ } as JSONSettings;
+ });
}
- const parser = new DOMParser();
- const xmlDoc = parser.parseFromString(data, 'text/xml');
-
- return {
- fps: parseInt(catchSetting(function() {return getXMLChild(xmlDoc, "fps");},function() {return defaultSettings.fps.toString();})),
- width: parseInt(catchSetting(function() {return getXMLChild(xmlDoc, "width");},function() {return defaultSettings.width.toString();})),
- stickDistance: parseInt(catchSetting(function() {return getXMLChild(xmlDoc, "stickDistance");},function() {return defaultSettings.stickDistance.toString();})),
- stickMode2: catchSetting(function() {return getXMLChild(xmlDoc, "stickMode2");},function() {return defaultSettings.stickMode2.toString();}) === "true",
- videoFormat: catchSetting(function() {return getXMLChild(xmlDoc, "videoFormat");},function() {return defaultSettings.videoFormat.toString();}) as VideoFormat as VideoFormat,
- log: catchSetting(function() {return (getXMLChild(xmlDoc, "log") === "None")? "":getXMLChild(xmlDoc, "log");},function() {return defaultSettings.log;}),
- output: catchSetting(function() {return getXMLChild(xmlDoc, "output");},function() {return defaultSettings.output;})
- }
+ return JSON.parse(data) as JSONSettings;
});
-if(!allSettingsFound) {
- updateSettings({});
+
+function createProfile(profileName:string, clone:boolean) {
+
+
+ settingList.profiles.push({
+ profileName: profileName,
+ fps: clone? getActiveProfile().fps:defaultSettings.profiles[0].fps,
+ width: clone? getActiveProfile().width:defaultSettings.profiles[0].width,
+ stickDistance: clone? getActiveProfile().stickDistance:defaultSettings.profiles[0].stickDistance,
+ stickMode2: clone? getActiveProfile().stickMode2:defaultSettings.profiles[0].stickMode2,
+ videoFormat: clone? getActiveProfile().videoFormat:defaultSettings.profiles[0].videoFormat
+ });
+
+ writeSettings();
}
-function updateSettings(optiones:{fps?:number, width?:number, stickDistance?:number, stickMode2?:boolean, videoFormat?:VideoFormat, log?:string, output?:string}) {
- if(optiones.fps === undefined) {
- optiones.fps = settingList.fps;
- } else {
- settingList.fps = optiones.fps;
- }
- if(optiones.width === undefined) {
- optiones.width = settingList.width;
- } else {
- settingList.width = optiones.width;
- }
- if(optiones.stickDistance === undefined) {
- optiones.stickDistance = settingList.stickDistance;
- } else {
- settingList.stickDistance = optiones.stickDistance;
- }
- if(optiones.stickMode2 === undefined) {
- optiones.stickMode2 = settingList.stickMode2;
- } else {
- settingList.stickMode2 = optiones.stickMode2;
- }
- if(optiones.videoFormat === undefined) {
- optiones.videoFormat = settingList.videoFormat;
- } else {
- settingList.videoFormat = optiones.videoFormat;
- }
- if(optiones.log === undefined) {
- optiones.log = settingList.log;
- } else {
- settingList.log = optiones.log;
- }
- if(optiones.output === undefined) {
- optiones.output = settingList.output;
- } else {
- settingList.output = optiones.output;
+function ProfileLoadDefault(profileName?:string) {
+ if(profileName === undefined) {
+ profileName = getActiveProfile().profileName;
}
- const xmlStr = `
-
-
openFolder(settingList.output)}>{output}
+openFolder(getInOutSettings().output)}>{output}
{ openPage(Page.Main); }}>Finish - +
{"Log " + logNumber + "/" + getLogList().length}
+{"Log " + logNumber + "/" + getInOutSettings().logList.length}
{status}