unit BS1OverlayIconl; {$WARN SYMBOL_PLATFORM OFF} interface uses Windows, ActiveX, Classes, ComObj, StdVcl, Winapi.ShlObj, System.SysUtils, Winapi.Messages; type TBSOneOverlayIcon = class(TComObject, IShellIconOverlayIdentifier) protected { IShellExtInit } function IsMemberOf(pwszPath: PWideChar; dwAttrib: DWORD): HResult; stdcall; function GetPriority(out pIPriority: Integer): HResult; stdcall; function GetOverlayInfo(pwszIconFile: PWideChar; cchMax: Integer; var pIndex: Integer; var pdwFlags: DWORD): HResult; stdcall; end; TBSOneOverlayIconFac = class(TComObjectFactory) public procedure UpdateRegistry(Register: Boolean); override; end; const Class_BSOneOverlayIcon: TGUID = '{278C7A76-0CE2-4AC3-B32B-0D36B2F11671}'; implementation uses System.Win.ComServ, Winapi.ShellAPI, System.Win.Registry, Tocsg.Path, Tocsg.Safe, CttSchDefine, Tocsg.Strings, Tocsg.Encrypt, Tocsg.FileInfo, GlobalDefine; var _DocExtList: TStringList = nil; function SendCopyData(hRcv: HWND; nCmd: Integer; sData: String): LRESULT; stdcall; inline; var CopyData: TCopyDataStruct; begin try if hRcv = 0 then begin Result := 0; exit; end; ZeroMemory(@CopyData, SizeOf(CopyData)); CopyData.dwData := nCmd; CopyData.cbData := (Length(sData) + 1) * 2; CopyData.lpData := PChar(sData); Result := SendMessage(hRcv, WM_COPYDATA, 0, NativeInt(@CopyData)); except // ... end; end; { TBSOneOverlayIcon } function TBSOneOverlayIcon.IsMemberOf(pwszPath: PWideChar; dwAttrib: DWORD): HResult; stdcall; var sPath, sTemp: String; begin Result := S_FALSE; sPath := pwszPath; try if _DocExtList.IndexOf(GetFileExt(sPath)) <> -1 then begin if TTgEncrypt.CheckSign(sPath, SIG_DRM) then Result := S_OK; { var hSL: HWND := FindWindow('TDlgSlCoreMain', nil); if hSL <> 0 then begin case SendCopyData(hSL, 2121, sPath) of 101 : // BSOne-DRM begin Result := S_OK; end; // 102 : // AIP // begin // Result := S_OK; // end; end; // űëÀü¿¡ °¨Áö°¡ µÉ °æ¿ì ó¸® 24_0227 16:05:05 kku if Result = S_FALSE then begin if TTgEncrypt.CheckSign(sPath, DRM_SIGN_BSONE) then Result := S_OK; end; end; // else // if TTgEncrypt.CheckSign(sPath, DRM_SIGN_BSONE) then // begin // Result := S_OK; // end; // else begin // sTemp := GetAipLabel(sPath); // if (sTemp <> '') and (Pos('ÀϹÝ', sTemp) = 0) then // begin // Result := S_OK; // end; // end; } end; except // .. end; // if GetFileExt(sPath).ToUpper = 'DOCX' then // Result := S_OK; // if GetFileExt(sPath).ToUpper = 'TXT' then // begin // Guard(StrList, TStringList.Create); // try // StrList.LoadFromFile(sPath, TEncoding.UTF8); // except // StrList.LoadFromFile(sPath); // end; // // if Pos('tocsg', StrList.Text) > 0 then // Result := S_OK; // end; // if (dwAttrib and faReadonly) = faReadonly then // Result := S_OK // else // Result := S_FALSE; end; function TBSOneOverlayIcon.GetPriority(out pIPriority: Integer): HResult; stdcall; begin pIPriority := 0; Result := S_OK; end; function TBSOneOverlayIcon.GetOverlayInfo(pwszIconFile: PWideChar; cchMax: Integer; var pIndex: Integer; var pdwFlags: DWORD): HResult; stdcall; var sOverIconPath: WideString; begin sOverIconPath := 'C:\Program Files\Tocsg\eCrmHome\conf\Bs1drm.dat'; // sOverIconPath := 'C:\taskToCSG\eCrmHE\Images\24_0228 BSOne_DRM_MS-AIP\Yellow\DRM_L.ico'; pIndex := 0; lstrcpynW(pwszIconFile, PWideChar(sOverIconPath), cchMax); pdwFlags := ISIOI_ICONFILE or ISIOI_ICONINDEX; Result := S_OK; end; { TBSOneOverlayIconFac } procedure TBSOneOverlayIconFac.UpdateRegistry(Register: Boolean); var ClassID: string; begin if Register then begin inherited UpdateRegistry(Register); ClassID := GUIDToString(Class_BSOneOverlayIcon); CreateRegKey('Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\ BSOne1', '', ClassID, HKEY_LOCAL_MACHINE); if (Win32Platform = VER_PLATFORM_WIN32_NT) then with TRegistry.Create do try RootKey := HKEY_LOCAL_MACHINE; OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Shell Extensions', True); OpenKey('Approved', True); WriteString(ClassID, 'BSone-DRM Icon Overlay Shell Extension'); finally Free; end; end else begin DeleteRegKey('Software\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers\ BSOne1', HKEY_LOCAL_MACHINE); inherited UpdateRegistry(Register); end; end; initialization _DocExtList := TStringList.Create; _DocExtList.CaseSensitive := false; SplitString(DOC_EXTS_TAG, '|', _DocExtList); TBSOneOverlayIconFac.Create(ComServer, TBSOneOverlayIcon, Class_BSOneOverlayIcon, 'BSOneDrmOverIcon', 'BSOne-DRM', ciMultiInstance, tmApartment); finalization FreeAndNil(_DocExtList); end.