Subversion Repositories recyclebinunit

Rev

Rev 16 | Rev 18 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16 Rev 17
Line 1... Line 1...
1
////////////////////////////////////////////////////////////////////////////////////
1
////////////////////////////////////////////////////////////////////////////////////
2
// RECYCLE-BIN-FUNCTIONS BY DANIEL MARSCHALL                                      //
2
// RECYCLE-BIN-FUNCTIONS BY DANIEL MARSCHALL                                      //
3
// E-MAIL: info@daniel-marschall.de                                               //
3
// E-MAIL: info@daniel-marschall.de                                               //
4
// WEB:    www.daniel-marschall.de                                                //
4
// WEB:    www.daniel-marschall.de                                                //
5
////////////////////////////////////////////////////////////////////////////////////
5
////////////////////////////////////////////////////////////////////////////////////
6
// Revision: 16 JUN 2010                                                          //
6
// Revision: 18 JUN 2010                                                          //
7
// This unit is freeware, but please link to my website if you are using it!      //
7
// This unit is freeware, but please link to my website if you are using it!      //
8
////////////////////////////////////////////////////////////////////////////////////
8
////////////////////////////////////////////////////////////////////////////////////
9
// Successful tested with:                                                        //
9
// Successful tested with:                                                        //
10
// Windows 95b, 95b + IE4, 98-SE, XP-SP2, 2000-SP4, 2003-SRV-EE-SP1, VISTA        //
10
// Windows 95b, 95b + IE4, 98-SE, XP-SP2, 2000-SP4, 2003-SRV-EE-SP1, VISTA        //
11
////////////////////////////////////////////////////////////////////////////////////
11
////////////////////////////////////////////////////////////////////////////////////
Line 129... Line 129...
129
    cbSize      : dword;
129
    cbSize      : dword;
130
    i64Size     : int64;
130
    i64Size     : int64;
131
    i64NumItems : int64;
131
    i64NumItems : int64;
132
  end;
132
  end;
133
 
133
 
-
 
134
  GPOLICYBOOL = (gpUndefined, gpEnabled, gpDisabled);
-
 
135
 
134
const
136
const
135
  RECYCLER_CLSID = '{645FF040-5081-101B-9F08-00AA002F954E}';
137
  RECYCLER_CLSID = '{645FF040-5081-101B-9F08-00AA002F954E}';
136
 
138
 
137
{$IFDEF DEL6UP}
139
{$IFDEF DEL6UP}
138
function RecyclerGetDateTime(drive: char; fileid: string): tdatetime; overload;
140
function RecyclerGetDateTime(drive: char; fileid: string): tdatetime; overload;
Line 201... Line 203...
201
 
203
 
202
function RecyclerAddFileOrFolder(FileOrFolder: string; confirmation: boolean): boolean; overload;
204
function RecyclerAddFileOrFolder(FileOrFolder: string; confirmation: boolean): boolean; overload;
203
function RecyclerAddFileOrFolder(FileOrFolder: string): boolean; overload;
205
function RecyclerAddFileOrFolder(FileOrFolder: string): boolean; overload;
204
 
206
 
205
function RecyclerConfirmationDialogEnabled: boolean;
207
function RecyclerConfirmationDialogEnabled: boolean;
-
 
208
function RecyclerShellStateConfirmationDialogEnabled: boolean;
206
procedure RecyclerConfirmationDialogSetEnabled(NewSetting: boolean);
209
procedure RecyclerConfirmationDialogSetEnabled(NewSetting: boolean);
207
 
210
 
208
function RecyclerGetCurrentIconString: string;
211
function RecyclerGetCurrentIconString: string;
209
function RecyclerGetDefaultIconString: string;
212
function RecyclerGetDefaultIconString: string;
210
function RecyclerGetEmptyIconString: string;
213
function RecyclerGetEmptyIconString: string;
Line 252... Line 255...
252
// - RecyclerGetNumItems
255
// - RecyclerGetNumItems
253
// - RecyclerGetSize
256
// - RecyclerGetSize
254
// - RecyclerGetAPIInfo
257
// - RecyclerGetAPIInfo
255
function RecyclerQueryFunctionAvailable: boolean;
258
function RecyclerQueryFunctionAvailable: boolean;
256
 
