home *** CD-ROM | disk | FTP | other *** search
/ Softwarová Záchrana 3 / Softwarova-zachrana-3.bin / StartRight / source.zip / UnitItemManager.pas < prev    next >
Pascal/Delphi Source File  |  2004-10-03  |  19KB  |  680 lines

  1. unit UnitItemManager;
  2. {
  3.     Purpose:
  4.         Create one centralized location where items
  5.         are Excluded/Disabled/Included. PPP
  6.  
  7.     Updates:
  8.         Fix: AutoExcludeRunkeyItems resorted startup items
  9.         instead of runkey items.
  10.  
  11.         Items that are excluded will be removed from disabled lists
  12.         (They can be both excluded and disabled because of the AutoExcluding)
  13.  
  14.     Notes:
  15.         When an Item is removed from a sorted list, the sorted list
  16.         must be recreated to keep it contiguous.
  17. }
  18.  
  19. interface
  20.  
  21. uses UnitMyRegistry;
  22.  
  23. type TItemManager = class(TObject)
  24.     private
  25.         r : TMyRegistry;
  26.  
  27.         procedure AddToRunkeySortItems(value : string);
  28.         procedure AddToStartupfolderItem(filename : string);
  29.         procedure AddItem(key : string; itemdata : string);
  30.         procedure DeleteStartupSortItem(filename : string);
  31.  
  32.         procedure MoveFile(FullName, ToPath : string);
  33.     public
  34.         constructor Create;
  35.         destructor Destroy; override;
  36.         procedure AutoExcludeRunkeyItems;
  37.         procedure AutoExcludeStartupItems;
  38.  
  39.         procedure DisableRunkeyItem(value : string);
  40.         procedure DisableStartupItem(filename : string; noResort : boolean = false);
  41.  
  42.         procedure ExcludeRunkeyItem(value : string);
  43.         procedure ExcludeStartupItem(shortcutname : string);
  44.  
  45.         procedure IncludeRunkeyItem(value : string; currentuser : boolean = false);
  46.         function IncludeStartupItem(filename : string) : string;
  47.  
  48.         procedure EnableRunkeyItem(value : string);
  49.         procedure EnableStartupItem(filename : string);
  50.  
  51.         procedure CorrectExcludedShortcutItem(value : string);
  52.  
  53.         procedure ResortRunkeySortItems;
  54.         procedure ResortStartupSortItems;
  55.  
  56.  
  57. end;
  58.  
  59. var ItemManager : TItemManager;
  60.  
  61. {////////////////////}
  62. {//}implementation{//}
  63. {////////////////////}
  64.  
  65. uses Classes, Windows, UnitMyKeys, StrUtils, SysUtils, ShellAPI, ShlObj,
  66.     UnitFrmDummyRunner, Forms, UnitSpecialPaths;
  67.  
  68. constructor TItemManager.Create;
  69. begin
  70.     r := TMyRegistry.Create;
  71. end;
  72.  
  73. destructor TItemManager.Destroy;
  74. begin
  75.     r.Free;
  76.     inherited Destroy;
  77. end;
  78.  
  79.  
  80. procedure TItemManager.CorrectExcludedShortcutItem(value : string);
  81. var s, cs, als : string;
  82. begin
  83.     s := IncludeTrailingPathDelimiter(  SpecialPaths.GetStartupPath);
  84.     cs := IncludeTrailingPathDelimiter(  SpecialPaths.GetCommonStartupPath);
  85.     als := IncludeTrailingPathDelimiter(  SpecialPaths.GetAltStartupPath);
  86.  
  87.     if FileExists(s + value) then begin
  88.         r.SetDataString(SR_STARTUPEXCLUDE_KEY, value, s + value);
  89.     end else if FileExists(cs + value) then begin
  90.         r.SetDataString(SR_STARTUPEXCLUDE_KEY, value, cs + value);
  91.     end else if FileExists(als + value) then begin
  92.          r.SetDataString(SR_STARTUPEXCLUDE_KEY, value, als + value);
  93.     end;
  94. end;
  95.  
  96. procedure TItemManager.DisableStartupItem(filename : string; noResort : boolean = false);
  97. var j, index : longint;
  98.     value : string;
  99. begin
  100.     // write the value to the disabled items
  101.     // find the sorted item and remove it
  102.  
  103.     r.SetDataString(SR_STARTUPDISABLE_KEY,ExtractFilename(filename),filename);
  104.  
  105.     try
  106.         index := UnitMyKeys.GetStartupSortCount;
  107.  
  108.         for j := 0 to (index - 1) do begin
  109.             value := r.GetDataString(SR_STARTUPSORT_KEY, IntToStr(j));
  110.             if lowercase(value) = lowercase(filename) then begin
  111.                 r.DeleteDataString(SR_STARTUPSORT_KEY, IntToStr(j));
  112.             end;
  113.         end;
  114.     except
  115.     end;
  116.  
  117.     self.ResortStartupSortItems;
  118. end;
  119.  
  120.  
  121. procedure TItemManager.AutoExcludeStartupItems;
  122.     procedure ScanForFiles(path : string; files : TStringList);
  123.     var rec : TSearchRec;
  124.         r : integer;
  125.     begin
  126.         if (trim(path) <> '') then begin
  127.             path := IncludeTrailingPathDelimiter(path);
  128.  
  129.             r := findfirst(path + '*.*', faHidden  , rec);
  130.             while r = 0 do begin
  131.                 files.Add(rec.Name);
  132.  
  133.                 r := findnext(rec);
  134.             end;
  135.         end;
  136.     end;
  137. var
  138.    Startup, CommonStartup, AltStartup : string;
  139.    newExcludes, files : TStringList;
  140.    i, cnt : longint;
  141.    s : string;
  142.  
  143. begin
  144.     files := TStringList.Create;
  145.     newExcludes := TStringList.Create;
  146.  
  147.     //
  148.     // get all existing startup folder files
  149.     //
  150.  
  151.     Startup := SpecialPaths.GetStartupPath;
  152.     CommonStartup := SpecialPaths.GetCommonStartupPath;
  153.     AltStartup := SpecialPaths.GetAltStartupPath;
  154.  
  155.     ScanForFiles(Startup, files);
  156.     ScanForFiles(CommonStartup, files);
  157.     ScanForFiles(AltStartup, files);
  158.  
  159.     //
  160.     // search for my startup files for matches in the startupsort key
  161.     // exclude all matches (remove the startup sort item and add it to excluded list)
  162.     //
  163.  
  164.     cnt := UnitMyKeys.GetStartupSortCount;
  165.     for i := 0 to (cnt - 1) do begin
  166.         s := ExtractFilename(r.GetDataString(SR_STARTUPSORT_KEY, IntToStr(i)));
  167.         if (files.IndexOf(s) <> - 1) then begin
  168.             r.DeleteDataString(SR_STARTUPSORT_KEY, IntToStr(i));
  169.             newExcludes.Add(s);
  170.         end;
  171.     end;
  172.  
  173.  
  174.     for i := 0 to (newExcludes.Count - 1) do begin
  175.         ExcludeStartupItem(newExcludes.Strings[i]);
  176.     end;
  177.  
  178.     files.Free;
  179.     newExcludes.Free;
  180. end;
  181.  
  182.  
  183.  
  184. procedure TItemManager.ExcludeStartupItem(shortcutname : string);
  185. var src, startup : string;
  186. begin
  187.     //
  188.     // move file back to system's startup folder
  189.     // write to excluded list
  190.     // remove from disabled list
  191.     // (autoexcluded items that are also disabled don't work anyways) 
  192.     startup := SpecialPaths.GetCommonStartupPath;
  193.     src := SpecialPaths.GetStartRightStartup;
  194.  
  195.     MoveFile(src + ExtractFilename(shortcutname), Startup);
  196.  
  197.     r.SetDataString(
  198.         SR_STARTUPEXCLUDE_KEY,
  199.         ExtractFilename(ShortcutName),
  200.         IncludeTrailingPathDelimiter(Startup) + ExtractFilename(Shortcutname)
  201.     );
  202.  
  203.     r.DeleteDataString(SR_STARTUPDISABLE_KEY, ExtractFilename(shortcutname));
  204.  
  205.     {
  206.     r.RootKey := HKEY_LOCAL_MACHINE;
  207.     if (r.OpenKey(SR_STARTUPEXCLUDE_KEY, true)) then begin
  208.         r.WriteString(ExtractFilename(ShortcutName),
  209.             IncludeTrailingPathDelimiter(Startup) + ExtractFilename(Shortcutname));
  210.         r.CloseKey;
  211.     end;
  212.  
  213.     r.RootKey := HKEY_LOCAL_MACHINE;
  214.     if (r.OpenKey(SR_STARTUPDISABLE_KEY, false)) then begin
  215.         r.DeleteValue(ExtractFilename(shortcutname));
  216.         r.closekey;
  217.     end;
  218.     }
  219.     self.DeleteStartupSortItem(shortcutname);
  220. end;
  221.  
  222. procedure TItemManager.AutoExcludeRunkeyItems;
  223. var winrun, myrun, exclude : TStringList;
  224.     i : longint;
  225.     s : string;
  226. begin
  227.     winrun := TStringList.Create;
  228.     myrun := TStringList.Create;
  229.     exclude  := TStringList.Create;
  230.  
  231.     //
  232.     // get both run keys and compare for matches
  233.     // on a match, delete from my run key and add to excluded items
  234.     //
  235.     r.GetValues(WINDOWS_RUN_KEY, winrun);
  236.     r.GetValues(SR_RUN_KEY, myrun);
  237.  
  238.     for i := 0 to (myrun.Count - 1) do begin
  239.         s := myrun.Strings[i];
  240.         if (winrun.IndexOf(s) <> -1) then begin
  241.             exclude.Add(s);
  242.             r.DeleteDataString(SR_RUN_KEY, s);
  243.         end;
  244.     end;
  245.     self.ResortRunkeySortItems;
  246.  
  247.     for i := 0 to (exclude.Count - 1) do begin
  248.         r.SetDataString(SR_RUNEXCLUDE_KEY, exclude.Strings[i], SR_EXCLUDE_DATA);
  249.     end;
  250.  
  251.     {
  252.     r.RootKey := HKEY_LOCAL_MACHINE;
  253.     if (r.OpenKey(SR_RUNEXCLUDE_KEY, false)) then begin
  254.         for i := 0 to (exclude.Count - 1) do begin
  255.             r.WriteString(exclude.Strings[i], SR_EXCLUDE_DATA);
  256.         end;
  257.         r.CloseKey;
  258.     end;
  259.     }
  260.  
  261.     winrun.free;
  262.     myrun.Free;
  263.     exclude.free;
  264. end;
  265.  
  266.  
  267.  
  268. procedure TItemManager.ExcludeRunkeyItem(value : string);
  269. var data : string;
  270. begin
  271.     // add the items to the registry excluded list
  272.     // read the data from SR's run key and delete the value
  273.     // if was Disabled - it didn't work so remove it from disabled list
  274.     // add the value/data back to the Windows' Run key
  275.  
  276.     r.SetDataString(SR_RUNEXCLUDE_KEY, value, SR_EXCLUDE_DATA);
  277.     data := r.DeleteDataString(SR_RUN_KEY, value);
  278.  
  279.     if (data <> '') then begin
  280.         self.ResortRunkeySortItems;
  281.         r.DeleteDataString(SR_RUNDISABLED_KEY, value);
  282.         r.SetDataString(WINDOWS_RUN_KEY, value, data);
  283.     end;
  284.  
  285.  
  286.     {
  287.     r.RootKey := HKEY_LOCAL_MACHINE;
  288.     if (r.OpenKey(SR_RUNEXCLUDE_KEY, true)) then begin
  289.         r.WriteString(value, SR_EXCLUDE_DATA);
  290.         r.CloseKey;
  291.     end;
  292.  
  293.     data := '';
  294.     r.RootKey := HKEY_LOCAL_MACHINE;
  295.     if (r.OpenKey(SR_RUN_KEY, false)) then begin
  296.         if r.ValueExists(value) then begin
  297.             data := r.ReadString(value);
  298.             r.DeleteValue(value);
  299.         end;
  300.         r.CloseKey;
  301.     end;
  302.     }
  303.  
  304.     {
  305.     if (data <> '') then begin
  306.         self.ResortRunkeySortItems;
  307.         r.RootKey := HKEY_LOCAL_MACHINE;
  308.         if r.OpenKey(SR_RUNDISABLED_KEY, false) then begin
  309.             r.DeleteValue(value);
  310.             r.CloseKey;
  311.         end;
  312.  
  313.         r.RootKey := HKEY_LOCAL_MACHINE;
  314.         if (r.OpenKey(WINDOWS_RUN_KEY, false)) then begin
  315.             r.WriteString(value, data);
  316.             r.CloseKey;
  317.         end;
  318.     end;
  319.     }
  320.  
  321. end;
  322.  
  323. procedure TItemManager.DisableRunkeyItem(value : string);
  324. var i : longint;
  325.     s, rundata : string;
  326. begin
  327.  
  328.     // If disabled item exists in included items sortlist, remove/resort
  329.     rundata := UnitMyKeys.GetRunSortData(value);
  330.     if (rundata <> '') then begin
  331.         for i := 0 to (UnitMyKeys.GetRunSortCount - 1) do begin
  332.             s := UnitMyKeys.GetRunSortValue(i);
  333.             if s <> value then CONTINUE;
  334.  
  335.             RunData := UnitMyKeys.GetRunSortData(i);
  336.  
  337.             r.DeleteDataString(SR_RUNSORT_KEY, IntToStr(i));
  338.             {
  339.             r.RootKey := HKEY_LOCAL_MACHINE;
  340.             if (r.OpenKey(SR_RUNSORT_KEY, false)) then begin
  341.                 r.DeleteValue(IntToStr(i));
  342.                 r.CloseKey;
  343.             end;
  344.             }
  345.         end;
  346.  
  347.         // Add the entry into the RunDisabled key, so that it
  348.         // may be enabled at a future date
  349.         r.SetDataString(SR_RUNDISABLED_KEY, value, rundata);
  350.         {
  351.         r.RootKey := HKEY_LOCAL_MACHINE;
  352.         if (r.OpenKey(SR_RUNDISABLED_KEY, true)) then begin
  353.             r.WriteString(value, rundata);
  354.             r.CloseKey;
  355.         end;
  356.         }
  357.     end;
  358.  
  359.     // remove from system's run key
  360.     r.DeleteDataString(WINDOWS_RUN_KEY, value);
  361.     {
  362.     r.RootKey := HKEY_LOCAL_MACHINE;
  363.     if (r.OpenKey(WINDOWS_RUN_KEY, false)) then begin
  364.         r.DeleteValue(value);
  365.         r.CloseKey;
  366.     end;
  367.     }
  368.     // resort since we just screwed up the contiguos numbers
  369.     // in the sort key
  370.  
  371.     self.ResortRunkeySortItems;
  372. end;
  373.  
  374.  
  375.  
  376.  
  377. procedure TItemManager.IncludeRunkeyItem(value : string; currentuser : boolean = false);
  378. var rundata : string;
  379.     rkey : HKEY;
  380. begin
  381.     // Find the item in windows' run key and delete
  382.     if (currentuser) then begin
  383.         rKey := HKEY_CURRENT_USER;
  384.     end else begin
  385.         rKey := HKEY_LOCAL_MACHINE;
  386.     end;
  387.     rundata := r.DeleteDataString(rkey, WINDOWS_RUN_KEY, value);
  388.  
  389.     // Ignore if item doesn't exist
  390.     // write into my runkey
  391.     if (rundata <> '') then begin
  392.         r.SetDataString(HKEY_LOCAL_MACHINE, SR_RUN_KEY, value, rundata);
  393.         self.AddToRunkeySortItems(value);
  394.         self.ResortRunkeySortItems; {just to be sure}
  395.     end;
  396.  
  397.     // remove from my excluded list
  398.     // and from run key
  399.     r.DeleteDataString(rkey, SR_RUNEXCLUDE_KEY, value);
  400. end;
  401. function TItemManager.IncludeStartupItem(filename : string) : string;
  402. var dest : string;
  403. begin
  404.     result := '';
  405.     // move the file back to the SR's startup folder
  406.     // remove the item from the exclusion list
  407.     dest := SpecialPaths.GetStartRightStartup;
  408.     if FileExists(filename) then begin
  409.         MoveFile(FileName, dest);
  410.         result := IncludeTrailingPathDelimiter(dest) + ExtractFilename(filename);
  411.     end;
  412.  
  413.  
  414.     r.DeleteDataString(SR_STARTUPEXCLUDE_KEY, ExtractFileName(filename));
  415.     {
  416.     r.RootKey := HKEY_LOCAL_MACHINE;
  417.     if r.OpenKey(SR_STARTUPEXCLUDE_KEY, false) then begin
  418.         r.DeleteValue(ExtractFileName(filename));
  419.         r.CloseKey;
  420.     end;
  421.     }
  422.     self.AddToStartupfolderItem(IncludeTrailingPathDelimiter(dest)
  423.         + ExtractFilename(filename));
  424. end;
  425.  
  426.  
  427. procedure TItemManager.EnableRunkeyItem(value : string);
  428. var rundata : string;
  429. begin
  430.     // Find the data in my disabled list
  431.     // and remove it
  432.     rundata := r.DeleteDataString(SR_RUNDISABLED_KEY, value);
  433.     {
  434.     r.RootKey := HKEY_LOCAL_MACHINE;
  435.     if r.OpenKey(SR_RUNDISABLED_KEY, false) then begin
  436.         rundata := r.ReadString(value);
  437.         r.DeleteValue(value);
  438.         r.CloseKey;
  439.     end;
  440.     }
  441.  
  442.     // Ignore if item doesn't exist
  443.     // write into my runkey
  444.     if (rundata <> '') then begin
  445.         r.SetDataString(SR_RUN_KEY, value, rundata);
  446.         {
  447.         r.RootKey := HKEY_LOCAL_MACHINE;
  448.         if r.OpenKey(SR_RUN_KEY, true) then begin
  449.             r.WriteString(value, rundata);
  450.             r.CloseKey;
  451.         end;
  452.         }
  453.         self.AddToRunkeySortItems(value);
  454.         self.ResortRunkeySortItems; {just to be sure}
  455.     end;
  456. end;
  457.  
  458. procedure TItemManager.EnableStartupItem(filename : string);
  459. begin
  460.     // remove the disable key
  461.     r.DeleteDataString(SR_STARTUPDISABLE_KEY,ExtractFilename(filename));
  462.     {
  463.     r.RootKey := HKEY_LOCAL_MACHINE;
  464.     if (r.OpenKey(SR_STARTUPDISABLE_KEY, false)) then begin
  465.         r.DeleteValue(ExtractFilename(filename));
  466.         r.closekey;
  467.     end;
  468.     }
  469.     self.AddToStartupfolderItem(filename);
  470. end;
  471.  
  472.  
  473. //====================================
  474. // Util methods
  475. //====================================
  476.  
  477.  
  478.  
  479.  
  480.  
  481. procedure TItemManager.ResortRunKeySortItems;
  482. var {runvalues, values,} data : TStringList;
  483.     s : string;
  484.     i : longint;
  485. begin
  486.     data := TStringList.Create;
  487.     data.Sorted := false;
  488.  
  489.  
  490.     // generate an ordered list of valid RunSort data
  491.     for i := 0 to (UnitMyKeys.GetRunSortCount - 1) do begin
  492.         s := UnitMyKeys.GetRunSortData(i);
  493.         if (s <> '') then begin
  494.             data.Add(UnitMyKeys.GetRunSortValue(i));
  495.         end;
  496.     end;
  497.  
  498.     // recreate the sort list using the verified ordered list
  499.     r.EraseKey(SR_HOME_KEY, SR_SUB_RUNSORT);
  500.  
  501.     for i := 0 to (data.Count - 1) do begin
  502.         r.SetDataString(SR_RUNSORT_KEY,IntToStr(i), data.Strings[i]);
  503.     end;
  504.     r.SetDataInteger(SR_RUNSORT_KEY, SR_SORTINDEX_VALUE, data.count);
  505.  
  506.     {
  507.     r.RootKey := HKEY_LOCAL_MACHINE;
  508.     if (r.OpenKey(SR_HOME_KEY, false)) then begin
  509.         r.DeleteKey(SR_SUB_RUNSORT);
  510.         r.CreateKey(SR_SUB_RUNSORT);
  511.         r.CloseKey;
  512.     end;
  513.  
  514.     r.RootKey := HKEY_LOCAL_MACHINE;
  515.     if (r.OpenKey(SR_RUNSORT_KEY, false)) then begin
  516.         for i := 0 to (data.Count - 1) do begin
  517.  
  518.             r.WriteString(IntToStr(i), data.Strings[i]);
  519.         end;
  520.         r.WriteInteger(SR_SORTINDEX_VALUE, data.count);
  521.         r.CloseKey;
  522.     end;
  523.     }
  524.     data.Free;
  525. end;
  526.  
  527.  
  528. procedure TItemManager.ResortStartupSortItems;
  529. begin
  530.     self.DeleteStartupSortItem('thisitemdoesnotexistever');
  531. end;
  532.  
  533.  
  534.  
  535.  
  536. //================================
  537. // Private Implemenation
  538. //================================
  539.  
  540. procedure TItemManager.AddItem(key : string; itemdata : string);
  541. var sortIndex : integer;
  542.     s : string;
  543. begin
  544.     if (not r.ValueExistsInteger(key, SR_SORTINDEX_VALUE, sortIndex)) then begin
  545.         sortIndex := 0;
  546.     end;
  547.     if (not r.ValueExistsString(key, IntToStr(sortIndex), s)) then begin
  548.         r.SetDataString(key, IntToStr(sortIndex), itemdata);
  549.         r.SetDataInteger(key, SR_SORTINDEX_VALUE, sortIndex + 1);
  550.     end;
  551.  
  552.     {
  553.     r.RootKey := HKEY_LOCAL_MACHINE;
  554.     if (r.OpenKey(KEY, true)) then begin
  555.         // read the sort index (default if doesn't exist)
  556.         // write new entry at end of list
  557.         // increment the sort index
  558.         if (not r.ValueExists(SR_SORTINDEX_VALUE)) then begin
  559.             sortIndex := 0;
  560.         end else begin
  561.             sortIndex := r.ReadInteger(SR_SORTINDEX_VALUE);
  562.         end;
  563.  
  564.         //Add only if doesn't already exist
  565.         if (data.IndexOf(itemdata) = -1) then begin
  566.             r.WriteString(IntToStr(sortIndex), itemdata);
  567.             r.WriteInteger(SR_SORTINDEX_VALUE, sortIndex + 1);
  568.         end;
  569.         r.CloseKey;
  570.     end;
  571.     }
  572. end;
  573.  
  574. procedure TItemManager.AddToStartupfolderItem(filename : string);
  575. var s1, s2 : string;
  576.     i : integer;
  577. begin
  578.     // ignore duplicates
  579.     s1 := lowercase(ExtractFileName(filename));
  580.     for i := 0 to UnitMyKeys.GetStartupSortCount - 1 do begin
  581.         s2 := r.GetDataString(SR_STARTUPSORT_KEY, IntToStr(i));
  582.         s2 := lowercase(ExtractFileName(s2));
  583.         if s1 = s2 then EXIT;
  584.     end;
  585.  
  586.     self.AddItem(SR_STARTUPSORT_KEY, filename);
  587. end;
  588.  
  589. procedure TItemManager.AddToRunkeySortItems(value : string);
  590. begin
  591.     self.AddItem(SR_RUNSORT_KEY, value);
  592. end;
  593.  
  594.  
  595. procedure TItemManager.DeleteStartupSortItem(filename : string);
  596. var values, data : TStringList;
  597.     i : integer;
  598.     s : string;
  599. begin
  600.     //
  601.     values := TStringList.Create();
  602.     data := TStringList.Create();
  603.  
  604.     //
  605.     // extract the existing values/data
  606.     // [minus the sort index]
  607.     // [delete any entries matching filename]
  608.  
  609.     r.GetValues(SR_STARTUPSORT_KEY, values);
  610.     values.Delete(values.IndexOf(SR_SORTINDEX_VALUE));
  611.  
  612.     for i := (values.Count - 1) downto 0 do begin
  613.         s := r.GetDataString(SR_STARTUPSORT_KEY, values[i]);
  614.         if (filename <> s) or (filename = '') then begin
  615.             data.Add(s);
  616.         end else begin
  617.             values.Delete(i);
  618.         end;
  619.     end;
  620.  
  621.  
  622.     //
  623.     // delete existing and recreate
  624.     r.EraseKey(SR_HOME_KEY, SR_SUB_STARTUPSORT);
  625.  
  626.     for i := 0 to (values.Count - 1) do begin
  627.         r.SetDataString(SR_STARTUPSORT_KEY, IntToStr(i), data[i]);
  628.     end;
  629.     r.SetDataInteger(SR_STARTUPSORT_KEY, SR_SORTINDEX_VALUE, values.count);
  630.  
  631.  
  632.     {
  633.     r.RootKey := HKEY_LOCAL_MACHINE;
  634.     if (r.OpenKey(SR_HOME_KEY, false)) then begin
  635.         r.DeleteKey(SR_SUB_STARTUPSORT);
  636.         r.CreateKey(SR_SUB_STARTUPSORT);
  637.         r.CloseKey;
  638.     end;
  639.  
  640.     r.RootKey := HKEY_LOCAL_MACHINE;
  641.     if (r.OpenKey(SR_STARTUPSORT_KEY, false)) then begin
  642.         for i := 0 to (values.Count - 1) do begin
  643.             r.WriteString(IntToStr(i), data[i]);
  644.         end;
  645.         r.WriteInteger(SR_SORTINDEX_VALUE, values.count);
  646.         r.CloseKey;
  647.     end;
  648.     }
  649.     values.free;
  650.     data.Free;
  651. end;
  652.  
  653.  
  654. procedure TItemManager.MoveFile(FullName, ToPath : string);
  655. var exeName : string;
  656.     dest : string;
  657. begin
  658.     exeName := ExtractFileName(FullName);
  659.     dest := IncludeTrailingPathDelimiter(ToPath) + exeName;
  660.  
  661.     if (lowercase(dest) <> lowercase(fullname)) then begin
  662.         if FileExists( dest ) then begin
  663.             DeleteFile( dest );
  664.         end;
  665.  
  666.         if CopyFile(PChar(FullName), PChar(Dest), true) then begin
  667.             DeleteFile(FullName);
  668.         end;
  669.     end;
  670. end;
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677. initialization
  678.     ItemManager := TItemManager.Create();
  679. end.
  680.