From 86a428abe0cdc904876281f512a0cd53cc745818 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 20 Aug 2018 17:13:28 -0400 Subject: [PATCH] Fixed doc.Dump? --- v2/Test.json | 79 ++++++++++++++++++++++++ v2/Test.psd | Bin 96116 -> 123604 bytes v2/document.go | 10 ++- v2/ps.go | 1 + v2/runner/scripts/activeDocFullName.jsx | 2 + v2/runner/scripts/test.jsx | 1 + v2/test.log | 10 +++ 7 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 v2/Test.json create mode 100644 v2/runner/scripts/activeDocFullName.jsx create mode 100644 v2/test.log diff --git a/v2/Test.json b/v2/Test.json new file mode 100644 index 0000000..33e857c --- /dev/null +++ b/v2/Test.json @@ -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": [] + } + ] +} \ No newline at end of file diff --git a/v2/Test.psd b/v2/Test.psd index 129ebca3fdb94b0963d0e99bf445aaaac1a66a91..1e1b817c9a36dc2c33fe7674022aee199c316c71 100644 GIT binary patch delta 3542 zcmezJj`hk>_6Z7lha)VUJbhVM7(l>WhB1nPSz6T{7d=r=Mdq$ZT-Lq&tE{K7Z1NCI z_F@C;R{?3CEwwT46C;;}u8~2Ap}CcT<>V|T8zk=L4NTh^6$~vc+}te944hmXOI6%8X|0UB44XB z`C45_(`safaIh=+T0!wmbi5i_8JWXvbuu8uR%0t;M7%n=np&8dx;heN6r!pD|&5h`eTEWq?Qt&L-q*H6>9iA|*JRk*3wi7!kJS zpvAz!O2iCPh5sG%EaT1^mIjSR@wYDl71 zL=HDHB1NmIl@TIxjEu?GYC@t`Q+Pr&G9^tbQj#z-BU`JbsgsF;iLoJZ3DFd}TD3GI zMXQ;W0iqzZG$&uH1!1i`@G{iQ%3yK=_X%(_z|xYiPDH6@W@U)TbC!$Q7aZ=CquGz8WGkBPr*j!R;Gxw(f}7A`%3lt_(;ka{nie+u3mQBAXAwMuH*?3=E763=9hx7#Ok{ z7#JTgFq~Mxz##C0L4twt|Be5Tcp^NVo#O+7{M|f#Tp1V{CmXmpGcs&0abe-vyeVJ_ XE0=|pk%0oZo7J2Uwml(?QA7~{{f~ts delta 167 zcmca|l>N&))(HxH;Xf>#JbhVM7(hULqMwQk(`gRByz4(#6*kIW@-cqB1T3!tlD0A4 z*!PKXatXKS2beXTqv7mA8(KEl$%zF9xJ(twd+^NQIY zgcVqJF)%PNGB7YKU|?X#W?*1^z`$@~0RsceJO&8{#{V}q3+-9L%4KF{Xry3dWMyR7 NeBj{r0|yyJ6al++G<5&~ diff --git a/v2/document.go b/v2/document.go index 805fed9..20d887c 100644 --- a/v2/document.go +++ b/v2/document.go @@ -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) } diff --git a/v2/ps.go b/v2/ps.go index 1d2105f..69e8a2d 100644 --- a/v2/ps.go +++ b/v2/ps.go @@ -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 diff --git a/v2/runner/scripts/activeDocFullName.jsx b/v2/runner/scripts/activeDocFullName.jsx new file mode 100644 index 0000000..fbf3b13 --- /dev/null +++ b/v2/runner/scripts/activeDocFullName.jsx @@ -0,0 +1,2 @@ +#include lib.js +var stdout = newFile(arguments[0]);stdout.writeln(app.activeDocument.fullName);stdout.close(); \ No newline at end of file diff --git a/v2/runner/scripts/test.jsx b/v2/runner/scripts/test.jsx index 280da5f..df892c5 100644 --- a/v2/runner/scripts/test.jsx +++ b/v2/runner/scripts/test.jsx @@ -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]); diff --git a/v2/test.log b/v2/test.log new file mode 100644 index 0000000..0daa85a --- /dev/null +++ b/v2/test.log @@ -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