home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 April / enter-2004-04.iso / files / httrack-3.30.exe / {app} / src_win / WinHTTrack / NewProj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2003-09-17  |  13.2 KB  |  517 lines

  1. // NewProj.cpp : implementation file
  2. //
  3.  
  4. // pour lecture dir
  5. //#include "kernel32.h"
  6.  
  7. #include "stdafx.h"
  8. #include "Shell.h"
  9. #include "NewProj.h"
  10.  
  11. /* Externe C */
  12. extern "C" {
  13.   #include "htscore.h"
  14. }
  15.  
  16. #include "XSHBrowseForFolder.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. extern HICON httrack_icon;
  25. extern CNewProj* dialog0;
  26.  
  27. // Helper
  28. extern LaunchHelp* HtsHelper;
  29.  
  30. /* Main WizTab frame */
  31. #include "WizTab.h"
  32. extern CWizTab* this_CWizTab;
  33.  
  34. /* Main splitter frame */
  35. #include "DialogContainer.h"
  36. #include "splitter.h"
  37. extern CSplitterFrame* this_CSplitterFrame;
  38.  
  39. /* DirTreeView */
  40. #include "DirTreeView.h"
  41. extern CDirTreeView* this_DirTreeView;
  42.  
  43. /* reference sur objet Wid1 */
  44. #include "Wid1.h"
  45. extern Wid1* dialog1;
  46.  
  47. /* shellapp */
  48. extern CShellApp* CShellApp_app;
  49.  
  50. /* crΘation structure */
  51. extern "C" HTSEXT_API int structcheck(char* s);
  52.  
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CNewProj dialog
  56.  
  57. IMPLEMENT_DYNCREATE(CNewProj, CPropertyPage)
  58.  
  59. CNewProj::CNewProj()
  60.     : CPropertyPage(CNewProj::IDD)
  61. {
  62.   dialog0=this;    /* NOTER REFERENCE */
  63.   can_click_next=TRUE;
  64.     //{{AFX_DATA_INIT(CNewProj)
  65.     m_projname = _T("");
  66.     m_projpath = _T("");
  67.     //}}AFX_DATA_INIT
  68. }
  69.  
  70. CNewProj::~CNewProj() {
  71.   dialog0=NULL;
  72. }
  73.  
  74.  
  75. void CNewProj::DoDataExchange(CDataExchange* pDX)
  76. {
  77.     CPropertyPage::DoDataExchange(pDX);
  78.     //{{AFX_DATA_MAP(CNewProj)
  79.     DDX_Control(pDX, IDC_projname, m_ctl_projname);
  80.     DDX_Text(pDX, IDC_projname, m_projname);
  81.     DDX_Text(pDX, IDC_projpath, m_projpath);
  82.     //}}AFX_DATA_MAP
  83. }
  84.  
  85.  
  86. #define wm_CEasyDropTargetCallback (WM_USER + 1)
  87. BEGIN_MESSAGE_MAP(CNewProj, CPropertyPage)
  88.     //{{AFX_MSG_MAP(CNewProj)
  89.     ON_BN_CLICKED(IDC_br, Onbr)
  90.     ON_EN_CHANGE(IDC_projpath, OnChangeprojpath)
  91.     ON_CBN_EDITCHANGE(IDC_projname, OnChangeprojname)
  92.     ON_WM_CREATE()
  93.     ON_CBN_SELCHANGE(IDC_projname, OnSelchangeprojname)
  94.     //}}AFX_MSG_MAP
  95.   ON_COMMAND(ID_HELP_FINDER,OnHelpInfo2)
  96.   ON_COMMAND(ID_HELP,OnHelpInfo2)
  97.     ON_COMMAND(ID_DEFAULT_HELP,OnHelpInfo2)
  98.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  99.   //
  100.   ON_MESSAGE( wm_CEasyDropTargetCallback, DragDropText)
  101. END_MESSAGE_MAP()
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CNewProj message handlers
  105.  
  106. CString CNewProj::GetBasePath() {
  107.   CString st=m_projpath;
  108.   st.Replace('/','\\');
  109.   st+="\\";
  110.   return st;
  111. }
  112.  
  113. CString CNewProj::GetName() {
  114.   return m_projname;
  115. }
  116.  
  117. CString CNewProj::GetPath0() {
  118.   CString st=m_projpath;
  119.   st.Replace('/','\\');
  120.   st+="\\";
  121.   st+=m_projname;
  122.   return st;
  123. }
  124.  
  125. CString CNewProj::GetPath() {
  126.   CString st=GetPath0();
  127.   st+="\\";
  128.   return st;
  129. }
  130.  
  131. LRESULT CNewProj::OnWizardNext() {
  132.   CString st,stp="";
  133.   char tempo[8192];
  134.  
  135.   GetDlgItemText(IDC_projpath,stp);
  136.   strcpybuff(tempo,stp);
  137.   if ((tempo[strlen(tempo)-1]=='/') || (tempo[strlen(tempo)-1]=='\\'))
  138.     tempo[strlen(tempo)-1]='\0';
  139.   stp=tempo;
  140.  
  141.   // ecrire
  142.   CString strSection       = "DefaultValues";    
  143.   CWinApp* pApp = AfxGetApp();
  144.   pApp->WriteProfileString(strSection,"BasePath",stp);
  145.  
  146.   GetDlgItemText(IDC_projname,st);
  147.   st.TrimLeft();
  148.   st.TrimRight();
  149.   strcpybuff(tempo,st);
  150.   // caractΦres interdits
  151.   {
  152.     int i;
  153.     char* a=NULL;
  154.     for(i=0;i<9;i++)
  155.       while(a=strchr(tempo,("\\/:*?\"<>|")[i])) 
  156.         *a=' ';
  157.   }
  158.   //
  159.   //while(a=strchr(tempo,' ')) *a='_';      // PAS de _
  160.   SetDlgItemText(IDC_projname,tempo);
  161.  
  162.   // ModifiΘ et sauvable
  163.   GetDlgItemText(IDC_projpath,stp);
  164.   if ((stp.Right(1)!="\\") && (stp.Right(1)!="/"))    // ajouter /
  165.     stp+="\\";
  166.   GetDlgItemText(IDC_projname,st);
  167.   this_CSplitterFrame->SetNewName(stp+st+".whtt");
  168.   //GetDlgItemText(IDC_projpath,st);
  169.   //this_CSplitterFrame->GetActiveDocument()->SetPathName(st);
  170.  
  171.   if (can_click_next)
  172.     return 0;
  173.   else
  174.     return -1;
  175. }
  176.  
  177. void CNewProj::Onbr() 
  178. {
  179.   CString st,spth;
  180.   char pth[256];
  181.   GetDlgItemText(IDC_projpath,spth);
  182.   strcpybuff(pth,spth);
  183.   st=XSHBrowseForFolder(this->m_hWnd,"Select a path name for mirror",pth);
  184.   if (st.GetLength()>0) {
  185.     if (st.Right(1)=='\\')
  186.       st=st.Left(st.GetLength()-1);
  187.     SetDlgItemText(IDC_projpath,st);
  188.   }
  189.  
  190. }
  191.  
  192. BOOL CNewProj::OnInitDialog() 
  193. {
  194.     CPropertyPage::OnInitDialog();
  195.   SetIcon(httrack_icon,false);
  196.   SetIcon(httrack_icon,true);
  197.   EnableToolTips(true);     // TOOL TIPS
  198.   SetForegroundWindow();   // yop en premier plan!
  199.  
  200.   // disabled
  201.   OnChangeprojname();
  202.  
  203.   // Patcher l'interface pour les Franτais ;-)
  204.   if (LANG_T(-1)) {    // Patcher en franτais
  205.     SetWindowText( LANG(LANG_S10));
  206.     // SetDlgItemText(IDOK,LANG(LANG_NEXT )); // "SUIVANT ->");
  207.     // SetDlgItemText(IDCANCEL,LANG(LANG_QUIT));  // exit 
  208.     SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11));
  209.     SetDlgItemText(IDC_STATIC_basepath,LANG(LANG_S12));
  210.     //SetDlgItemText(IDC_STATIC_updtcontinue,LANG(LANG_S13));
  211.   }
  212.   
  213.   CString strSection       = "DefaultValues";    
  214.   CWinApp* pApp = AfxGetApp();
  215.   CString st;
  216.  
  217.   st = pApp->GetProfileString(strSection, "BasePath");
  218.   if (m_projpath.GetLength()==0) {
  219.     if (st != "")
  220.       SetDlgItemText(IDC_projpath,st);    
  221.     else
  222.       SetDlgItemText(IDC_projpath,LANG(LANG_S20));    
  223.   }
  224.  
  225.   return TRUE;
  226. }
  227.  
  228. void CNewProj::OnChangeprojpath() 
  229. {
  230.   CWaitCursor wait;
  231.   CString st;
  232.   CString old_name;
  233.   char tempo[HTS_URLMAXSIZE*2];
  234.  
  235.   GetDlgItemText(IDC_projname,old_name);
  236.   GetDlgItemText(IDC_projpath,st);
  237.   tempo[0] = '\0';
  238.   strcatbuff(tempo, st);
  239.   if ((tempo[strlen(tempo)-1]=='/') || (tempo[strlen(tempo)-1]=='\\')) {
  240.     tempo[strlen(tempo)-1]='\0';
  241.     //SetDlgItemText(IDC_projpath,tempo);
  242.   }
  243.   strcatbuff(tempo,"\\");
  244.  
  245.   // chargement de la liste
  246.   m_ctl_projname.ResetContent();
  247.   WIN32_FIND_DATA find;
  248.   char  pth[MAX_PATH + 32];
  249.   strcpybuff(pth,tempo);
  250.   strcatbuff(pth,"*.*");
  251.   HANDLE h = FindFirstFile(pth,&find);
  252.   if (h != INVALID_HANDLE_VALUE) {
  253.     do {
  254.       if (find.dwFileAttributes  & FILE_ATTRIBUTE_DIRECTORY )
  255.       if (!(find.dwFileAttributes  & (FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN) ))
  256.       if (strcmp(find.cFileName,".."))
  257.         if (strcmp(find.cFileName,".")) {
  258.           CString st;
  259.           st=tempo;
  260.           st=st+find.cFileName;
  261.           st=st+"\\hts-cache";
  262.  
  263.           WIN32_FIND_DATA find2;
  264.           HANDLE h2 = FindFirstFile(st,&find2);
  265.           if (h2 != INVALID_HANDLE_VALUE) {
  266.             FindClose(h2);
  267.             m_ctl_projname.InsertString(-1,find.cFileName);
  268.           }
  269.         }
  270.     } while(FindNextFile(h,&find));
  271.     FindClose(h);
  272.   }
  273.  
  274.   // nouveau nom!
  275.   SetDlgItemText(IDC_projname,old_name);
  276.   OnChangeprojname();
  277. }
  278.  
  279.  
  280.  
  281. // ------------------------------------------------------------
  282. // TOOL TIPS
  283. //
  284. // ajouter dans le .cpp:
  285. // remplacer les deux Wid1:: par le nom de la classe::
  286. // dans la message map, ajouter
  287. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  288. // dans initdialog ajouter
  289. // EnableToolTips(true);     // TOOL TIPS
  290. //
  291. // ajouter dans le .h:
  292. // char* GetTip(int id);
  293. // et en generated message map
  294. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  295. BOOL CNewProj::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  296. {
  297.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  298.   UINT nID =pNMHDR->idFrom;
  299.   if (pTTT->uFlags & TTF_IDISHWND)
  300.   {
  301.     // idFrom is actually the HWND of the tool
  302.     nID = ::GetDlgCtrlID((HWND)nID);
  303.     if(nID)
  304.     {
  305.       char* st=GetTip(nID);
  306.       if (st != "") {
  307.         pTTT->lpszText = st;
  308.         pTTT->hinst = AfxGetResourceHandle();
  309.         return(TRUE);
  310.       }
  311.     }
  312.   }
  313.   return(FALSE);
  314. }
  315. char* CNewProj::GetTip(int ID)
  316. {
  317.   switch(ID) {
  318.     case IDC_projname:  return LANG(LANG_S1); break;
  319.     case IDC_projpath:  return LANG(LANG_S2); break;
  320.     //case IDC_projlist:  return LANG(LANG_S3); break;
  321.     case IDC_br:        return LANG(LANG_S4); break;
  322.     case IDCANCEL:     return LANG(LANG_G20); break; // "Quit WinHTTrack","Quittter WinHTTrack"); break;
  323.     case IDOK:         return LANG(LANG_G23); break; // "Click to continue","Clic pour continuer"); break;
  324.   }
  325.   return "";
  326. }
  327. // TOOL TIPS
  328. // ------------------------------------------------------------
  329.  
  330.  
  331. void CNewProj::OnChangeprojname() 
  332. {
  333.   CString stl;
  334.   GetDlgItemText(IDC_projname,stl);
  335.   Changeprojname(stl);
  336. }
  337.  
  338. void CNewProj::Changeprojname(CString stl) {
  339.   CWaitCursor wait;
  340.   CString st;
  341.   //
  342.   if (stl.GetLength()==0 || stl.GetLength() > HTS_URLMAXSIZE) {
  343.     //m_ctl_idok.ModifyStyle(0,WS_DISABLED);
  344.     SetDlgItemText(IDC_STATIC_comments,LANG(LANG_S30));
  345.     SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11c));
  346.     this_CWizTab->SetWizardButtons(PSWIZB_BACK);
  347.     can_click_next=FALSE;
  348.   } else {
  349.     char tempo[HTS_URLMAXSIZE*2];
  350.     GetDlgItemText(IDC_projpath,st);
  351.     if (st.GetLength() + stl.GetLength() + 32 > sizeof(tempo)) {
  352.       can_click_next=FALSE;
  353.     } else {
  354.       strcpybuff(tempo,st);
  355.       strcatbuff(tempo,"/");
  356.       strcatbuff(tempo,stl);
  357.       strcatbuff(tempo,"/");
  358.       if (fexist(fconcat(tempo,"hts-cache/winprofile.ini"))) {    // un cache est prΘsent
  359.         if (fsize(fconcat(tempo,"hts-cache/winprofile.ini"))>0) {   // taille log contr⌠le>0
  360.           CString strSection       = "OptionsValues";
  361.           CString st = MyGetProfileString(fconcat(tempo,"hts-cache/winprofile.ini"),strSection,"CurrentUrl");
  362.           //
  363.           SetDlgItemText(IDC_STATIC_comments,st);
  364.           SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11b));
  365.         } else {
  366.           SetDlgItemText(IDC_STATIC_comments,LANG(LANG_S31));
  367.           SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11));
  368.         }
  369.       } else {
  370.         SetDlgItemText(IDC_STATIC_comments,LANG(LANG_S31));
  371.         SetDlgItemText(IDC_STATIC_projname,LANG(LANG_S11));
  372.       }
  373.       //m_ctl_idok.ModifyStyle(WS_DISABLED,0);
  374.       //if (!can_click_next)
  375.       this_CWizTab->SetWizardButtons(PSWIZB_BACK|PSWIZB_NEXT);
  376.       can_click_next=TRUE;
  377.     }
  378.   }
  379.   //m_ctl_idok.RedrawWindow();
  380. }
  381.  
  382.  
  383. // help
  384. // Appel aide
  385. BOOL CNewProj::OnHelpInfo2() {
  386.   return OnHelpInfo(NULL);
  387. }
  388.  
  389. BOOL CNewProj::OnHelpInfo(HELPINFO* dummy) 
  390. {
  391.   //return CPropertyPage::OnHelpInfo(pHelpInfo);
  392.   //AfxGetApp()->WinHelp(0,HELP_FINDER);    // Index du fichier Hlp
  393.   HtsHelper->Help("step1.html");
  394.   //HtsHelper->Help();
  395.   return true;
  396. }
  397.  
  398.  
  399. extern HWND App_Main_HWND;
  400. int CNewProj::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  401. {
  402.   //lpCreateStruct->hwndParent=AfxGetApp()->GetMainWnd()->m_hWnd;
  403.   lpCreateStruct->hwndParent=App_Main_HWND;
  404.     if (CPropertyPage::OnCreate(lpCreateStruct) == -1)
  405.         return -1;
  406.     
  407.   // Drag&Drop
  408.   drag=new CEasyDropTarget(this);
  409.   if (drag->IsRegistered()) {
  410.     drag->SetTextCallback(wm_CEasyDropTargetCallback);
  411.   }
  412.     
  413.     return 0;
  414. }
  415.  
  416. // Message from CEasyDropTarget
  417. LRESULT CNewProj::DragDropText(WPARAM wParam,LPARAM lParam) {
  418.   if (lParam) {
  419.     CString st=*((CString*) lParam);
  420.     CLIPFORMAT cfFormat=wParam;
  421.     if (cfFormat==CF_HDROP) {
  422.       if (st.Right(5).CompareNoCase(".whtt")==0)
  423.         st=st.Left(st.GetLength()-5);
  424.       if(st.GetLength()<256) {
  425.         char s[256];
  426.         strcpybuff(s,st);
  427.         if (!fexist(s)) {
  428.           if (st.Find('\n')<0) {
  429.             int pos=st.ReverseFind('\\');
  430.             SetDlgItemText(IDC_projpath,st.Mid(0,pos));
  431.             SetDlgItemText(IDC_projname,st.Mid(pos+1));
  432.             //
  433.             OnChangeprojpath();
  434.             OnChangeprojname();
  435.           } else
  436.             AfxMessageBox(LANG(LANG_DIAL3),MB_SYSTEMMODAL);
  437.         } else
  438.           AfxMessageBox(LANG(LANG_DIAL4),MB_SYSTEMMODAL);
  439.       }
  440.     } else
  441.       AfxMessageBox(LANG(LANG_DIAL5),MB_SYSTEMMODAL);
  442.   }
  443.   return 0;
  444. }
  445.  
  446.  
  447. void CNewProj::OnSelchangeprojname() 
  448. {
  449.   CString stl;
  450.   int r;
  451.   if ((r=m_ctl_projname.GetCurSel()) != CB_ERR) {
  452.     m_ctl_projname.GetLBText(r,stl);
  453.   } else
  454.     GetDlgItemText(IDC_projname,stl);
  455.   Changeprojname(stl);
  456. }
  457.  
  458. BOOL CNewProj::OnSetActive( ) {
  459.   //this_CWizTab->SetWizardButtons(PSWIZB_BACK);
  460.  
  461.   WHTT_LOCATION("NewProj");
  462.   //if (!can_click_next) {
  463.   // structure visible
  464.   CString st;
  465.   GetDlgItemText(IDC_projpath,st);    
  466.   this_DirTreeView->EnsureVisible(st+"\\index.html");
  467.   this_CWizTab->SetDlgItemText(IDCANCEL,LANG_CANCEL);
  468.   //} else
  469.   //this_CWizTab->PressButton(PSBTN_NEXT);
  470.   
  471.   return 1;
  472. }
  473.  
  474. BOOL CNewProj::OnQueryCancel( ) {
  475.   this_CSplitterFrame->SetNewView(0,1,RUNTIME_CLASS(CDialogContainer));
  476.   return 0;
  477. }
  478.  
  479. BOOL CNewProj::OnKillActive( ) {
  480.   CString st;
  481.   char tempo[HTS_URLMAXSIZE*2];
  482.   GetDlgItemText(IDC_projpath,st);
  483.   strcpybuff(tempo,st);
  484.   if ((tempo[strlen(tempo)-1]=='/') || (tempo[strlen(tempo)-1]=='\\')) {
  485.     tempo[strlen(tempo)-1]='\0';
  486.     SetDlgItemText(IDC_projpath,tempo);
  487.   }
  488.  
  489.   UpdateData(TRUE);         // DoDataExchange
  490.  
  491.   // crΘer structure
  492.   {
  493.     char dest[HTS_URLMAXSIZE*2];
  494.     int i=0;
  495.     strcpybuff(dest,GetPath()+"hts-cache\\");
  496.     {
  497.       char* a;
  498.       while(a=strchr(dest,'\\')) *a='/';
  499.       structcheck(dest);
  500.     }
  501.   }
  502.  
  503.   CShellApp_app->end_path=dialog0->GetBasePath();
  504.   CShellApp_app->end_path_complete=dialog0->GetPath();
  505.   Build_TopIndex(FALSE);
  506.  
  507.   // structure visible
  508.   this_DirTreeView->EnsureVisible(GetPath()+"hts-cache");
  509.  
  510.   // charger prΘfs
  511.   dialog1->OnChangepathlog();
  512.  
  513.   return 1;
  514. }
  515.  
  516.  
  517.