// Explore // Updated 10-Dec-2016 // Maksim Terpilovsky's script // http://terpilovsky.ru DT_TOP = 0x00000000; DT_LEFT = 0x00000000; DT_CENTER = 0x00000001; DT_RIGHT = 0x00000002; DT_VCENTER = 0x00000004; DT_BOTTOM = 0x00000008; DT_WORDBREAK = 0x00000010; DT_SINGLELINE = 0x00000020; DT_EXPANDTABS = 0x00000040; DT_TABSTOP = 0x00000080; DT_NOCLIP = 0x00000100; DT_EXTERNALLEADING = 0x00000200; DT_CALCRECT = 0x00000400; DT_NOPREFIX = 0x00000800; DT_INTERNAL = 0x00001000; DT_EDITCONTROL = 0x00002000; DT_PATH_ELLIPSIS = 0x00004000; DT_END_ELLIPSIS = 0x00008000; DT_MODIFYSTRING = 0x00010000; DT_RTLREADING = 0x00020000; DT_WORD_ELLIPSIS = 0x00040000; DT_NOFULLWIDTHCHARBREAK = 0x00080000; DT_HIDEPREFIX = 0x00100000; DT_PREFIXONLY = 0x00200000; MF_SEPARATOR = 0x00000800; MF_ENABLED = 0x00000000; MF_GRAYED = 0x00000001; MF_DISABLED = 0x00000002; MF_UNCHECKED = 0x00000000; MF_CHECKED = 0x00000008; MF_STRING = 0x00000000; MF_POPUP = 0x00000010; MF_MENUBARBREAK = 0x00000020; MF_MENUBREAK = 0x00000040; var Drives = []; var Folders = []; var Files = []; var e, x, drag = 0; var fso = new ActiveXObject("Scripting.FileSystemObject"); var WshShell = new ActiveXObject("WScript.Shell"); var scrollbar_center = 25; var my_ini_values = {}; function drive( letter, type, name) { this.letter = letter; this.type = type; this.name = name; } function folder( path, name) { this.path = path; this.name = name; } function fileadd( name, size, type, path, attr) { this.name = name; this.size = size; this.type = type; this.path = path; this.attr = attr; } function in_array(a,b) { s = a.join('|'); s = '|' + s + '|'; return ( s.indexOf('|' + b + '|') == -1 ? false : true); } function my_ini_write(text) { var fso, f, r, write = text; var ForWriting = 2; fso = new ActiveXObject("Scripting.FileSystemObject"); var filename = fb.FoobarPath + "s7e.data"; try { f = fso.OpenTextFile(filename, ForWriting, true, -1) f.Write(write); f.Close(); } catch(e) { } } function object2string(obj) { var val, output = ""; if (obj) { for (var i in obj) { val = obj[i]; switch (typeof val) { case ("string"): output += i + "=" + val + "\r"; break; default: output += i + "=" + val + "\r"; } } output = output.substring(0, output.length-1); } return output; } function my_ini_read() { var fso, f, r, b; var ForReading = 1, ForWriting = 2; var filename = fb.FoobarPath + "s7e.data"; fso = new ActiveXObject("Scripting.FileSystemObject"); if ( fso.FileExists(filename) ) { file = fso.GetFile(filename); filecont = file.OpenAsTextStream(ForReading, -1); if ( typeof filecont == 'object' ) { r = filecont.ReadAll(); var a = r.split("\n"); for (key in a) { b = a[key].split("="); my_ini_values[b[0]] = b[1]; } return my_ini_values; } else return {}; } else return {}; } var my_ini = my_ini_read(); function Explore() { this.ShowHidden = parseInt( utils.ReadINI(fb.FoobarPath + 's7e.ini', 'explore', 'showhidden', '0') ); this.ShowOnlySupported = parseInt( utils.ReadINI(fb.FoobarPath + 's7e.ini', 'explore', 'showonlysupported', '1') ); this.ScrollShow = parseInt( utils.ReadINI(fb.FoobarPath + 's7e.ini', 'explore', 'showscrollbar', '0') ); this.Sync = parseInt( utils.ReadINI(fb.FoobarPath + 's7e.ini', 'explore', 'sync', '0') ); this.SyncMode = parseInt( utils.ReadINI(fb.FoobarPath + 's7e.ini', 'explore', 'syncmode', '0') ); this.RecentPaths = my_ini && my_ini.recentpaths !== false ? my_ini.recentpaths : ''; if ( this.Sync == 1 && this.SyncMode == 0 ) on_item_focus_change(); else if ( this.Sync == 1 ) on_playback_new_track(); this.ListDrives = function() { e = new Enumerator(fso.Drives); for (; !e.atEnd(); e.moveNext()) { x = e.item(); if (x.IsReady) { Drives.push( new drive( x.DriveLetter, x.DriveType, x.VolumeName) ); } } this.UpdateHeight(); } this.ListFiles = function( dir, prnt ) { var item, fn, f = false, fp = false; dir += '\\'; if ( fso.FolderExists( dir ) ) { fp = fso.GetFolder( dir ); f = prnt ? fp.ParentFolder : fp; } else { parent = dir.split('\\'); for ( i = parent.length; i >= 0; i-- ) { parent.pop(); path = parent.join('\\'); if ( fso.FolderExists( path) ) { fp = fso.GetFolder( path ); f = prnt ? fp.ParentFolder : fp; break; } else continue; } } if ( fp && prnt && fp.IsRootFolder ) { this.Mode = 'default'; this.Reset(); this.ListDrives(); } else if ( f ) { this.CurrentFolder = f.Path; fc = new Enumerator( f.SubFolders ); for (; !fc.atEnd(); fc.moveNext()) { item = fc.item(); if ( this.ShowHidden == 0 ) { attr = item.Attributes >= 1024 ? item.Attributes - 1040 : item.Attributes - 16; if ( attr != 2 && attr != 3 && attr != 6 && attr != 7 ) Folders.push( new folder( item.Path, item.Name ) ); } else Folders.push( new folder( item.Path, item.Name ) ); } Folders.sort(function(a,b) { var x = a.name.toLowerCase(); var y = b.name.toLowerCase(); return x < y ? -1 : x > y ? 1 : 0; }); Folders.unshift( new folder( dir, '..' ) ); //f = fso.GetFolder( dir ); fc = new Enumerator(f.Files); Files = new Array(); for (; !fc.atEnd(); fc.moveNext()) { item = fc.item(); if ( this.ShowOnlySupported == 1 ) { fn = fc.item().Name; regexp = /(.*)\.(\w+)$/ig; ext = fn.replace(regexp, "$2"); exts = "8|669|7z|8svx|aac|ac3|adp|afc|ahx|aif|aifc|aiff|amf|ape|apl|asf|asx|au|brr|bw|cda|cdx|cue|dsm|dsp|dts|dtswav|eam|fla|flac|flv|fpl|gbs|gcm|gym|hes|hps|hvl|idsp|it|j2b|jma|kss|kwf|lha|m3u|m3u8|m4a|m4b|m4r|mac|map|midi|mka|mod|mp+|mp1|mp2|mp3|mp4|mpc|mpf|mpp|mss|mtm|mus|nsf|nsfe|nwa|oga|ogg|ogx|opus|org|pcm|pls|psm|ptm|px|qsf|rxw|s3m|sap|snd|sng|spc|spd|spt|spu|spx|stm|str|svx|tfmx|umx|unix|vgm|w64|waf|wav|wave|wax|wdt|wma|wpd|wv|wvx|xm|zip|677"; r = exts.match( ext.toLowerCase() ); if ( r != null) { if ( this.ShowHidden == 0 ) { attr = item.Attributes >= 2048 ? item.Attributes - 2048 : ( item.Attributes >= 1024 ? item.Attributes - 1024 : (item.Attributes >= 32 ? item.Attributes - 32 : item.Attributes ) ); if ( attr != 2 && attr != 3 && attr != 6 && attr != 7 ) Files.push( new fileadd( item.Name, item.Size, item.Type, item.Path, item.Attributes ) ); } else Files.push( new fileadd( fc.item().Name, fc.item().Size, fc.item().Type, fc.item().Path, fc.item().Attributes ) ); } } else if ( this.ShowHidden == 0 ) { attr = item.Attributes >= 2048 ? item.Attributes - 2048 : (item.Attributes >= 1024 ? item.Attributes - 1024 : (item.Attributes >= 32 ? item.Attributes - 32 : item.Attributes ) ) ; if ( attr != 2 && attr != 3 && attr != 6 && attr != 7 ) Files.push( new fileadd( fc.item().Name, fc.item().Size, fc.item().Type, fc.item().Path, fc.item().Attributes ) ); } else Files.push( new fileadd( fc.item().Name, fc.item().Size, fc.item().Type, fc.item().Path, fc.item().Attributes ) ); } Files.sort(function(a,b) { var x = a.name.toLowerCase(); var y = b.name.toLowerCase(); return x < y ? -1 : x > y ? 1 : 0; }); } else { this.Mode = 'default'; this.Reset(); this.ListDrives(); } Explore.UpdateHeight(); } this.Reset = function() { Drives = []; Folders = []; Files = []; this.Offset = 0; } this.ResetList = function() { Drives = []; Folders = []; Files = []; } this.Update = function(path) { regexp = /(.*)\\(.*)\.(\w+)$/ig; folderpath = path.replace(regexp, "$1"); this.Reset(); this.Mode = 'folder'; this.CurrentFolder = folderpath + '\\'; this.ListFiles( Explore.CurrentFolder ); window.Repaint(); } this.UpdateHeight = function() { if ( this.Mode == 'default' ) this.Height = (Drives.length + 1) * 24; else this.Height = (Folders.length + Files.length + 1) * 24; } this.AddRecent = function( path ) { var a = this.RecentPaths ? this.RecentPaths.split('|') : new Array(); if ( !in_array( a, path ) ) { if ( a.length < 15 ) { a.push( path ); } else { a = a.reverse(); a.pop(); a = a.reverse(); a.push( path ); } a = a.join('|'); this.RecentPaths = my_ini.recentpaths = a; my_ini_write( object2string( my_ini ) ); } else { for ( z = 0; z < a.length; z++ ) { if ( a[z] == path ) { one = a.slice(0, z); two = a.slice(z+1); a = one.concat(two); a.push( path ); a = a.join('|'); this.RecentPaths = my_ini.recentpaths = a; my_ini_write( object2string( my_ini ) ); } } } } this.Mode = 'default'; this.ListDrives(); this.CurrentFolder = ''; this.Offset = 0; this.Hover = false; this.Data = false; this.Y1 = 0; this.Y2 = 0; this.X = 0; this.Y = 0; this.ScrollbarAdd = 0; this.Height = 0; this.Updated = false; } var Explore = new Explore(); var g_font = gdi.Font("Segoe UI", 12, 0); try { var compress = gdi.Image(fb.FoobarPath + "s7e_files\\images\\compress.png"); var folder_icon = gdi.Image(fb.FoobarPath + "s7e_files\\images\\folder.png"); var system_icon = gdi.Image(fb.FoobarPath + "s7e_files\\images\\system.png"); var drive_icon = gdi.Image(fb.FoobarPath + "s7e_files\\images\\drive.png"); var arrow_left = gdi.Image(fb.FoobarPath + "s7e_files\\images\\backwards.png"); var file_icon = gdi.Image(fb.FoobarPath + "s7e_files\\images\\page_music.png"); var cross = gdi.Image(fb.FoobarPath + "s7e_files\\images\\cross_black.png"); var opened_folder = gdi.Image(fb.FoobarPath + "s7e_files\\images\\opened_folder.png"); } catch(e) { } function RGBA(r, g, b, a) { return ((a << 24) | (r << 16) | (g << 8) | (b)); } function RGB(r, g, b) { return (0xff000000 | (r << 16) | (g << 8) | (b)); } ColorTypeCUI = { text: 0, selection_text: 1, inactive_selection_text: 2, background: 3, selection_background: 4, inactive_selection_background: 5, active_item_frame: 6 }; ColorTypeDUI = { text: 0, background: 1, highlight: 2, selection: 3 }; function get_color(){ if (window.InstanceType == 0){ norm_txt = window.GetColorCUI(ColorTypeCUI.text); sel_txt = window.GetColorCUI(ColorTypeCUI.selection_text); inactive_sel_txt = window.GetColorCUI(ColorTypeCUI.inactive_selection_text); bgcolor = window.GetColorCUI(ColorTypeCUI.background); sel_bgcolor = window.GetColorCUI(ColorTypeCUI.selection_background); inactive_sel_bgcolor = window.GetColorCUI(ColorTypeCUI.inactive_selection_background); active_itemframe = window.GetColorCUI(ColorTypeCUI.active_item_frame); } else if (window.InstanceType == 1) { bgcolor = window.GetColorDUI(ColorTypeDUI.background); select = window.GetColorDUI(ColorTypeDUI.highlight); inactive = window.GetColorDUI(ColorTypeDUI.text); } window.Repaint(); }; get_color(); function on_colors_changed(){ get_color(); } function on_paint( gr ) { !window.IsTransparent && gr.FillSolidRect(0, 0, window.Width, window.Height, bgcolor); var i; if ( Explore.Mode == 'folder' ) { gr.GdiDrawText( Explore.CurrentFolder, g_font, sel_txt, 25, 5 - Explore.Offset, window.Width - 30, window.Height, DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); if ( opened_folder ) gr.DrawImage( (Explore.Hover == -1 && Explore.Data == 1 ) ? cross : opened_folder, 5, 5 - Explore.Offset, 16, 16, 0, 0, 16, 16, 0, 100); for ( i = 1; i <= Folders.length; i++ ) { gr.FillSolidRect(0, i * 24 - Explore.Offset, window.Width, 24, ( Explore.Hover !== false && i - 1 - Explore.Hover == 0) ? RGBA(255,255,255,20) : ( i % 2 == 1 ? RGBA(255,255,255,10) : inactive_sel_bgcolor) ); gr.GdiDrawText( Folders[i-1].name, g_font, norm_txt, 25, 5 + i * 24 - Explore.Offset, window.Width - 30, window.Height, DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); gr.DrawRect(-1, i * 24 - Explore.Offset, window.Width + 2, 24, 1, inactive_sel_bgcolor ); if ( folder_icon && cross && arrow_left ) gr.DrawImage( ( Explore.Hover !== false && Explore.Data == 1 && i - 1 - Explore.Hover == 0 ) ? cross : (i == 1 ? arrow_left : folder_icon), 5, 5 + i * 24 - Explore.Offset, 16, 16, 0, 0, 16, 16, 0, 100); } for ( a = 0; a < Files.length; a++ ) { gr.FillSolidRect(0, (i + a) * 24 - Explore.Offset, window.Width, 24, ( Explore.Hover !== false && ( i + a - 1 ) - Explore.Hover == 0 ) ? RGBA(255,255,255,20) : ( (i + a) % 2 == 1 ? RGBA(255,255,255,10) : inactive_sel_bgcolor) ); gr.GdiDrawText( Files[a].name, g_font, norm_txt, 25, 5 + (i + a) * 24 - Explore.Offset, window.Width - 30, window.Height, DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); gr.DrawRect(-1, (i + a) * 24 - Explore.Offset, window.Width + 2, 24, 1, inactive_sel_bgcolor); if ( file_icon && cross ) gr.DrawImage( ( Explore.Hover !== false && Explore.Data == 1 && ( i + a - 1 ) - Explore.Hover == 0 ) ? cross : file_icon, 5, 5 + (i + a) * 24 - Explore.Offset, 16, 16, 0, 0, 16, 16, 0, 100); } Explore.Height = (Folders.length + Files.length + 1) * 24; } else { if ( system_icon ) gr.DrawImage( system_icon, 5, 5 - Explore.Offset, 16, 16, 0, 0, 16, 16, 0, 100); gr.GdiDrawText( 'Computer:', g_font, norm_txt, 25, 5 - Explore.Offset, window.Width - 30, window.Height, DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS); for ( a = 1; a <= Drives.length; a++ ) { gr.FillSolidRect(0, 1 + a * 24 - Explore.Offset, window.Width, 24, ( Explore.Hover !== false && a - 1 - Explore.Hover == 0 ) ? RGBA(255,255,255,20) : (a % 2 == 1 ? RGBA(255,255,255,10) : inactive_sel_bgcolor)); gr.GdiDrawText( Drives[a-1].name + ' (' + Drives[a-1].letter + ':)', g_font, norm_txt, 25, 5 + a * 24 - Explore.Offset, window.Width - 30, window.Height, DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS); gr.DrawRect(-1, a * 24 - Explore.Offset, window.Width + 2, 24, 1, inactive_sel_bgcolor); if ( drive_icon ) gr.DrawImage( drive_icon, 5, 5 + a * 24 - Explore.Offset, 16, 16, 0, 0, 16, 16, 0, 100); } Explore.Height = (Drives.length + 1) * 24; } Explore.ScrollbarAdd = Math.round( window.Height / ( Explore.Height / window.Height ) / 2); if ( Explore.Height > window.Height ) { scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / (Explore.Height - window.Height) ); if ( Explore.ScrollShow || Explore.Hover !== false ) { gr.FillRoundRect( window.Width - 4, (scrollbar_center < Explore.ScrollbarAdd) ? 0 : ( ( window.Height - scrollbar_center < Explore.ScrollbarAdd) ? (window.Height - (Explore.ScrollbarAdd * 2)) : (scrollbar_center - Explore.ScrollbarAdd)), 2, Explore.ScrollbarAdd * 2, 1, 1, drag == 1 ? RGB(155, 155, 155) : RGB(215, 215, 215)); gr.DrawRoundRect( window.Width - 4, (scrollbar_center < Explore.ScrollbarAdd) ? 0 : ( ( window.Height - scrollbar_center < Explore.ScrollbarAdd) ? (window.Height - (Explore.ScrollbarAdd * 2)) : (scrollbar_center - Explore.ScrollbarAdd)), 2, Explore.ScrollbarAdd * 2, 1, 1, 1, drag == 1 ? RGB(155, 155, 155) : RGB(215, 215, 215)); } } } function on_mouse_move(x, y) { Explore.X = x; Explore.Y = y; var row = Math.floor( (y + Explore.Offset) / 24 ) - 1; var data = ( x < 25 ) ? 1 : ( x > window.Width - 25 ? 2 : 0); Explore.Y2 = y; if ( Explore.Height > window.Height && Explore.Y1 != 0 && Math.abs(Explore.Y1 - Explore.Y2) > 0 ) { var y_diff = ( Explore.Y1 - Explore.Y2 ); ( Explore.Offset + y_diff > Explore.Height - window.Height ) ? Explore.Offset = Explore.Height - window.Height : ( ( Explore.Offset + y_diff < 0 ) ? Explore.Offset = 0 : Explore.Offset = Explore.Offset + y_diff ); scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / (Explore.Height - window.Height) ); Explore.Y1 = Explore.Y2; drag = 1; window.Repaint(); } else { if ( Explore.Mode == 'default' && ((Explore.Hover != row && typeof Explore.Hover == 'number') || Explore.Hover === false) ) { //fb.trace( 'row = ' + row + ' Explore.Data = ' + Explore.Data + ' Explore.Hover = ' + Explore.Hover ); if ( Drives[row] ) { Explore.Hover = row; Explore.Data = 0; window.SetCursor(32649); window.Repaint(); } else { Explore.Hover = false; window.SetCursor(32512); window.Repaint(); } } else if ( Explore.Mode == 'folder' && ( Explore.Data != data || (Explore.Hover != row && typeof Explore.Hover == 'number') || Explore.Hover === false) ) { //fb.trace( 'row = ' + row + ' Explore.Data = ' + Explore.Data + ' Explore.Hover = ' + Explore.Hover ); if ( Folders[row] || Files[row - Folders.length] || row == -1 ) { Explore.Hover = row; Explore.Data = row == 0 ? 0 : ( row == -1 ? 1 : ( Files[row - Folders.length] ? 1 : data )); window.SetCursor(32649); window.Repaint(); } else { Explore.Hover = false; window.SetCursor(32512); window.Repaint(); } } } if ( Explore.Updated === false ) { Explore.Updated = true; Explore.ResetList(); if ( Explore.Mode == 'default' ) { Explore.ListDrives(); } else { Explore.ListFiles( Explore.CurrentFolder ); } if ( Explore.Offset > Explore.Height - window.Height ) Explore.Offset = 0; window.Repaint(); } } function on_mouse_leave() { Explore.Hover = false; Explore.Data = false; Explore.Updated = false; Explore.Y1 = 0; Explore.Y2 = 0; Explore.X = 0; Explore.Y = 0; drag = 0; window.Repaint(); } function on_mouse_lbtn_down( x, y) { Explore.Y1 = y; drag = 0; } function on_mouse_lbtn_up( x, y) { Explore.Y2 = y; //fb.trace( 'Explore.Y1 = ' + Explore.Y1 + " Explore.Y2 = " + Explore.Y2 ); if ( Explore.Data == 0 && !drag && Explore.Y1 == Explore.Y2 ) { var pressed = Math.floor( (y + Explore.Offset) / 24 ) - 1; if ( Explore.Mode == 'default' && Drives[pressed] ) { Explore.Mode = 'folder'; Explore.CurrentFolder = Drives[pressed].letter + ':'; Explore.Reset(); Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } else if ( Explore.Mode == 'folder' ) { if ( pressed == 0 ) { Explore.Reset(); Explore.ListFiles( Explore.CurrentFolder, true ); window.Repaint(); } else if ( Folders[pressed] ) { Explore.Mode = 'folder'; Explore.CurrentFolder = Folders[pressed].path; Explore.Reset(); Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } else if ( Files[pressed - Folders.length] ) { Explore.AddRecent( Explore.CurrentFolder ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Files[pressed - Folders.length].path + '" /immediate'); } } } else if ( Explore.Data == 1 && Explore.Mode == 'folder' && !drag && Explore.Y1 == Explore.Y2 ) { var pressed = Math.floor( (y + Explore.Offset) / 24 ) - 1; if ( pressed == -1 ) { Explore.AddRecent( Explore.CurrentFolder ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Explore.CurrentFolder + '" /immediate'); } else if ( Folders[pressed] ) { Explore.AddRecent( Folders[pressed].path ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Folders[pressed].path + '" /immediate'); } else if ( Files[pressed - Folders.length] ) { Explore.AddRecent( Explore.CurrentFolder ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Files[pressed - Folders.length].path + '" /immediate'); } window.Repaint(); } drag = 0; Explore.Y1 = 0; Explore.Y2 = 0; } function on_mouse_wheel( delta ) { if ( delta < 0 && Explore.Offset < Explore.Height - window.Height) { ( Explore.Offset - delta * 25 > Explore.Height - window.Height ) ? Explore.Offset = Explore.Height - window.Height : Explore.Offset -= delta * 25; scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / ( Explore.Height - window.Height) ); Explore.Hover = false; on_mouse_move( Explore.X, Explore.Y); } else if ( delta > 0 && Explore.Offset > 0 ) { ( Explore.Offset - delta * 25 > 0 ) ? Explore.Offset -= delta * 25 : Explore.Offset = 0; scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / ( Explore.Height - window.Height) ); Explore.Hover = false; on_mouse_move( Explore.X, Explore.Y); } } function on_mouse_rbtn_up( x, y ) { var _menu = window.CreatePopupMenu(); var i = 1; var ret; var _firstgroup = window.CreatePopupMenu(); var _secondgroup = window.CreatePopupMenu(); var _thirdgroup = window.CreatePopupMenu(); var _fourthgroup = window.CreatePopupMenu(); var _fifthgroup = window.CreatePopupMenu(); var pressed = Math.floor( (y + Explore.Offset) / 24 ) - 1; _firstgroup.AppendMenuItem(MF_STRING, i++, "Show hidden files and folder"); _firstgroup.CheckMenuItem( i-1, Explore.ShowHidden ); _firstgroup.AppendMenuItem(MF_STRING, i++, "Show only supported files"); _firstgroup.CheckMenuItem( i-1, Explore.ShowOnlySupported ); _firstgroup.AppendMenuSeparator(); _firstgroup.AppendMenuItem(MF_STRING, i++, "Show scrollbar constantly"); _firstgroup.CheckMenuItem( i-1, Explore.ScrollShow ); _secondgroup.AppendMenuItem(MF_STRING, i++, "Sync panel with playlist"); _secondgroup.CheckMenuItem( i-1, Explore.Sync ); _secondgroup.AppendMenuSeparator(); _secondgroup.AppendMenuItem(MF_STRING, i++, "Focused item"); _secondgroup.AppendMenuItem(MF_STRING, i++, "Now playling item"); _secondgroup.CheckMenuRadioItem(i-2, i-1, Explore.SyncMode + i-2, bypos = false); if ( Explore.Sync == 0 ) { _secondgroup.EnableMenuItem( i-1, 1); _secondgroup.EnableMenuItem( i-2, 1); } try { checkroot = fso.GetFolder(Explore.CurrentFolder).IsRootFolder; } catch(e) { checkroot = false; } var p = Explore.RecentPaths ? Explore.RecentPaths.split('|') : new Array(); if ( p.length > 0 ) { for ( r = p.length - 1; r > -1 ; r-- ) _thirdgroup.AppendMenuItem(MF_STRING, i++, p[r] ); _thirdgroup.AppendMenuSeparator(); _thirdgroup.AppendMenuItem(MF_STRING, i++, 'Clear list' ); } _fourthgroup.AppendMenuItem(MF_STRING, i++, "... it now"); if ( Explore.Mode == 'folder' ) { if ( (checkroot || pressed != -1) && ( ( (!Folders[pressed] && !Files[pressed - Folders.length]) || ( Folders.length + Files.length < 1 ) ) || pressed == 0 ) ) { _fourthgroup.EnableMenuItem( i-1, 1); var turnoff_enq = true; } else var turnoff_enq = false; } else var turnoff_enq = true; _firstgroup.AppendTo( _menu, MF_STRING, "Display settings"); _secondgroup.AppendTo( _menu, MF_STRING, "Sync settings"); _menu.AppendMenuSeparator(); _thirdgroup.AppendTo( _menu, MF_STRING | ( p.length < 1 ? MF_DISABLED : MF_ENABLED ), "Recent paths"); _fourthgroup.AppendTo( _menu, MF_STRING | ( turnoff_enq ? MF_DISABLED : MF_ENABLED ) , "Delete..."); _menu.AppendMenuSeparator(); _menu.AppendMenuItem(MF_STRING, i++, "Enqueue"); _menu.AppendMenuItem(MF_STRING, i++, "Clear playlist and enqueue"); _menu.AppendMenuItem(MF_STRING, i++, "Create a new playlist and enqueue"); if ( turnoff_enq ) _menu.EnableMenuItem( i-3, 1); if ( turnoff_enq ) _menu.EnableMenuItem( i-2, 1); if ( turnoff_enq ) _menu.EnableMenuItem( i-1, 1); _menu.AppendMenuSeparator(); _menu.AppendMenuItem(MF_STRING, i++, "Go top"); _menu.AppendMenuItem(MF_STRING, i++, "Go bottom"); if ( Explore.Height < window.Height ) { _menu.EnableMenuItem( i-2, 1); _menu.EnableMenuItem( i-1, 1); } _menu.AppendMenuSeparator(); _menu.AppendMenuItem(MF_STRING, i++, "Go back"); _menu.AppendMenuItem(MF_STRING, i++, "Go root"); if ( checkroot ) { _menu.EnableMenuItem( i-1, 1); } _menu.AppendMenuItem(MF_STRING, i++, "Show drives"); if ( Explore.Mode == 'default' ) { _menu.EnableMenuItem( i-1, 1); _menu.EnableMenuItem( i-2, 1); _menu.EnableMenuItem( i-3, 1); } _menu.AppendMenuSeparator(); _menu.AppendMenuItem(MF_STRING, i++, "Open" + ( Explore.Mode == 'default' ? ' drive' : ' folder' )); _menu.AppendMenuSeparator(); _menu.AppendMenuItem(MF_STRING, i++, "Update"); _menu.AppendMenuSeparator(); _fifthgroup.AppendTo( _menu, MF_STRING, "Keyboard shortcuts"); _fifthgroup.AppendMenuItem(MF_STRING, i++, "Backspace — go back"); _fifthgroup.AppendMenuItem(MF_STRING, i++, "Space — middle click (clear playlist and enqueue)"); _fifthgroup.AppendMenuItem(MF_STRING, i++, "Enter — left click (choose folder or enqueue)"); _fifthgroup.AppendMenuItem(MF_STRING, i++, "Page Up/Down — scrolling"); _fifthgroup.AppendMenuItem(MF_STRING, i++, "Home/End — scrolling"); _menu.EnableMenuItem( i-1, 1); _menu.EnableMenuItem( i-2, 1); _menu.EnableMenuItem( i-3, 1); _menu.EnableMenuItem( i-4, 1); _menu.EnableMenuItem( i-5, 1); ret = _menu.TrackPopupMenu(x, y); if ( p.length > 0 ) recent_clear_option = 1; else recent_clear_option = 0; if (ret == 1 ) { utils.WriteINI( fb.FoobarPath + 's7e.ini', 'explore', 'showhidden', Explore.ShowHidden = ( Explore.ShowHidden == 1 ) ? 0 : 1 ); Explore.Reset(); if ( Explore.Mode == 'default' ) Explore.ListDrives(); else Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } else if (ret == 2 ) { utils.WriteINI( fb.FoobarPath + 's7e.ini', 'explore', 'showonlysupported', Explore.ShowOnlySupported = ( Explore.ShowOnlySupported == 1 ) ? 0 : 1); Explore.Reset(); if ( Explore.Mode == 'default' ) Explore.ListDrives(); else Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } else if (ret == 3 ) { utils.WriteINI( fb.FoobarPath + 's7e.ini', 'explore', 'showscrollbar', Explore.ScrollShow = ( Explore.ScrollShow == 1 ) ? 0 : 1); Explore.Reset(); if ( Explore.Mode == 'default' ) Explore.ListDrives(); else Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } else if (ret == 4) { utils.WriteINI( fb.FoobarPath + 's7e.ini', 'explore', 'sync', Explore.Sync = ( Explore.Sync == 1 ) ? 0 : 1); if ( Explore.Sync == 1 && Explore.SyncMode == 0 ) on_item_focus_change(); else if ( Explore.Sync == 1 ) on_playback_new_track(); } else if (ret > 4 && ret < 7 ) { utils.WriteINI( fb.FoobarPath + 's7e.ini', 'explore', 'syncmode', Explore.SyncMode = ret - 5 ); if (Explore.SyncMode == 0 ) on_item_focus_change(); else on_playback_new_track(); } else if ( ret > 6 && ret < 6 + p.length + recent_clear_option ) { w = Explore.RecentPaths.split('|'); w = w.reverse(); Explore.Mode = 'folder'; Explore.Reset(); Explore.AddRecent( w[ret - 7] ); Explore.ListFiles( w[ret - 7] ); } else if (ret == 6 + p.length + recent_clear_option ) { Explore.RecentPaths = my_ini.recentpaths = ''; my_ini_write( object2string( my_ini ) ); } else if (ret == 7 + p.length + recent_clear_option ) { if ( Explore.Mode == 'folder' ) { if ( pressed < 0 ) { try { fso.DeleteFolder( Explore.CurrentFolder, true); } catch(e) { } } else if ( Folders[pressed] ) { try { fso.DeleteFolder( Folders[pressed].path, true); } catch(e) { } } else if ( Files[pressed - Folders.length] ) { try { fso.DeleteFile( Files[pressed - Folders.length].path, true); } catch(e) { } } Explore.ResetList(); Explore.ListFiles( Explore.CurrentFolder ); Explore.Updated = false; on_mouse_move( Explore.Data == 1 ? 5 : ( Explore.Data == 2 ? window.Width - 10 : 30 ), Explore.Y2); //window.Repaint(); } } else if (ret > 7 + p.length + recent_clear_option && ret < 11 + p.length + recent_clear_option ) { if ( Explore.Mode == 'folder' ) { if ( Folders[pressed] ) { if ( ret == 9 + p.length + recent_clear_option ) fb.ClearPlaylist(); else if ( ret == 10 + p.length + recent_clear_option ) { var new_playlist = fb.CreatePlaylist(fb.PlaylistCount, Folders[pressed].name ); fb.ActivePlaylist = new_playlist; } Explore.AddRecent( Folders[pressed].path ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Folders[pressed].path + '" /immediate'); } else if ( Files[pressed - Folders.length] ) { if ( ret == 9 + p.length + recent_clear_option ) fb.ClearPlaylist(); else if ( ret == 10 + p.length + recent_clear_option) { var new_playlist = fb.CreatePlaylist(fb.PlaylistCount, Files[pressed - Folders.length].name); fb.ActivePlaylist = new_playlist; } Explore.AddRecent( Explore.CurrentFolder ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Files[pressed - Folders.length].path + '" /immediate'); } else { if ( ret == 9 + p.length + recent_clear_option) fb.ClearPlaylist(); else if ( ret == 10 + p.length + recent_clear_option) { foldername = Explore.CurrentFolder.replace(/^.*(\/|\\)/,""); var new_playlist = fb.CreatePlaylist(fb.PlaylistCount, foldername); fb.ActivePlaylist = new_playlist; } Explore.AddRecent( Explore.CurrentFolder ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Explore.CurrentFolder + '" /immediate'); } window.Repaint(); } } else if (ret == 11 + p.length + recent_clear_option ) { Explore.Offset = 0; window.Repaint(); } else if (ret == 12 + p.length + recent_clear_option ) { Explore.Offset = Explore.Height - window.Height; window.Repaint(); } else if (ret == 13 + p.length + recent_clear_option ) { Explore.Reset(); Explore.ListFiles( Explore.CurrentFolder, true ); window.Repaint(); } else if (ret == 14 + p.length + recent_clear_option ) { root = Explore.CurrentFolder.replace(/(\w\:\\)(.*)/ig, "$1"); //fb.trace( root ); f = fso.GetFolder( root ); Explore.Reset(); Explore.CurrentFolder = f.Path; Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } else if (ret == 15 + p.length + recent_clear_option ) { Explore.Mode = 'default'; Explore.Reset(); Explore.ListDrives(); window.Repaint(); } else if (ret == 16 + p.length + recent_clear_option ) { if ( Explore.Mode == 'default' ) { if ( Drives[pressed] ) { WshShell.Run('"' + Drives[pressed].letter + ':\\' + '"'); } else WshShell.Run('"explorer.exe"'); } else { if ( Folders[pressed] ) { WshShell.Run('"' + Folders[pressed].path + '\\' + '"'); } else WshShell.Run('"' + Explore.CurrentFolder + '"'); } } else if (ret == 17 + p.length + recent_clear_option ) { Explore.Reset(); if ( Explore.Mode == 'default' ) Explore.ListDrives(); else Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } return true; } function on_item_focus_change() { if ( Explore.Sync == 1 && (Explore.SyncMode == 0 || !fb.IsPlaying) ) { path = fb.GetFocusItem(true) ? fb.GetFocusItem(true).Path : false; if ( path ) Explore.Update ( path ); } } function on_focus() { Explore.ResetList(); if ( Explore.Mode == 'default' ) Explore.ListDrives(); else Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } function on_playback_new_track( ) { if ( Explore.Sync == 1 && Explore.SyncMode == 1 ) { metadb = !fb.IsPlaying ? fb.GetFocusItem(true) : fb.GetNowPlaying(); Explore.Update ( metadb.Path ); } } function on_playback_stop(Reason) { if ( Reason == 0 && Explore.Sync == 1 ) { Explore.Update ( fb.GetFocusItem(true).Path ); } } function on_playlist_switch() { on_item_focus_change(); } function on_mouse_mbtn_down(x,y) { //Explore.Y1 = y; drag = 0; } function on_mouse_mbtn_up(x,y) { Explore.Y2 = y; var pressed = Math.floor( (y + Explore.Offset) / 24 ) - 1; //fb.trace( 'Explore.Y1 = ' + Explore.Y1 + " Explore.Y2 = " + Explore.Y2 ); if ( Explore.Mode == 'folder' && !drag ) { //&& Explore.Y1 == Explore.Y2 if ( pressed == -1 ) { fb.ClearPlaylist(); Explore.AddRecent( Explore.CurrentFolder ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Explore.CurrentFolder + '" /immediate'); } else if ( Folders[pressed] ) { fb.ClearPlaylist(); Explore.AddRecent( Folders[pressed].path ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Folders[pressed].path + '" /immediate'); } else if ( Files[pressed - Folders.length] ) { fb.ClearPlaylist(); Explore.AddRecent( Explore.CurrentFolder ); WshShell.Run('"' + fb.FoobarPath + '\\foobar2000.exe" /add ' + '"' + Files[pressed - Folders.length].path + '" /immediate'); } } else if ( Explore.Mode == 'default' ) { if ( Drives[pressed] ) { Explore.Mode = 'folder'; Explore.CurrentFolder = Drives[pressed].letter + ':'; Explore.Reset(); Explore.ListFiles( Explore.CurrentFolder ); window.Repaint(); } } drag = 0; Explore.Y1 = 0; Explore.Y2 = 0; } function on_key_up( vkey ) { if ( vkey == 0x00000008 ) { // BACKSPACE if ( Explore.Mode == 'default' ) { Explore.Reset(); Explore.ListDrives(); window.Repaint(); } else if ( Explore.Mode == 'folder' ) { Explore.Reset(); Explore.ListFiles( Explore.CurrentFolder, true ); window.Repaint(); } } else if ( vkey == 0x0000000D ) { // ENTER if ( Explore.X && Explore.Y ) { on_mouse_lbtn_down( Explore.X, Explore.Y); on_mouse_lbtn_up( Explore.X, Explore.Y ); } } else if ( vkey == 0x00000020 ) { // ENTER if ( Explore.X && Explore.Y ) { on_mouse_mbtn_down( Explore.X, Explore.Y); on_mouse_mbtn_up( Explore.X, Explore.Y ); } } else if ( vkey == 0x00000023 ) { // ENTER Explore.Offset = Explore.Height - window.Height; scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / ( Explore.Height - window.Height) ); window.Repaint(); } else if ( vkey == 0x00000024 ) { // HOME Explore.Offset = 0; scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / (Explore.Height - window.Height) ); window.Repaint(); } Explore.Updated = false; } function on_key_down(vkey) { if ( (vkey == 0x00000021 || vkey == 0x00000026) && Explore.Offset > 0 ) { ( Explore.Offset - 25 > 0 ) ? Explore.Offset -= 25 : Explore.Offset = 0; scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / ( Explore.Height - window.Height) ); Explore.Hover = false; on_mouse_move( Explore.X, Explore.Y); } else if ( (vkey == 0x00000022 || vkey == 0x00000028) && Explore.Offset < Explore.Height - window.Height ) { ( Explore.Offset + 25 > Explore.Height - window.Height ) ? Explore.Offset = Explore.Height - window.Height : Explore.Offset += 25; scrollbar_center = Explore.ScrollbarAdd + Math.ceil(( Explore.Offset * ( window.Height - Explore.ScrollbarAdd * 2 ) ) / (Explore.Height - window.Height) ); Explore.Hover = false; on_mouse_move( Explore.X, Explore.Y); } }