Skip to content

Instantly share code, notes, and snippets.

@958
Created January 22, 2009 02:28
Show Gist options
  • Save 958/50382 to your computer and use it in GitHub Desktop.
Save 958/50382 to your computer and use it in GitHub Desktop.
[Sleipnir]Backup Action
(function() {
// Backup directory path
var baseDir = 'd:\\temp\\backup\\';
// Use save dialog
var useDialog = false;
// make file name
var now = new Date();
var baseName =
((now.getYear() < 2000) ? (now.getYear() + 1900).toString() : now.getYear().toString()) +
((now.getMonth() < 9) ? '0' + (now.getMonth() + 1) : (now.getMonth() + 1).toString()) +
((now.getDate() < 10) ? '0' + now.getDate() : now.getDate().toString()) +
((now.getHours() < 10) ? '0' + now.getHours() : now.getHours().toString()) +
((now.getMinutes() < 10) ? '0' + now.getMinutes() : now.getMinutes().toString()) +
((now.getSeconds() < 10) ? '0' + now.getSeconds() : now.getSeconds().toString());
var fso = new ActiveXObject('Scripting.FileSystemObject');
var sh = new ActiveXObject('Shell.Application');
(function() { // settings
var fileName = baseDir + 'SleipnirSetting_' + baseName + '.zip';
var saveFile = showDialog(fileName);
if (saveFile == '') { return; }
var file = fso.CreateTextFile(saveFile, false);
file.Write('PK' + String.fromCharCode(5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
file.Close();
var dst = sh.NameSpace(fso.GetAbsolutePathName(saveFile));
var src = sh.NameSpace(sleipnir.UserFolder);
dst.CopyHere(src);
})();
(function() { // Seahorse scripts
var fileName = baseDir + 'SleipnirSeahorse_' + baseName + '.zip';
var saveFile = showDialog(fileName);
if (saveFile == '') { return; }
var file = fso.CreateTextFile(saveFile, false);
file.Write('PK' + String.fromCharCode(5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
file.Close();
var dst = sh.NameSpace(fso.GetAbsolutePathName(saveFile));
var src = sh.NameSpace(sleipnir.ScriptFullName.replace(sleipnir.ScriptName, '').replace(/\.js$/, '') + '..\\seahorse\\');
dst.CopyHere(src);
})();
(function() { // UserAction scripts
var fileName = baseDir + 'SleipnirUserAction_' + baseName + '.zip';
var saveFile = showDialog(fileName);
if (saveFile == '') { return; }
var file = fso.CreateTextFile(saveFile, false);
file.Write('PK' + String.fromCharCode(5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
file.Close();
var dst = sh.NameSpace(fso.GetAbsolutePathName(saveFile));
var src = sh.NameSpace(sleipnir.ScriptFullName.replace(sleipnir.ScriptName, '').replace(/\.js$/, '') + '..\\scripts\\');
dst.CopyHere(src);
})();
function showDialog(fileName) {
if (useDialog == false) {
return fileName;
}
try {
// SAFRCFileDlg.FileSave
var dlg = new ActiveXObject("SAFRCFileDlg.FileSave");
dlg.FileName = fileName;
dlg.FileType = '*.zip';
if (dig.OpenFileSaveDlg()) {
return dlg.FileName;
} else {
return '';
}
} catch(e) { }
try {
// MSComDlg.CommonDialog
var comDlg = new ActiveXObject("MSComDlg.CommonDialog");
comDlg.CancelError = true;
comDlg.MaxFileSize = 256;
comDlg.InitDir = baseDir;
comDlg.Filter = '*.zip|*.zip';
comDlg.FileName = fso.GetFileName(fileName);
comDlg.DefaultExt = 'zip';
try { comDlg.ShowSave(); } catch(e) { return ''; }
return comDlg.FileName;
} catch(e) { }
try {
// Excel.Application
var excel = new ActiveXObject("Excel.Application");
var ret = excel.GetSaveAsFileName(fileName, '*.zip,*.zip');
if (ret == false) { return ''; }
return ret;
} catch(e) { }
try {
// UserAccounts.CommonDialog
var dlg = new ActiveXObject("UserAccounts.CommonDialog")
dlg.InitialDir = baseDir;
dlg.FileName = fso.GetFileName(fileName);
dlg.Filter = '*.zip|*.zip';
dlg.Flags = 0x04;
if (dlg.ShowOpen()) {
return dlg.FileName;
} else {
return '';
}
} catch(e) { }
return fileName;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment