home *** CD-ROM | disk | FTP | other *** search
/ Freelog 117 / FreelogNo117-OctobreNovembre2013.iso / Theme / 8GadgetPack / 8GadgetPackSetup.msi / Gadgets.7z / Gadgets / Clipboarder.gadget / Main.js < prev    next >
Text (UTF-16)  |  2013-08-20  |  19KB  |  252 lines

  1.  
  2.  
  3. var DockedWidth = 125;
  4. var UndockedWidth = 180;
  5.  
  6. var version = 220;
  7. var Net = null;
  8. var guid = "{460BD50A-CC02-45FE-9A4A-981B48D26B98}";
  9. var progId = "Clipboarder.ClipboarderNet220";
  10. var dllPath = System.Gadget.path + "\\Release\\Clipboarder.220.dll";
  11. var altDllPath = System.Gadget.path + "\\..\\ClipboarderDLLs\\Clipboarder.220.dll";
  12. var dllPath2 = System.Gadget.path + "\\Release\\Clipboarder2.220.dll";
  13. var altDllPath2 = System.Gadget.path + "\\..\\ClipboarderDLLs\\Clipboarder2.220.dll";
  14. var settingsPath = "Settings.220.html";
  15. var h = 0;
  16. var prevVersion = 0;
  17. var CurrentWidth = 0;
  18.  
  19. function Load()
  20. {
  21.     SetDefaultSettings();
  22.     CurrentWidth = System.Gadget.docked ? DockedWidth : UndockedWidth;
  23.     h = System.Gadget.Settings.read("Height");
  24.     with(document.body.style)
  25.         width = CurrentWidth,
  26.         height = h;
  27.  
  28.     LoadNet();
  29.     Net.CheckVersion(version);
  30.     Net.Init(NewSize, LocalizedFunction, WriteSetting, System.Gadget.path+"\\");
  31.     SettingsClosed(null);
  32.  
  33.     System.Gadget.settingsUI = settingsPath;
  34.     System.Gadget.onSettingsClosed = SettingsClosed;
  35.     System.Gadget.onDock = Docked;
  36.     System.Gadget.onUndock = Undocked;
  37. }
  38.  
  39. function Unload()
  40. {
  41.     if(Net != null)
  42.         Net.Dispose();
  43.     Net = null;
  44. }
  45.  
  46. function Docked()
  47. {
  48.     CurrentWidth = DockedWidth;
  49.     with(document.body.style)
  50.         width = CurrentWidth,
  51.         height = h;
  52. }
  53.  
  54. function Undocked()
  55. {
  56.     CurrentWidth = UndockedWidth;
  57.     with(document.body.style)
  58.         width = CurrentWidth,
  59.         height = h;
  60. }
  61.  
  62. function NewSize(size)
  63. {
  64.     h = size;
  65.     System.Gadget.Settings.write("Height", size);
  66.     with(document.body.style)
  67.         width = CurrentWidth,
  68.         height = h;
  69. }
  70.  
  71. function LocalizedFunction(name)
  72. {
  73.     return Localized[name];
  74. }
  75.  
  76. function WriteSetting(Var, Val)
  77. {
  78.     System.Gadget.Settings.write(Var, Val);
  79. }
  80.  
  81. function SettingsClosed(event)
  82. {
  83.     Net.SetSettings(prevVersion,
  84.                     parseInt(System.Gadget.Settings.read("UseHotKeys")),
  85.                     parseInt(System.Gadget.Settings.read("HotKeyModifer1")),
  86.                     System.Gadget.Settings.read("HotKey1"),
  87.                     parseInt(System.Gadget.Settings.read("HotKeyModifer2")),
  88.                     System.Gadget.Settings.read("HotKey2"),
  89.                     parseInt(System.Gadget.Settings.read("MaxContents")),
  90.                     parseInt(System.Gadget.Settings.read("FixedVisibleContents")),
  91.                     parseInt(System.Gadget.Settings.read("UseGlass")),
  92.                     parseInt(System.Gadget.Settings.read("UseAnimation")),
  93.                     parseInt(System.Gadget.Settings.read("UseNumpadHotkey")),
  94.                     parseInt(System.Gadget.Settings.read("UseForeground")),
  95.                     System.Gadget.Settings.read("UseSave"),
  96.                     parseInt(System.Gadget.Settings.read("UseSound")),
  97.                     System.Gadget.Settings.read("SoundFile"),
  98.                     System.Gadget.Settings.read("Browser"),
  99.                     parseInt(System.Gadget.Settings.read("MonitorClipboard")),
  100.                     parseInt(System.Gadget.Settings.read("UseHotkeyUnformatted")));
  101.     prevVersion = System.Gadget.Settings.read("Version");
  102. }
  103.  
  104.  
  105. function SetDefaultSettings()
  106. {
  107.     if(System.Gadget.Settings.read("SettingsWritten") == "1")
  108.         prevVersion = parseInt(System.Gadget.Settings.read("Version"));
  109.  
  110.     if(System.Gadget.Settings.read("SettingsWritten") != "1")
  111.     {
  112.         System.Gadget.Settings.write("Height", 200);
  113.         System.Gadget.Settings.write("HotKeyModifer1", 8);
  114.         System.Gadget.Settings.write("HotKeyModifer2", 8);
  115.         System.Gadget.Settings.write("HotKey1", "V");
  116.         System.Gadget.Settings.write("HotKey2", "C");
  117.         System.Gadget.Settings.write("MaxContents", 20);
  118.         System.Gadget.Settings.write("FixedVisibleContents", 1);
  119.         System.Gadget.Settings.write("UseGlass", "1");
  120.         System.Gadget.Settings.write("SettingsWritten", "1");
  121.     }
  122.     if(prevVersion <= 100)
  123.     {
  124.         System.Gadget.Settings.write("UseAnimation", "1");
  125.         System.Gadget.Settings.write("UseNumpadHotkey", "0");
  126.         System.Gadget.Settings.write("UseForeground", "0");
  127.         System.Gadget.Settings.write("UseSave", "@");
  128.     }
  129.     if(prevVersion <= 130)
  130.     {
  131.         System.Gadget.Settings.write("UseSound", "0");
  132.         System.Gadget.Settings.write("SoundFile", "C:\\Windows\\Media\\chimes.wav");
  133.     }
  134.     if(prevVersion <= 180)
  135.     {
  136.         System.Gadget.Settings.write("UseHotKeys", "1");
  137.         System.Gadget.Settings.write("MonitorClipboard", "1");
  138.     }
  139.     if(prevVersion <= 210)
  140.     {
  141.         System.Gadget.Settings.write("UseHotkeyUnformatted", "0");
  142.     }
  143.     System.Gadget.Settings.write("Version", version);        
  144. }
  145.  
  146. function LoadNet()
  147. {
  148.     var wshShell = new ActiveXObject("WScript.Shell");
  149.  
  150.     RegisterNet(wshShell, "HKCU", dllPath, "v4.0.30319");
  151.     RegisterNet(wshShell, "HKLM", dllPath, "v4.0.30319");
  152.  
  153.     // create the COM object and store it in global variable
  154.     try
  155.     {
  156.         Net = new ActiveXObject(progId); 
  157.     }
  158.     catch(err)
  159.     {
  160.         UnregisterNet(wshShell, "HKCU");
  161.         UnregisterNet(wshShell, "HKLM");
  162.  
  163.         RegisterNet(wshShell, "HKCU", altDllPath, "v4.0.30319");
  164.         RegisterNet(wshShell, "HKLM", altDllPath, "v4.0.30319");
  165.         try
  166.         {
  167.             Net = new ActiveXObject(progId);
  168.         }
  169.         catch (err)
  170.         {
  171.             UnregisterNet(wshShell, "HKCU");
  172.             UnregisterNet(wshShell, "HKLM");
  173.  
  174.             RegisterNet(wshShell, "HKCU", dllPath2, "v2.0.50727");
  175.             RegisterNet(wshShell, "HKLM", dllPath2, "v2.0.50727");
  176.             try
  177.             {
  178.                 Net = new ActiveXObject(progId);
  179.             }
  180.             catch (err)
  181.             {
  182.                 UnregisterNet(wshShell, "HKCU");
  183.                 UnregisterNet(wshShell, "HKLM");
  184.  
  185.                 RegisterNet(wshShell, "HKCU", altDllPath2, "v2.0.50727");
  186.                 RegisterNet(wshShell, "HKLM", altDllPath2, "v2.0.50727");
  187.                 Net = new ActiveXObject(progId);
  188.             }
  189.         }
  190.     }
  191.     if(Net == null)
  192.     {
  193.         alert("Gadgets\\ClipboarderDLLs folder not found. Install the gadget again.");
  194.         debugger;
  195.         return;
  196.     }
  197.  
  198.     // delete all the entries again
  199.     UnregisterNet(wshShell, "HKCU");
  200.     UnregisterNet(wshShell, "HKLM");
  201.  
  202.     wshShell = null;
  203. }
  204.  
  205. function RegisterNet(wshShell, root, path, netversion)
  206. {
  207.     try
  208.     {
  209.         wshShell.RegWrite(root + "\\Software\\Classes\\" + progId + "\\", progId);
  210.         wshShell.RegWrite(root + "\\Software\\Classes\\" + progId + "\\CLSID\\", guid);       
  211.  
  212.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\", progId); 
  213.  
  214.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\", "mscoree.dll");
  215.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\ThreadingModel", "Both");
  216.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\Class", progId);
  217.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\Assembly", "Clipboarder."+version+", Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
  218.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\RuntimeVersion", netversion);
  219.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\CodeBase", path); 
  220.  
  221.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\1.0.0.0\\Class", progId);
  222.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\1.0.0.0\\Assembly", "Clipboarder."+version+", Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
  223.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\1.0.0.0\\RuntimeVersion", netversion);
  224.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\1.0.0.0\\CodeBase", path); 
  225.  
  226.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\ProgId\\", progId); 
  227.  
  228.         wshShell.RegWrite(root + "\\Software\\Classes\\CLSID\\" + guid + "\\Implemented Categories\\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}\\", "");
  229.     }
  230.     catch(err)
  231.     {
  232.     }
  233. }
  234. function UnregisterNet(wshShell, root)
  235.     try
  236.     {
  237.         wshShell.RegDelete(root + "\\Software\\Classes\\" + progId + "\\CLSID\\");
  238.         wshShell.RegDelete(root + "\\Software\\Classes\\" + progId + "\\");
  239.         wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\1.0.0.0\\");
  240.         wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\InprocServer32\\");
  241.         wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\ProgId\\");
  242.         wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\Implemented Categories\\{62C8FE65-4EBB-45E7-B440-6E39B2CDBF29}\\");
  243.         wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\Implemented Categories\\");
  244.         wshShell.RegDelete(root + "\\Software\\Classes\\CLSID\\" + guid + "\\");
  245.     }
  246.     catch(err)
  247.     {
  248.     }
  249. }
  250.  
  251.