259
 
-
 
260
function RecyclerGroupPolicyNoRecycleFiles: GPOLICYBOOL;
-
 
261
function RecyclerGroupPolicyConfirmFileDelete: GPOLICYBOOL;
-
 
262
function RecyclerGroupPolicyRecycleBinSize: integer;
-
 
263
 
-
 
264
function GPBoolToString(value: GPOLICYBOOL): String;
-
 
265
 
257
function RecyclerLibraryVersion: string;
266
function RecyclerLibraryVersion: string;
258
 
267
 
259
implementation
268
implementation
260
 
269
 
261
type
270
type
Line 2093... Line 2102...
2093
begin
2102
begin
2094
  result := RecyclerAddFileOrFolder(FileOrFolder, false);
2103
  result := RecyclerAddFileOrFolder(FileOrFolder, false);
2095
end;
2104
end;
2096
 
2105
 
2097
function RecyclerConfirmationDialogEnabled: boolean;
2106
function RecyclerConfirmationDialogEnabled: boolean;
-
 
2107
var
-
 
2108
  gp: GPOLICYBOOL;
-
 
2109
begin
-
 
2110
  gp := RecyclerGroupPolicyConfirmFileDelete;
-
 
2111
  if gp <> gpUndefined then
-
 
2112
  begin
-
 
2113
    result := gp = gpEnabled;
-
 
2114
  end
-
 
2115
  else
-
 
2116
  begin
-
 
2117
    result := RecyclerShellStateConfirmationDialogEnabled;
-
 
2118
  end;
-
 
2119
end;
-
 
2120
 
-
 
2121
function RecyclerShellStateConfirmationDialogEnabled: boolean;
2098
type
2122
type
2099
  TSHGetSettings = procedure (var lpss: SHELLSTATE; dwMask: DWORD) stdcall;
2123
  TSHGetSettings = procedure (var lpss: SHELLSTATE; dwMask: DWORD) stdcall;
2100
const
2124
const
2101
  C_SHGetSettings = 'SHGetSettings';
2125
  C_SHGetSettings = 'SHGetSettings';
2102
var
2126
var
Line 2560... Line 2584...
2560
    reg.Free;
2584
    reg.Free;
2561
  end;
2585
  end;
2562
end;
2586
end;
2563
 
2587
 
2564
function RecyclerGetPercentUsageAutoDeterminate(Drive: Char): integer;
2588
function RecyclerGetPercentUsageAutoDeterminate(Drive: Char): integer;
-
 
2589
var
-
 
2590
  gpSetting: integer;
2565
begin
2591
begin
-
 
2592
  gpSetting := RecyclerGroupPolicyRecycleBinSize;
-
 
2593
  if gpSetting <> -1 then
-
 
2594
    result := gpSetting
2566
  if RecyclerHasGlobalSettings then
2595
  else if RecyclerHasGlobalSettings then
2567
    result := RecyclerGlobalGetPercentUsage
2596
    result := RecyclerGlobalGetPercentUsage
2568
  else
2597
  else
2569
    result := RecyclerSpecificGetPercentUsage(Drive);
2598
    result := RecyclerSpecificGetPercentUsage(Drive);
2570
end;
2599
end;
2571
 
2600
 
Line 2679... Line 2708...
2679
  end;
2708
  end;
2680
end;
2709
end;
2681
 
2710
 
2682
function RecyclerIsNukeOnDeleteAutoDeterminate(Drive: Char): boolean;
2711
function RecyclerIsNukeOnDeleteAutoDeterminate(Drive: Char): boolean;
2683
begin
2712
begin
-
 
2713
  if RecyclerGroupPolicyNoRecycleFiles = gpEnabled then
-
 
2714
    result := true
2684
  if RecyclerHasGlobalSettings then
2715
  else if RecyclerHasGlobalSettings then
2685
    result := RecyclerGlobalIsNukeOnDelete
2716
    result := RecyclerGlobalIsNukeOnDelete
2686
  else
2717
  else
