home *** CD-ROM | disk | FTP | other *** search
/ Kompuutteri K-CD 2002 #1 / K-CD_2002-01.iso / Delphi / INFO / Extras / RegCleanUtility / Source / Unit2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-22  |  3.2 KB  |  107 lines

  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #pragma hdrstop
  5. #include "D6RegClean.h"
  6. #include "Unit2.h"
  7. //---------------------------------------------------------------------------
  8. #pragma package(smart_init)
  9. #pragma resource "*.dfm"
  10. TForm2 *Form2;
  11.  
  12. extern TRegClean *Cleanup;
  13. //---------------------------------------------------------------------------
  14. __fastcall TForm2::TForm2(TComponent* Owner)
  15.     : TForm(Owner)
  16. {
  17.     Reg = new TRegistry;
  18. }
  19. //---------------------------------------------------------------------------
  20.  
  21.  
  22.  
  23. void __fastcall TForm2::Button2Click(TObject *Sender)
  24. {
  25.     Application->Terminate();
  26. }
  27. //---------------------------------------------------------------------------
  28.  
  29. void __fastcall TForm2::CleanupReg(TObject *Sender)
  30. {
  31.     int nResult = 0;
  32.  
  33.     nResult += CleanDelphiReg("\\Software\\Borland\\Delphi\\6.0");    // do not localize
  34.     Reg->RootKey = HKEY_CURRENT_USER;
  35.     if (Reg->OpenKey("Software\\Borland\\DBExpress", false)) {        // do not localize
  36.         Reg->CloseKey();
  37.         if (MessageBox(NULL, LoadStr(MSG_REMOVEDBX).c_str(), LoadStr(TITLE_INFO).c_str(),
  38.             MB_YESNO | MB_ICONINFORMATION | MB_DEFBUTTON1 | MB_TASKMODAL | MB_SETFOREGROUND) == IDYES) {
  39.             nResult += CleanDelphiReg("\\Software\\Borland\\DBExpress");        // do not localize
  40.         }
  41.     }
  42.  
  43.     // display results, enable exit button
  44.     if (nResult == SUCCESS) {
  45.         this->Memo1->Lines->Add(LoadStr(MSG_SUCCESS));
  46.     } else if (nResult < FAILURE) {
  47.         this->Memo1->Lines->Add(LoadStr(MSG_PARTSUCCESS));
  48.     } else {
  49.         this->Memo1->Lines->Add(LoadStr(MSG_COMPLETEFAILED));
  50.     }
  51.  
  52.     this->Button1->Enabled = true;
  53.     this->Button1->SetFocus();
  54.  
  55.  
  56. }
  57. //---------------------------------------------------------------------------
  58.  
  59. int TForm2::CleanDelphiReg(String szKey)
  60. {
  61.     int nResult = 0;
  62.     String szMsg;
  63.  
  64.     Reg->RootKey = HKEY_CURRENT_USER;
  65.     if (Reg->OpenKey(szKey, false)) {
  66.         if (Reg->HasSubKeys()) {
  67.             TStringList *lstKeys = new TStringList;
  68.             int i;
  69.  
  70.             Reg->GetKeyNames(lstKeys);
  71.             for (i = 0; i < lstKeys->Count; i++) {
  72.                 lstKeys->Strings[i] = szKey + "\\" + lstKeys->Strings[i];
  73.                 nResult += this->CleanDelphiReg(lstKeys->Strings[i]);
  74.             }
  75.             delete lstKeys;
  76.         }
  77.         Reg->CloseKey();
  78.         try {
  79.             Cleanup->RemoveKey(szKey);
  80.             szMsg = LoadStr(MSG_REMOVED);
  81.             szMsg += szKey;
  82.             Form2->Memo1->Lines->Add(szMsg);
  83.             nResult += SUCCESS;
  84.         } catch (...) {
  85.             szMsg = LoadStr(MSG_FAILED);
  86.             szMsg += szKey;
  87.             Form2->Memo1->Lines->Add(szMsg);
  88.             nResult += FAILURE;
  89.         }
  90.     } else {
  91.         szMsg = LoadStr(MSG_NOTFOUND);
  92.         szMsg += szKey;
  93.         Form2->Memo1->Lines->Add(szMsg);
  94.         nResult += NOT_FOUND;
  95.     }
  96.  
  97.     return nResult;
  98. }
  99.  
  100. void __fastcall TForm2::Button1Click(TObject *Sender)
  101. {
  102.     Application->Terminate();
  103. }
  104. //---------------------------------------------------------------------------
  105.  
  106.  
  107.