// ==PREPROCESSOR==
// @name "WSH panel. change file attributes"
// @author "kgena_ua"
// @feature "v1.4"
// @feature "watch-metadb"
// ==/PREPROCESSOR==
// press left mouse button to change
function RGB(r,g,b) { return (0xff000000|(r<<16)|(g<<8)|(b)); }
var font = gdi.Font("Arial",12, 1);
var ww, wh;
DT_LEFT = 0x00000000;
DT_WORD_ELLIPSIS = 0x00040000;
MF_ENABLED = 0x00000000;
var color = RGB(90, 90, 90);
var fso = new ActiveXObject("Scripting.FileSystemObject");
var rw = [], r0 = [];
var count;
on_item_focus_change();
function on_paint(gr){
var text1 = rw.length == 0 ? "" : rw.length + (rw.length > 1 ? " files are" : " file is") + " READ - WRITE";
var text2 = ro.length == 0 ? "" : ro.length + (ro.length > 1 ? " files are" : " file is") + " READ - ONLY";
var text3 = text1 ? text1 + "\n" + text2 : text2;
gr.GdiDrawText( text3, font, color, 10, 10, ww, wh, DT_LEFT | DT_WORD_ELLIPSIS );
}
function get_file_attributes() {
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
file_attributes = 0;
rw = [];
ro = [];
for (var i = 0; i < count; i++) {
item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
file_path = fb.Titleformat("%path%").EvalWithMetadb(item);
try {
file = fso.GetFile(file_path);
file_attributes = parseInt(file.Attributes);
switch (file_attributes) {
case 32:
rw.push(i);
break;
case 33:
ro.push(i);
break;
}
} catch(e) {};
}
window.Repaint();
}
function change_attributes(k) {
for (var i = 0; i < count; i++) {
item = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Item(i);
file_path = fb.Titleformat("%path%").EvalWithMetadb(item);
try {
file = fso.GetFile(file_path);
file.Attributes = k;
} catch(e) {};
}
get_file_attributes();
}
function on_selection_changed(metadb) {
on_item_focus_change();
}
function on_item_focus_change() {
window.Repaint();
count = plman.GetPlaylistSelectedItems(plman.ActivePlaylist).Count;
get_file_attributes();
}
function on_mouse_lbtn_up (x, y){
var _menu = window.CreatePopupMenu();
_menu.AppendMenuItem(MF_ENABLED, 10, "read write");
_menu.AppendMenuItem(MF_ENABLED, 20, "read only");
ret = _menu.TrackPopupMenu(x,y);
if (ret == 0) return;
switch (ret) {
case 10:
change_attributes(32);
break;
case 20:
change_attributes(33);
break;
}
_menu.Dispose();
}
function on_size(){
ww = window.Width;
wh = window.Height;
}