int Directory::GetFilesCount(const CString& path, const bool& recursive) { CString pathMask = path + _T("\\*"); WIN32_FIND_DATA findData; HANDLE findResult = FindFirstFile(pathMask, &findData); int filesCount = 0; do { if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if (!recursive) continue; if ((CString) findData.cFileName == _T(".")) continue; if ((CString) findData.cFileName == _T("..")) continue; CString innerPath = path + _T('\\') + (CString) findData.cFileName; filesCount += GetFilesCount(innerPath, recursive); } else ++filesCount; } while (FindNextFile(findResult, &findData)); FindClose(findResult); return filesCount; }
bool wxDebugReport::DoProcess() { wxString msg(_("A debug report has been generated. It can be found in")); msg << wxT("\n") wxT("\t") << GetDirectory() << wxT("\n\n") << _("And includes the following files:\n"); wxString name, desc; const size_t count = GetFilesCount(); for ( size_t n = 0; n < count; n++ ) { GetFile(n, &name, &desc); msg += wxString::Format("\t%s: %s\n", name, desc); } msg += _("\nPlease send this report to the program maintainer, thank you!\n"); wxLogMessage(wxT("%s"), msg.c_str()); // we have to do this or the report would be deleted, and we don't even // have any way to ask the user if he wants to keep it from here Reset(); return true; }
bool wxDebugReportCompress::DoProcess() { const size_t count = GetFilesCount(); if ( !count ) return false; // create the compressed report file outside of the directory with the // report files as it will be deleted by wxDebugReport dtor but we want to // keep this one: for this we simply treat the directory name as the name // of the file so that its last component becomes our base name wxFileName fn(GetDirectory()); if ( !m_zipDir.empty() ) fn.SetPath(m_zipDir); if ( !m_zipName.empty() ) fn.SetName(m_zipName); fn.SetExt("zip"); // create the streams wxFFileOutputStream os(fn.GetFullPath(), wxT("wb")); wxZipOutputStream zos(os, 9); // add all files to the ZIP one wxString name, desc; for ( size_t n = 0; n < count; n++ ) { GetFile(n, &name, &desc); wxZipEntry *ze = new wxZipEntry(name); ze->SetComment(desc); if ( !zos.PutNextEntry(ze) ) return false; const wxFileName filename(GetDirectory(), name); wxFFileInputStream is(filename.GetFullPath()); if ( !is.IsOk() || !zos.Write(is).IsOk() ) return false; } if ( !zos.Close() ) return false; m_zipfile = fn.GetFullPath(); return true; }
bool wxDebugReport::Process() { if ( !GetFilesCount() ) { wxLogError(_("Debug report generation has failed.")); return false; } if ( !DoProcess() ) { wxLogError(_("Processing debug report has failed, leaving the files in \"%s\" directory."), GetDirectory().c_str()); Reset(); return false; } return true; }
bool wxDebugReportCompress::DoProcess() { const size_t count = GetFilesCount(); if ( !count ) return false; // create the streams wxFileName fn(GetDirectory(), GetReportName(), _T("zip")); wxFFileOutputStream os(fn.GetFullPath(), _T("wb")); wxZipOutputStream zos(os, 9); // add all files to the ZIP one wxString name, desc; for ( size_t n = 0; n < count; n++ ) { GetFile(n, &name, &desc); wxZipEntry *ze = new wxZipEntry(name); ze->SetComment(desc); if ( !zos.PutNextEntry(ze) ) return false; wxFileName filename(fn.GetPath(), name); wxFFileInputStream is(filename.GetFullPath()); if ( !is.IsOk() || !zos.Write(is).IsOk() ) return false; } if ( !zos.Close() ) return false; m_zipfile = fn.GetFullPath(); return true; }
int CItem::CompareSibling(const CTreeListItem *tlib, int subitem) const { CItem *other = (CItem *)tlib; int r=0; switch (subitem) { case COL_NAME: if (GetType() == IT_DRIVE) { ASSERT(other->GetType() == IT_DRIVE); r = signum(GetPath().CompareNoCase(other->GetPath())); } else { r = signum(m_name.CompareNoCase(other->m_name)); } break; case COL_SUBTREEPERCENTAGE: if (MustShowReadJobs()) r = signum(m_readJobs - other->m_readJobs); else r = signum(GetFraction() - other->GetFraction()); break; case COL_PERCENTAGE: r = signum(GetFraction() - other->GetFraction()); break; case COL_SUBTREETOTAL: r = signum(GetSize() - other->GetSize()); break; case COL_ITEMS: r = signum(GetItemsCount() - other->GetItemsCount()); break; case COL_FILES: r = signum(GetFilesCount() - other->GetFilesCount()); break; case COL_SUBDIRS: r = signum(GetSubdirsCount() - other->GetSubdirsCount()); break; case COL_LASTCHANGE: { if (m_lastChange < other->m_lastChange) return -1; else if (m_lastChange == other->m_lastChange) return 0; else return 1; } break; case COL_ATTRIBUTES: r = signum(GetSortAttributes() - other->GetSortAttributes()); break; default: ASSERT(false); break; } return r; }
CString CItem::GetText(int subitem) const { CString s; switch (subitem) { case COL_NAME: s = m_name; break; case COL_SUBTREEPERCENTAGE: if (IsDone()) { ASSERT(m_readJobs == 0); //s = "ok"; } else { if (m_readJobs == 1) s.LoadString(IDS_ONEREADJOB); else s.FormatMessage(IDS_sREADJOBS, FormatCount(m_readJobs)); } break; case COL_PERCENTAGE: if (GetOptions()->IsShowTimeSpent() && MustShowReadJobs() || IsRootItem()) { s.Format(_T("[%s s]"), FormatMilliseconds(GetTicksWorked())); } else { s.Format(_T("%s%%"), FormatDouble(GetFraction() * 100)); } break; case COL_SUBTREETOTAL: s = FormatBytes(GetSize()); break; case COL_ITEMS: if (GetType() != IT_FILE && GetType() != IT_FREESPACE && GetType() != IT_UNKNOWN) s = FormatCount(GetItemsCount()); break; case COL_FILES: if (GetType() != IT_FILE && GetType() != IT_FREESPACE && GetType() != IT_UNKNOWN) s = FormatCount(GetFilesCount()); break; case COL_SUBDIRS: if (GetType() != IT_FILE && GetType() != IT_FREESPACE && GetType() != IT_UNKNOWN) s = FormatCount(GetSubdirsCount()); break; case COL_LASTCHANGE: if (GetType() != IT_FREESPACE && GetType() != IT_UNKNOWN) { s = FormatFileTime(m_lastChange); } break; case COL_ATTRIBUTES: if (GetType() != IT_FREESPACE && GetType() != IT_UNKNOWN && GetType() != IT_MYCOMPUTER && GetType() != IT_FILESFOLDER) { s = FormatAttributes(GetAttributes()); } break; default: ASSERT(0); break; } return s; }
// Return: false if deleted bool CItem::StartRefresh() { ASSERT(GetType() != IT_FREESPACE); ASSERT(GetType() != IT_UNKNOWN); m_ticksWorked = 0; // Special case IT_MYCOMPUTER if (GetType() == IT_MYCOMPUTER) { ZeroMemory(&m_lastChange, sizeof(m_lastChange)); for (int i=0; i < GetChildrenCount(); i++) GetChild(i)->StartRefresh(); return true; } ASSERT(GetType() == IT_FILE || GetType() == IT_DRIVE || GetType() == IT_DIRECTORY || GetType() == IT_FILESFOLDER); bool wasExpanded = IsVisible() && IsExpanded(); int oldScrollPosition = 0; if (IsVisible()) oldScrollPosition = GetScrollPosition(); UncacheImage(); // Upward clear data UpdateLastChange(); UpwardSetUndone(); UpwardAddReadJobs(-GetReadJobs()); ASSERT(GetReadJobs() == 0); if (GetType() == IT_FILE) GetParent()->UpwardAddFiles(-1); else UpwardAddFiles(-GetFilesCount()); ASSERT(GetFilesCount() == 0); if (GetType() == IT_DIRECTORY || GetType() == IT_DRIVE) UpwardAddSubdirs(-GetSubdirsCount()); ASSERT(GetSubdirsCount() == 0); UpwardAddSize(-GetSize()); ASSERT(GetSize() == 0); RemoveAllChildren(); UpwardRecalcLastChange(); // Special case IT_FILESFOLDER if (GetType() == IT_FILESFOLDER) { CFileFindWDS finder; BOOL b = finder.FindFile(GetFindPattern()); while (b) { b = finder.FindNextFile(); if (finder.IsDirectory()) continue; FILEINFO fi; fi.name = finder.GetFileName(); fi.attributes = finder.GetAttributes(); // Retrieve file size fi.length = finder.GetCompressedLength(); finder.GetLastWriteTime(&fi.lastWriteTime); AddFile(fi); UpwardAddFiles(1); } SetDone(); if (wasExpanded) GetTreeListControl()->ExpandItem(this); return true; } ASSERT(GetType() == IT_FILE || GetType() == IT_DRIVE || GetType() == IT_DIRECTORY); // The item may have been deleted. bool deleted = false; if (GetType() == IT_DRIVE) deleted = !DriveExists(GetPath()); else if (GetType() == IT_FILE) deleted = !FileExists(GetPath()); else if (GetType() == IT_DIRECTORY) deleted = !FolderExists(GetPath()); if (deleted) { if (GetParent() == NULL) { GetDocument()->UnlinkRoot(); } else { GetParent()->UpwardRecalcLastChange(); GetParent()->RemoveChild(GetParent()->FindChildIndex(this)); // --> delete this } return false; } // Case IT_FILE if (GetType() == IT_FILE) { CFileFindWDS finder; BOOL b = finder.FindFile(GetPath()); if (b) { finder.FindNextFile(); if (!finder.IsDirectory()) { FILEINFO fi; fi.name = finder.GetFileName(); fi.attributes = finder.GetAttributes(); // Retrieve file size fi.length = finder.GetCompressedLength(); finder.GetLastWriteTime(&fi.lastWriteTime); SetLastChange(fi.lastWriteTime); UpwardAddSize(fi.length); UpwardUpdateLastChange(GetLastChange()); GetParent()->UpwardAddFiles(1); } } SetDone(); return true; } ASSERT(GetType() == IT_DRIVE || GetType() == IT_DIRECTORY); if (GetType() == IT_DIRECTORY && !IsRootItem() && GetApp()->IsMountPoint(GetPath()) && !GetOptions()->IsFollowMountPoints()) return true; if (GetType() == IT_DIRECTORY && !IsRootItem() && GetApp()->IsJunctionPoint(GetPath()) && !GetOptions()->IsFollowJunctionPoints()) return true; // Initiate re-read SetReadJobDone(false); // Re-create <free space> and <unknown> if (GetType() == IT_DRIVE) { if (GetDocument()->OptionShowFreeSpace()) CreateFreeSpaceItem(); if (GetDocument()->OptionShowUnknown()) CreateUnknownItem(); } DoSomeWork(0); if (wasExpanded) GetTreeListControl()->ExpandItem(this); if (IsVisible()) SetScrollPosition(oldScrollPosition); return true; }