2687
    result := RecyclerSpecificIsNukeOnDelete(Drive);
2718
    result := RecyclerSpecificIsNukeOnDelete(Drive);
2688
end;
2719
end;
2689
 
2720
 
Line 2842... Line 2873...
2842
function RecyclerGetCLSID: string;
2873
function RecyclerGetCLSID: string;
2843
begin
2874
begin
2844
  result := RECYCLER_CLSID;
2875
  result := RECYCLER_CLSID;
2845
end;
2876
end;
2846
 
2877
 
2847
// Windows 95 without Internet Explorer 4 has not SHQueryRecycleBinA.
2878
// Windows 95 without Internet Explorer 4 has no SHQueryRecycleBinA.
2848
function RecyclerQueryFunctionAvailable: boolean;
2879
function RecyclerQueryFunctionAvailable: boolean;
2849
var
2880
var
2850
  RBHandle: THandle;
2881
  RBHandle: THandle;
2851
  SHQueryRecycleBin: TSHQueryRecycleBin;
2882
  SHQueryRecycleBin: TSHQueryRecycleBin;
2852
begin
2883
begin
Line 2862... Line 2893...
2862
  end;
2893
  end;
2863
 
2894
 
2864
  result := RBHandle <> 0;
2895
  result := RBHandle <> 0;
2865
end;
2896
end;
2866
 
2897
 
-
 
2898
const
-
 
2899
  GroupPolicyAcceptHKLMTrick = true;
-
 
2900
 
-
 
2901
// TODO: In future also detect for other users
-
 
2902
// TODO: Also make a setter (inkl. Message to Windows Explorer?)
-
 
2903
function RecyclerGroupPolicyNoRecycleFiles: GPOLICYBOOL;
-
 
2904
var
-
 
2905
  reg: TRegistry;
-
 
2906
begin
-
 
2907
  result := gpUndefined;
-
 
2908
 
-
 
2909
  reg := TRegistry.Create;
-
 
2910
  try
-
 
2911
    // If a value is set in HKEY_LOCAL_MACHINE, it will be prefered,
-
 
2912
    // even if gpedit.msc shows "Not configured"!
-
 
2913
    if GroupPolicyAcceptHKLMTrick then
-
 
2914
    begin
-
 
2915
      reg.RootKey := HKEY_LOCAL_MACHINE;
-
 
2916
      if reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer') then
-
 
2917
      begin
-
 
2918
        if reg.ValueExists('NoRecycleFiles') then
-
 
2919
        begin
-
 
2920
          if reg.ReadBool('NoRecycleFiles') then
-
 
2921
            result := gpEnabled
-
 
2922
          else
-
 
2923
            result := gpDisabled;
-
 
2924
          Exit;
-
 
2925
        end;
-
 
2926
        reg.CloseKey;
-
 
2927
      end;
-
 
2928
    end;
-
 
2929
 
-
 
2930
    reg.RootKey := HKEY_CURRENT_USER;
-
 
2931
    if reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer') then
-
 
2932
    begin
-
 
2933
      if reg.ValueExists('NoRecycleFiles') then
-
 
2934
      begin
-
 
2935
        if reg.ReadBool('NoRecycleFiles') then
-
 
2936
          result := gpEnabled
-
 
2937
        else
-
 
2938
          result := gpDisabled;
-
 
2939
      end;
-
 
2940
      reg.CloseKey;
-
 
2941
    end;
-
 
2942
  finally
-
 
2943
    reg.Free;
-
 
2944
  end;
-
 
2945
end;
-
 
2946
 
-
 
2947
// TODO: In future also detect for other users
-
 
2948
// TODO: Also make a setter (inkl. Message to Windows Explorer?)
-
 
2949
function RecyclerGroupPolicyConfirmFileDelete: GPOLICYBOOL;
-
 
2950
var
-
 
2951
  reg: TRegistry;
-
 
2952
begin
-
 
2953
  result := gpUndefined;
-
 
2954
  reg := TRegistry.Create;
-
 
2955
  try
-
 
2956
    // If a value is set in HKEY_LOCAL_MACHINE, it will be prefered,
-
 
