/* * $Logfile: /DescentIII/Main/editor/OrphanRemoveDlg.cpp $ * $Revision: 1.1.1.1 $ * $Date: 2003-08-26 03:57:38 $ * $Author: kevinb $ * * Orphan file delete * * $Log: not supported by cvs2svn $ * * 4 4/09/99 3:46p Jeff * handle new texture sound names * * 3 3/19/99 10:34a Jeff * enable/disable controls when thinking * * 2 3/18/99 8:41p Jeff * created orphan hunter dialog * * $NoKeywords: $ */ // OrphanRemoveDlg.cpp : implementation file // #include "stdafx.h" #include "editor.h" #include "OrphanRemoveDlg.h" #include "manage.h" #include "doorpage.h" #include "gamefilepage.h" #include "genericpage.h" #include "shippage.h" #include "soundpage.h" #include "texpage.h" #include "weaponpage.h" #include "ddio.h" #include "mem.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // COrphanRemoveDlg dialog COrphanRemoveDlg::COrphanRemoveDlg(CWnd* pParent /*=NULL*/) : CDialog(COrphanRemoveDlg::IDD, pParent) { //{{AFX_DATA_INIT(COrphanRemoveDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void COrphanRemoveDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(COrphanRemoveDlg) DDX_Control(pDX, IDC_LIST, m_List); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(COrphanRemoveDlg, CDialog) //{{AFX_MSG_MAP(COrphanRemoveDlg) ON_CBN_SELCHANGE(IDC_DIRECTORY, OnSelchangeDirectory) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // COrphanRemoveDlg message handlers bool HasFilesCheckedOut(void) { int i; for (i=0;iEnableWindow(enable); wnd = (CWnd *)GetDlgItem(IDCANCEL); wnd->EnableWindow(enable); wnd = (CWnd *)GetDlgItem(IDC_DIRECTORY); wnd->EnableWindow(enable); } void COrphanRemoveDlg::SetStatus(char *status) { CWnd *stat = (CWnd *)GetDlgItem(IDC_STATUS); stat->SetWindowText(status); Descent->defer(); } void COrphanRemoveDlg::OnOK() { if(HasFilesCheckedOut()) { OutrageMessageBox("You can't have any files checked out file doing this operation"); return; } if(MessageBox("Are you sure you want to remove the orphans permanently?",NULL,MB_YESNO)!=IDYES) return; SetStatus("Deleting Files"); char directory[_MAX_PATH]; CString dir; CComboBox *combo = (CComboBox *)GetDlgItem(IDC_DIRECTORY); int sel = combo->GetCurSel(); if(sel==-1) return; combo->GetLBText(sel,dir); ddio_MakePath(directory,LocalD3Dir,"data",dir.GetBuffer(0),NULL); char fullpath[_MAX_PATH]; int size = m_List.GetCount(); for(int i=0;idefer(); return found; } int filelen(char *filename,char *dir) { char path[_MAX_PATH]; ddio_MakePath(path,dir,filename,NULL); CFILE *cf = cfopen(filename,"rb"); if(!cf) return 0; int len = cfilelength(cf); cfclose(cf); return len; } bool isdirectory(char *filename,char *basepath) { char fullpath[_MAX_PATH]; ddio_MakePath(fullpath,basepath,filename,NULL); char olddir[_MAX_PATH]; ddio_GetWorkingDir(olddir,_MAX_PATH); if(ddio_SetWorkingDir(fullpath)) { ddio_SetWorkingDir(olddir); return true; } return false; } void COrphanRemoveDlg::OnSelchangeDirectory() { CString dir; CComboBox *combo = (CComboBox *)GetDlgItem(IDC_DIRECTORY); int sel = combo->GetCurSel(); if(sel==-1) return; SetStatus("Updating File List"); Enable(false); combo->GetLBText(sel,dir); m_List.ResetContent(); char fullpath[_MAX_PATH]; ddio_MakePath(fullpath,LocalD3Dir,"data",dir.GetBuffer(0),NULL); char oldpath[_MAX_PATH]; ddio_GetWorkingDir(oldpath,_MAX_PATH); ddio_SetWorkingDir(fullpath); char filename[_MAX_PATH]; int num_files = 0; int total_filesize = 0; CWnd *stats = (CWnd *)GetDlgItem(IDC_STATS); char data[256]; sprintf(data,"Num Files: %d\r\nSize: %dK",0,0); stats->SetWindowText(data); if(ddio_FindFileStart("*.*",filename)) { if(!isdirectory(filename,fullpath) && !IsFileUsed(filename)) { m_List.AddString(filename); num_files++; total_filesize += filelen(filename,fullpath); sprintf(data,"Num Files: %d\r\nSize: %dK",num_files,total_filesize/1024); stats->SetWindowText(data); } while(ddio_FindNextFile(filename)) { if(!isdirectory(filename,fullpath) && !IsFileUsed(filename)) { m_List.AddString(filename); num_files++; total_filesize += filelen(filename,fullpath); sprintf(data,"Num Files: %d\r\nSize: %dK",num_files,total_filesize/1024); stats->SetWindowText(data); } } } ddio_FindFileClose(); ddio_SetWorkingDir(oldpath); //select all for(int i=0;iAddString(DirectoryNames[i]); } Enable(true); SetStatus("Ready..."); return TRUE; } void COrphanRemoveDlg::OnCancel() { CDialog::OnCancel(); }