Minor Improvements

* Made Refresh() more robust - when an error is encountered, the layer(set) is reloaded automatically.
* JS errors are now output to console instead of alerts.
This commit is contained in:
Unknown
2018-04-04 15:14:59 -04:00
parent d52e896ac3
commit 4bf7eca6b0
5 changed files with 42 additions and 36 deletions

20
ps.go
View File

@@ -73,10 +73,10 @@ func SaveAs(path string) error {
func DoJs(path string, args ...string) (out []byte, err error) { func DoJs(path string, args ...string) (out []byte, err error) {
// Temp file for js to output to. // Temp file for js to output to.
outpath := filepath.Join(os.Getenv("TEMP"), "js_out.txt") outpath := filepath.Join(os.Getenv("TEMP"), "js_out.txt")
defer os.Remove(outpath)
if !strings.HasSuffix(path, ".jsx") { if !strings.HasSuffix(path, ".jsx") {
path += ".jsx" path += ".jsx"
} }
defer os.Remove(outpath)
args = append([]string{outpath}, args...) args = append([]string{outpath}, args...)
@@ -87,14 +87,12 @@ func DoJs(path string, args ...string) (out []byte, err error) {
args = append([]string{path}, args...) args = append([]string{path}, args...)
cmd, err := run("dojs", args...) cmd, err := run("dojs", args...)
if err != nil { if err == nil {
return []byte{}, err file, err := ioutil.ReadFile(outpath)
if err == nil {
cmd = append(cmd, file...)
}
} }
file, err := ioutil.ReadFile(outpath)
if err != nil {
return cmd, err
}
cmd = append(cmd, file...)
return cmd, err return cmd, err
} }
@@ -138,11 +136,7 @@ func run(name string, args ...string) ([]byte, error) {
cmd.Stdout = &out cmd.Stdout = &out
cmd.Stderr = &errs cmd.Stderr = &errs
err := cmd.Run() err := cmd.Run()
if err != nil { if err != nil || len(errs.Bytes()) != 0 {
return out.Bytes(), err
// return append(out.Bytes(), errs.Bytes()...), err
}
if len(errs.Bytes()) != 0 {
return out.Bytes(), errors.New(string(errs.Bytes())) return out.Bytes(), errors.New(string(errs.Bytes()))
} }
return out.Bytes(), nil return out.Bytes(), nil

12
scripts/PsIsOpen.vbs Normal file
View File

@@ -0,0 +1,12 @@
Function IsProcessRunning( strComputer, strProcess )
Dim Process, strObject
IsProcessRunning = False
strObject = "winmgmts://" & strComputer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = True
Exit Function
End If
Next
End Function
wScript.Echo IsProcessRunning(".", "Photoshop.exe")

View File

@@ -6,5 +6,8 @@ if wScript.Arguments.Count = 0 then
else else
path = wScript.Arguments(0) path = wScript.Arguments(0)
args = wScript.Arguments(1) args = wScript.Arguments(1)
appRef.DoJavaScriptFile path, Split(args, ",") error = appRef.DoJavaScriptFile(path, Split(args, ","))
if Not error = "true" Then
Err.raise 1, "dojs.vbs", error
end if
end if end if

View File

@@ -1,5 +1,5 @@
#include lib.js #include lib.js
app.displayDialogs=DialogModes.NO
var stdout = newFile(arguments[0]); var stdout = newFile(arguments[0]);
var lyr = eval(arguments[1]); var lyr = eval(arguments[1]);
stdout.write(('{"Name":"' + lyr.name + '","Bounds":[[' + lyr.bounds[0] + ',' + stdout.write(('{"Name":"' + lyr.name + '","Bounds":[[' + lyr.bounds[0] + ',' +

View File

@@ -411,10 +411,10 @@ func (a *ArtLayer) SetPos(x, y int, bound string) {
a.bounds = lyr.bounds a.bounds = lyr.bounds
} }
func (a *ArtLayer) Refresh() { func (a *ArtLayer) Refresh() error {
tmp, err := Layer(a.Path()) tmp, err := Layer(a.Path())
if err != nil { if err != nil {
log.Panic(err) return err
} }
tmp.SetParent(a.Parent()) tmp.SetParent(a.Parent())
a.name = tmp.name a.name = tmp.name
@@ -423,6 +423,7 @@ func (a *ArtLayer) Refresh() {
a.parent = tmp.Parent() a.parent = tmp.Parent()
a.visible = tmp.visible a.visible = tmp.visible
a.current = true a.current = true
return nil
} }
type LayerSet struct { type LayerSet struct {
@@ -487,28 +488,20 @@ func (l *LayerSet) ArtLayer(name string) *ArtLayer {
for _, lyr := range l.artLayers { for _, lyr := range l.artLayers {
if lyr.name == name { if lyr.name == name {
if Mode == 0 && !lyr.current { if Mode == 0 && !lyr.current {
lyr.Refresh() err := lyr.Refresh()
/* if err != nil {
byt, err := DoJs("getLayer.jsx", JSLayer(lyr.Path())) l.Refresh()
if err != nil { }
log.Panic(err)
}
var lyr2 *ArtLayer
err = json.Unmarshal(byt, &lyr2)
if err != nil {
log.Panic(err)
}
lyr.name = lyr2.name
lyr.bounds = lyr2.bounds
lyr.visible = lyr2.visible
lyr.current = true
lyr.Text = lyr2.Text
*/
} }
return lyr return lyr
} }
} }
return nil l.Refresh()
for _, lyr := range l.artLayers {
fmt.Println(lyr)
}
lyr := l.ArtLayer(name)
return lyr
} }
func (l *LayerSet) LayerSets() []*LayerSet { func (l *LayerSet) LayerSets() []*LayerSet {
@@ -589,7 +582,11 @@ func (l *LayerSet) Refresh() {
} }
tmp.SetParent(l.Parent()) tmp.SetParent(l.Parent())
for _, lyr := range l.artLayers { for _, lyr := range l.artLayers {
lyr.Refresh() err := lyr.Refresh()
if err != nil {
l.artLayers = tmp.artLayers
break
}
} }
for _, set := range l.layerSets { for _, set := range l.layerSets {
set.Refresh() set.Refresh()