@@ -2,8 +2,9 @@ const { dialog } = require("electron").remote;
22const fs = require ( "fs" ) ;
33const path = require ( "path" ) ;
44const child_process = require ( "child_process" ) ;
5- const stream = require ( "stream" ) ;
65const os = require ( "os" ) ;
6+ const process = require ( "process" ) ;
7+ const configPath = path . join ( process . cwd ( ) , "config.json" ) ;
78
89const valueToLanguage = [
910 "8086" ,
@@ -22,7 +23,7 @@ const valueToMonacoLanguage = [
2223 "cpp" ,
2324 "java" ,
2425 "plaintext" ,
25- "plaintext " ,
26+ "m3 " ,
2627 "plaintext" ,
2728 "pascal" ,
2829 "plaintext" ,
@@ -83,6 +84,10 @@ async function processSIM() {
8384 const err = ret . stderr . toString ( "utf-8" ) ;
8485 $ ( "#sim-stdout" ) . text ( out ) ;
8586 $ ( "#sim-stderr" ) . text ( err ) ;
87+ }
88+
89+ function processResultFilter ( ) {
90+ const out = $ ( "#sim-stdout" ) . text ( ) ;
8691 const resArr = out . split ( "\n" ) ;
8792 let startIndex = resArr . indexOf ( "\r" ) + 1 ;
8893 let tableData = [ ] ;
@@ -103,9 +108,7 @@ async function processSIM() {
103108 tableData . forEach ( ( v ) => {
104109 tableBody . append (
105110 $ (
106- `<tr onclick="diff()"><th>${ v . fileAName } </th><th>${
107- v . fileBName
108- } </th><th>${ v . similarPercentage . toString ( ) } </th></tr>`
111+ `<tr onclick="diff()"><th>${ v . fileAName } </th><th>${ v . fileBName } </th><th>${ v . similarPercentage } </th></tr>`
109112 )
110113 ) ;
111114 } ) ;
@@ -132,6 +135,40 @@ function diff() {
132135 $ ( "#diffModal" ) . modal ( ) ;
133136}
134137
138+ function loadConfig ( ) {
139+ const config = JSON . parse ( fs . readFileSync ( configPath ) ) ;
140+ $ ( "#directory-input" ) . val ( config . directory ?? "" ) ;
141+ $ ( "#input-file-fliter" ) . val ( config . fileFilter ?? "" ) ;
142+ $ ( "#language-select" ) . val ( config . language ?? "" ) ;
143+ $ ( "#threshold" ) . val ( config . threshold ?? "" ) ;
144+ $ ( "#result-fliter" ) . val ( config . resultFilter ?? "" ) ;
145+ }
146+
147+ function saveConfig ( config ) {
148+ fs . writeFileSync (
149+ configPath ,
150+ JSON . stringify (
151+ config ?? {
152+ directory : $ ( "#directory-input" ) . val ( ) ,
153+ fileFilter : $ ( "#input-file-fliter" ) . val ( ) ,
154+ language : $ ( "#language-select" ) . val ( ) ,
155+ threshold : $ ( "#threshold" ) . val ( ) ,
156+ resultFilter : $ ( "#result-fliter" ) . val ( ) ,
157+ }
158+ )
159+ ) ;
160+ }
161+ function resetConfig ( ) {
162+ saveConfig ( {
163+ directory : os . homedir ( ) ,
164+ fileFilter : "(filename) => true" ,
165+ language : "2" ,
166+ threshold : 75 ,
167+ resultFilter : `(fileAName, fileBName, percentage) => {\n const A = fileAName.split("-");\n const B = fileBName.split("-");\n return A[0] != B[0] && A[1] == B[1];\n};` ,
168+ } ) ;
169+ loadConfig ( ) ;
170+ }
171+
135172( function ( ) {
136173 const amdLoader = require ( "./node_modules/monaco-editor/min/vs/loader.js" ) ;
137174 const amdRequire = amdLoader . require ;
@@ -159,3 +196,12 @@ function diff() {
159196 ) ;
160197 } ) ;
161198} ) ( ) ;
199+
200+ ( function ( ) {
201+ if ( ! fs . existsSync ( configPath ) ) {
202+ resetConfig ( ) ;
203+ } else {
204+ loadConfig ( ) ;
205+ }
206+ window . onbeforeunload = ( ) => saveConfig ( ) ;
207+ } ) ( ) ;
0 commit comments