Fixed doc.Dump?

This commit is contained in:
Unknown
2018-08-20 17:13:28 -04:00
parent f64ea7a84c
commit 86a428abe0
7 changed files with 100 additions and 3 deletions

79
v2/Test.json Normal file
View File

@@ -0,0 +1,79 @@
{
"Name": "Test.psd",
"FullName": "~/go/src/github.com/sbrow/ps/v2/Test.psd",
"Height": 600,
"Width": 900,
"ArtLayers": [
{
"Name": "Background",
"Bounds": [
[
0,
0
],
[
900,
600
]
],
"Color": [
0,
0,
0
],
"Stroke": [
0,
0,
0
],
"StrokeAmt": 0,
"Visible": true,
"TextItem": null
}
],
"LayerSets": [
{
"Name": "Group 1",
"Bounds": [
[
0,
0
],
[
0,
0
]
],
"Visible": true,
"ArtLayers": [
{
"Name": "Layer 1",
"Bounds": [
[
222,
290
],
[
472,
454
]
],
"Color": [
0,
0,
0
],
"Stroke": [
0,
0,
0
],
"StrokeAmt": 0,
"Visible": true,
"TextItem": null
}
],
"LayerSets": []
}
]
}

Binary file not shown.

View File

@@ -130,16 +130,16 @@ func ActiveDocument() (*Document, error) {
log.Println("Loading ActiveDocument")
d := &Document{}
byt, err := DoJS("activeDocName.jsx")
byt, err := DoJS("activeDocFullName.jsx")
if err != nil {
return nil, err
}
d.name = strings.TrimRight(string(byt), "\r\n")
d.fullName = strings.TrimRight(string(byt), "\r\n")
if Mode != Safe {
err = d.Restore(d.DumpFile())
switch {
case os.IsNotExist(err):
log.Println("Previous version not found.")
log.Printf("Previous version not found: \"%s\"\n", d.DumpFile())
case err == nil:
return d, err
default:
@@ -202,6 +202,10 @@ func (d *Document) DumpFile() string {
log.Println(err)
}
path := filepath.Join(strings.Replace(d.fullName, "~", usr.HomeDir, 1))
path = strings.TrimPrefix(path, `\`)
path = strings.Replace(path, `[^:]\`, `:\`, 1)
drive := filepath.VolumeName(path)
path = strings.Replace(path, drive, strings.ToUpper(drive), 1)
return strings.Replace(path, ".psd", ".json", 1)
}

View File

@@ -141,6 +141,7 @@ func Quit(save SaveOption) error {
}
// SaveAs saves the Photoshop document to the given location.
// // TODO(sbrow): doesn't return error on non-existant path.
func SaveAs(path string) error {
_, err := runner.Run("save", path)
return err

View File

@@ -0,0 +1,2 @@
#include lib.js
var stdout = newFile(arguments[0]);stdout.writeln(app.activeDocument.fullName);stdout.close();

View File

@@ -1,4 +1,5 @@
#include lib.js
alert(app.activeDocument.path)
var f = newFile(arguments[0]);
for (var i = 0; i < arguments.length; i++) {
f.writeln(arguments[i]);

10
v2/test.log Normal file
View File

@@ -0,0 +1,10 @@
2018/08/20 17:09:51 Loading ActiveDocument
2018/08/20 17:09:51 Previous version not found: "C:\Users\Spencer\go\src\github.com\sbrow\ps\v2\Test.json"
2018/08/20 17:09:51 Loading manually (This could take awhile)
2018/08/20 17:09:51 Loading ActiveDocument/Group 1/
2018/08/20 17:09:51 Dumping to disk
2018/08/20 17:09:51 C:\Users\Spencer\go\src\github.com\sbrow\ps\v2\Test.json
2018/08/20 17:09:52 Dumping to disk
2018/08/20 17:09:52 C:\Users\Spencer\go\src\github.com\sbrow\ps\v2\Test.json
2018/08/20 17:09:52 Loading ActiveDocument
2018/08/20 17:09:52 Previous version found, loading