Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function GetContext()
- {
- var ctx = {
- source: Salamander.SourcePanel.Path,
- target: Salamander.TargetPanel.Path,
- files: []
- };
- var items = null;
- if (Salamander.SourcePanel.SelectedItems.Count > 0)
- {
- items = Salamander.SourcePanel.SelectedItems;
- }
- else if (Salamander.SourcePanel.FocusedItem &&
- Salamander.SourcePanel.FocusedItem.Name != "..")
- {
- items = new Array();
- items[0] = Salamander.SourcePanel.FocusedItem;
- }
- if (items == null)
- return ctx;
- for (var e = new Enumerator(items); !e.atEnd(); e.moveNext())
- {
- var item = e.item();
- if (!(item.Attributes & 16))
- {
- ctx.files.push(
- Salamander.SourcePanel.Path + "\\" + item.Name
- );
- }
- }
- return ctx;
- }
- function SerializeContext(ctx)
- {
- var s = "";
- s += "SRC=" + ctx.source + "\n";
- s += "DEST=" + ctx.target + "\n";
- for (var i = 0; i < ctx.files.length; i++)
- {
- s += "FILE=" + ctx.files[i] + "\n";
- }
- return s;
- }
- function Main()
- {
- var ctx = GetContext();
- if (ctx.files.length == 0)
- {
- Salamander.MsgBox("Nie sú vybrané žiadne súbory.");
- return;
- }
- var json = SerializeContext(ctx);
- var shell = new ActiveXObject("WScript.Shell");
- var exec = shell.Exec(
- 'python "C:\\Users\\Admin\\Documents\\PythonAPI.py"'
- );
- exec.StdIn.Write(json);
- exec.StdIn.Close();
- while (exec.Status == 0)
- {
- Salamander.Sleep(50);
- }
- var result = exec.StdOut.ReadAll();
- result = result.replace(/^\s+|\s+$/g, "");
- if (result.indexOf("TARGET|") == 0)
- {
- Salamander.TargetPanel.Path =
- result.substr(7);
- }
- else
- {
- Salamander.MsgBox(result, 32, "Python");
- }
- }
- Main();
Advertisement
Add Comment
Please, Sign In to add comment