2957
    // even if gpedit.msc shows "Not configured"!
-
 
2958
    if GroupPolicyAcceptHKLMTrick then
-
 
2959
    begin
-
 
2960
      reg.RootKey := HKEY_LOCAL_MACHINE;
-
 
2961
      if reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer') then
-
 
2962
      begin
-
 
2963
        if reg.ValueExists('ConfirmFileDelete') then
-
 
2964
        begin
-
 
2965
          if reg.ReadBool('ConfirmFileDelete') then
-
 
2966
            result := gpEnabled
-
 
2967
          else
-
 
2968
            result := gpDisabled;
-
 
2969
          Exit;
-
 
2970
        end;
-
 
2971
        reg.CloseKey;
-
 
2972
      end;
-
 
2973
    end;
-
 
2974
 
-
 
2975
    reg.RootKey := HKEY_CURRENT_USER;
-
 
2976
    if reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer') then
-
 
2977
    begin
-
 
2978
      if reg.ValueExists('ConfirmFileDelete') then
-
 
2979
      begin
-
 
2980
        if reg.ReadBool('ConfirmFileDelete') then
-
 
2981
          result := gpEnabled
-
 
2982
        else
-
 
2983
          result := gpDisabled;
-
 
2984
      end;
-
 
2985
      reg.CloseKey;
-
 
2986
    end;
-
 
2987
  finally
-
 
2988
    reg.Free;
-
 
2989
  end;
-
 
2990
end;
-
 
2991
 
-
 
2992
 
-
 
2993
// TODO: In future also detect for other users
-
 
2994
// TODO: Also make a setter (inkl. Message to Windows Explorer?)
-
 
2995
function RecyclerGroupPolicyRecycleBinSize: integer;
-
 
2996
var
-
 
2997
  reg: TRegistry;
-
 
2998
begin
-
 
2999
  result := -1;
-
 
3000
  reg := TRegistry.Create;
-
 
3001
  try
-
 
3002
    // If a value is set in HKEY_LOCAL_MACHINE, it will be prefered,
-
 
3003
    // even if gpedit.msc shows "Not configured"!
-
 
3004
    if GroupPolicyAcceptHKLMTrick then
-
 
3005
    begin
-
 
3006
      reg.RootKey := HKEY_LOCAL_MACHINE;
-
 
3007
      if reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer') then
-
 
3008
      begin
-
 
3009
        if reg.ValueExists('RecycleBinSize') then
-
 
3010
        begin
-
 
3011
          result := reg.ReadInteger('RecycleBinSize');
-
 
3012
          Exit;
-
 
3013
        end;
-
 
3014
        reg.CloseKey;
-
 
3015
      end;
-
 
3016
    end;
-
 
3017
 
-
 
3018
    reg.RootKey := HKEY_CURRENT_USER;
-
 
3019
    if reg.OpenKeyReadOnly('Software\Microsoft\Windows\CurrentVersion\Policies\Explorer') then
-
 
3020
    begin
-
 
3021
      if reg.ValueExists('RecycleBinSize') then
-
 
3022
        result := reg.ReadInteger('RecycleBinSize');
-
 
3023
      reg.CloseKey;
-
 
3024
    end;
-
 
3025
  finally
-
 
3026
    reg.Free;
-
 
3027
  end;
-
 
3028
end;
-
 
3029
 
-
 
3030
function GPBoolToString(value: GPOLICYBOOL): String;
-
 
3031
begin
-
 
3032
  case value of
-
 
3033
    gpUndefined: result := 'Not configured';
-
 
3034
    gpEnabled: result := 'Enabled';
-
 
3035
    gpDisabled: result := 'Disabled';
-
 
3036
  end;
-
 
3037
end;
-
 
3038
 
2867
function RecyclerLibraryVersion: string;
3039
function RecyclerLibraryVersion: string;
2868
begin
3040
begin
2869
  result := 'ViaThinkSoft Recycle Bin Unit [16 JUN 2010]';
3041
  result := 'ViaThinkSoft Recycle Bin Unit [18 JUN 2010]';
2870
end;
3042
end;
2871
 
3043
 
2872
end.
3044
end.