working on paths...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-07-13 21:03:29 +04:00
parent 0192dff702
commit 9b816ec553

View File

@ -35,43 +35,39 @@ if(window.CEF_dumpJSON != null){
console.log('node-webkit mode: loading...') console.log('node-webkit mode: loading...')
var path = require('path')
var fs = require('fs') var fs = require('fs')
var fse = require('fs.extra') var fse = require('fs.extra')
var proc = require('child_process') var proc = require('child_process')
var node_crypto = require('crypto') var node_crypto = require('crypto')
//var exif = require('exif2') //var exif = require('exif2')
var gui = require('nw.gui') var gui = require('nw.gui')
var fp = /file:\/\/\//
window.osPath = function(p){
return path.normalize(p.replace(/file:\/\/\//, ''))
}
// paths to included utils... // paths to included utils...
process.env.PATH += ';' + process.cwd() + '/vips/bin' process.env.PATH += ';' + path.normalize(process.cwd() + '/vips/bin')
// Things ImageGrid needs... // Things ImageGrid needs...
// XXX do we need assync versions?? // XXX do we need assync versions??
window.listDir = function(path){ window.listDir = function(path){
if(fp.test(path)){ return fs.readdirSync(osPath(path))
// XXX will this work on Mac???
path = path.replace(fp, '')
}
return fs.readdirSync(path)
} }
// XXX make this work across fs... // XXX make this work across fs...
// XXX this will not overwrite... // XXX this will not overwrite...
window.copyFile = function(src, dst){ window.copyFile = function(src, dst){
var deferred = $.Deferred() var deferred = $.Deferred()
if(fp.test(src)){ src = osPath(src)
// XXX will this work on Mac??? dst = osPath(dst)
src = src.replace(fp, '')
}
if(fp.test(dst)){
// XXX will this work on Mac???
dst = dst.replace(fp, '')
}
var path = dst.split('/') var path = dst.split(/[\\\/]/)
path.pop() path.pop()
path = path.join('/') path = path.join('/')
@ -97,10 +93,7 @@ if(window.CEF_dumpJSON != null){
return deferred.resolve() return deferred.resolve()
} }
window.dumpJSON = function(path, data){ window.dumpJSON = function(path, data){
if(fp.test(path)){ path = osPath(path)
// XXX will this work on Mac???
path = path.replace(fp, '')
}
var dirs = path.split(/[\\\/]/) var dirs = path.split(/[\\\/]/)
dirs.pop() dirs.pop()
dirs = dirs.join('/') dirs = dirs.join('/')
@ -112,18 +105,10 @@ if(window.CEF_dumpJSON != null){
return fs.writeFileSync(path, JSON.stringify(data), encoding='utf8') return fs.writeFileSync(path, JSON.stringify(data), encoding='utf8')
} }
window.removeFile = function(path){ window.removeFile = function(path){
if(fp.test(path)){ return fs.unlinkSync(osPath(path))
// XXX will this work on Mac???
path = path.replace(fp, '')
}
return fs.unlinkSync(path)
} }
window.runSystem = function(path){ window.runSystem = function(path){
if(fp.test(path)){ return proc.exec('"'+osPath(path)+'"', function(error, stdout, stderr){
// XXX will this work on Mac???
path = path.replace(fp, '')
}
return proc.exec('"'+path+'"', function(error, stdout, stderr){
if(error != null){ if(error != null){
console.error(stderr) console.error(stderr)
} }
@ -138,7 +123,7 @@ if(window.CEF_dumpJSON != null){
} }
var getter = $.Deferred() var getter = $.Deferred()
var cmd = 'vips im_header_string "$FIELD" "$IN"' var cmd = 'vips im_header_string "$FIELD" "$IN"'
.replace(/\$IN/g, source.replace(fp, '')) .replace(/\$IN/g, osPath(source))
.replace(/\$FIELD/g, field) .replace(/\$FIELD/g, field)
proc.exec(cmd, function(error, stdout, stderr){ proc.exec(cmd, function(error, stdout, stderr){
getter.resolve(stdout.trim()) getter.resolve(stdout.trim())
@ -224,7 +209,7 @@ if(window.CEF_dumpJSON != null){
var img = IMAGES[gid] var img = IMAGES[gid]
var source = normalizePath(img.path) var source = normalizePath(img.path)
var name = gid +' - '+ source.split('/').pop() var name = gid +' - '+ source.split(/[\\\/]/).pop()
var compression = 90 var compression = 90
var previews = [] var previews = []
@ -238,7 +223,7 @@ if(window.CEF_dumpJSON != null){
// build usable local path (without 'file:///')... // build usable local path (without 'file:///')...
var cache_path = normalizePath(CACHE_DIR) var cache_path = normalizePath(CACHE_DIR)
cache_path = cache_path.replace(fp, '') cache_path = osPath(cache_path)
// get cur image size... // get cur image size...
var size_getter = _getImageSize('max', source) var size_getter = _getImageSize('max', source)
@ -306,7 +291,7 @@ if(window.CEF_dumpJSON != null){
} }
var cmd = 'vips im_shrink "$IN:$RSCALE" "$OUT:$COMPRESSION" $FACTOR $FACTOR' var cmd = 'vips im_shrink "$IN:$RSCALE" "$OUT:$COMPRESSION" $FACTOR $FACTOR'
.replace(/\$IN/g, source.replace(fp, '')) .replace(/\$IN/g, osPath(source))
.replace(/\$RSCALE/g, rscale) .replace(/\$RSCALE/g, rscale)
.replace(/\$OUT/g, preview_path) .replace(/\$OUT/g, preview_path)
.replace(/\$COMPRESSION/g, compression) .replace(/\$COMPRESSION/g, compression)