Skip to content

Commit 26a198f

Browse files
committed
fixed bugs: windows paths issue, menu reset function, config saving, custom bootscreen v2
1 parent 80e6e01 commit 26a198f

File tree

5 files changed

+31
-30
lines changed

5 files changed

+31
-30
lines changed

app/git-tool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ exports.Status=()=>promisify('status',git(root))();
4141
exports.Fetch=()=>promisify('fetch',git(root))(['--all']);
4242
exports.Tag=gitTag;
4343
exports.Tags=gitTags;
44-
exports.Show=(branch,file)=>promisify('show',git(root))([branch+':'+file]);
44+
exports.Show = (branch, file) => promisify('show', git(root))([branch + ':' + file.replace(/\\/g, '/')]);
4545
exports.git=git;
4646
exports.root=a=>a?gitRoot(a):root?Promise.resolve(root):Promise.reject();
4747

app/server.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var os = require('os');
2121
var ifaces = os.networkInterfaces();
2222
var natUpnp = require('nat-upnp');
2323
var moment = require('moment');
24+
var mkdirp = require('mkdirp');
2425

2526
var natClient;
2627

@@ -252,8 +253,13 @@ app.get('/checkout-force', function (req, res) {
252253
).catch(e => 'not found')
253254
)
254255
))
256+
var rm = () =>
257+
seek4File('_Bootscreen.h', [path.join('Marlin', 'src', 'config'), 'Marlin'])
258+
.then(file => file && promisify(fs.unlink)(file));
259+
255260
git.Checkout('--force')
256-
.then(a => baseCfg == 'Marlin' && a || cp())
261+
.then(rm)
262+
.then(a => baseCfg == 'Marlin' ? a : cp())
257263
.then(a=>res.send(a));
258264
});
259265
app.get('/fetch', function (req, res) {
@@ -275,26 +281,19 @@ var copyFile=(from,to)=>
275281
);
276282
app.get('/save', function (req, res) {
277283
var dt=moment().format('YYYY-MM-DD kk-mm-ss');
278-
git.root()
279-
.then(root=>path.join(root,store))
280-
.then(dir=>promisify(fs.stat)(dir).catch(a=>promisify(fs.mkdir)(dir)).then(a=>dir))
281-
.then(dir=>git.Tag().then(tag=>path.join(dir,tag)))
282-
.then(dir=>promisify(fs.stat)(dir).catch(a=>promisify(fs.mkdir)(dir)).then(a=>dir))
283-
.then(dir=>path.join(dir,dt))
284-
.then(dir=>promisify(fs.stat)(dir).catch(a=>promisify(fs.mkdir)(dir)).then(a=>dir))
285-
.then(dir=>git.root().then(root=>({dir:dir,root:root})))
284+
Promise.all([git.root(), git.Tag()])
285+
.then(p => {
286+
var dir = path.join(p[0], store, p[1].replace('/', path.sep), dt);
287+
return promisify(mkdirp)(dir).then(a => ({to: dir, root: p[0]}));
288+
})
286289
.then(dirs=>Promise.all(
287290
['Configuration.h','Configuration_adv.h','_Bootscreen.h']
288-
.map(file=>promisify(fs.stat)(path.join(dirs.root,'Marlin',file)).then(()=>file).catch(()=>null))
291+
.map(file => seek4File(file, ['Marlin', path.join('Marlin', 'src', 'config')]).catch(()=>null))
289292
)
290-
.then(files=>({root:dirs.root,files:files.filter(a=>a),to:dirs.dir,message:req.query.message}))
293+
.then(files => Object.assign(dirs, {files: files.filter(a => a), message:req.query.message}))
291294
)
292295
.then(dirs=>
293-
Promise.all(
294-
dirs.files.map(f=>
295-
copyFile(path.join(dirs.root,'Marlin',f), path.join(dirs.to,f) )
296-
)
297-
)
296+
Promise.all(dirs.files.map(f => copyFile(f, path.join(dirs.to, path.basename(f)))))
298297
.then(()=>dirs)
299298
)
300299
.then(dirs=>promisify(fs.writeFile)(path.join(dirs.to,'contents.json'),JSON.stringify(dirs,null,2)).then(()=>dirs))
@@ -326,8 +325,9 @@ app.get('/restore/:path', function (req, res) {
326325
.map(f=>({path:f,name:path.parse(f).base}))
327326
var cp=files
328327
.filter(i=>/_Bootscreen\.h/.test(i))
329-
.map(f=>git.root()
330-
.then(root=>copyFile(f,path.join(root,'Marlin',path.parse(f).base)))
328+
.map(f =>
329+
seek4File('', [path.join('Marlin', 'src', 'config'), 'Marlin'])
330+
.then(dir => copyFile(f, path.join(dir, path.basename(f) )))
331331
)
332332
console.log(cp);
333333
//return (uploadFiles(up));
@@ -489,18 +489,18 @@ app.get('/bs/default', function (req, res) {
489489
});
490490
app.post('/bs/custom', function (req, res) {
491491
var name='_Bootscreen.h';
492-
Promise
493-
.resolve(path.join(__dirname,'..','views',name))
494-
.then(file=>promisify(fs.readFile)(file,'utf8'))
495-
.then(text=>text.replace(/{{([\w.]+)}}/g,(m,r)=>r.split('.').reduce((p,o)=>(p=p&&p[o],p),req.body)))
496-
.then(file=>git.root().then(p=>promisify(fs.writeFile)(path.join(p,'Marlin',name),file)))
492+
Promise.all([
493+
seek4File('', [path.join('Marlin', 'src', 'config'), 'Marlin']),
494+
promisify(fs.readFile)(path.join(__dirname, '..', 'views', name), 'utf8')
495+
.then(text => text.replace(/{{([\w.]+)}}/g, (m, r) => r.split('.').reduce((p, o) => (p = p && p[o], p), req.body)))
496+
])
497+
.then(p => promisify(fs.writeFile)(path.join(p[0], name), p[1]))
497498
.then(a=>res.end('writed'))
498499
.catch(e=>res.status(403).send(e))
499500
});
500501
app.get('/bs/custom', function (req, res) {
501-
git.root()
502-
.then(f=>path.join(f,'Marlin','_Bootscreen.h'))
503-
.then(file=>promisify(fs.readFile)(file,'utf8'))
502+
seek4File('_Bootscreen.h', [ 'Marlin', path.join('Marlin', 'src', 'config')])
503+
.then(file => promisify(fs.readFile)(file, 'utf8'))
504504
.then(data=>{
505505
var d=getMatch(/{(([^}]|\r\n?|\n)*)}/g,data);
506506
d=d.replace(/\n/g,'').replace(/ /g,'');

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "marlin-conf",
3-
"version": "2.7.14",
3+
"version": "2.7.16",
44
"description": "configuration tool for Marlin project",
55
"main": "./index.js",
66
"scripts": {
@@ -71,6 +71,7 @@
7171
"jquery-ui-dist": "^1.12.1",
7272
"js-yaml": "^3.8.4",
7373
"marked": "^0.3.6",
74+
"mkdirp": "^0.5.1",
7475
"moment": "^2.18.1",
7576
"nat-upnp": "^1.1.0",
7677
"node-notifier": "^5.1.2",

start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,5 @@ commands:
152152
`);
153153
}
154154
module.exports.main=main;
155-
console.log('Node',process.version);
155+
console.log('Node', process.version, pjson.name, 'v', pjson.version);
156156
require.main===module && main();

static/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ <h5 class="modal-title" id="mct-restoreModalLabel">Choose desired configuration
319319
</button>
320320
</div>
321321
<div class="modal-body">
322-
<p></p>
322+
<p style="max-height:50vh;overflow-y:auto;"></p>
323323
<div class="form-group">
324324
<label for="message-text" class="form-control-label">Message:</label>
325325
<textarea class="form-control" rows="8" id="message-text" disabled></textarea>

0 commit comments

Comments
 (0)