Ejemplo n.º 1
0
size_t wxDir::Traverse(wxDirTraverser& sink,
                       const wxString& filespec,
                       int flags) const
{
    wxCHECK_MSG( IsOpened(), (size_t)-1,
                 wxT("dir must be opened before traversing it") );

    // the total number of files found
    size_t nFiles = 0;

    // the name of this dir with path delimiter at the end
    const wxString prefix = GetNameWithSep();

    // first, recurse into subdirs
    if ( flags & wxDIR_DIRS )
    {
        wxString dirname;
        for ( bool cont = GetFirst(&dirname, wxEmptyString,
                                   (flags & ~(wxDIR_FILES | wxDIR_DOTDOT))
                                   | wxDIR_DIRS);
              cont;
              cont = cont && GetNext(&dirname) )
        {
            const wxString fulldirname = prefix + dirname;

            switch ( sink.OnDir(fulldirname) )
            {
                default:
                    wxFAIL_MSG(wxT("unexpected OnDir() return value") );
                    wxFALLTHROUGH;

                case wxDIR_STOP:
                    cont = false;
                    break;

                case wxDIR_CONTINUE:
                    {
                        wxDir subdir;

                        // don't give the error messages for the directories
                        // which we can't open: there can be all sorts of good
                        // reason for this (e.g. insufficient privileges) and
                        // this shouldn't be treated as an error -- instead
                        // let the user code decide what to do
                        bool ok;
                        do
                        {
                            wxLogNull noLog;
                            ok = subdir.Open(fulldirname);
                            if ( !ok )
                            {
                                // ask the user code what to do
                                bool tryagain;
                                switch ( sink.OnOpenError(fulldirname) )
                                {
                                    default:
                                        wxFAIL_MSG(wxT("unexpected OnOpenError() return value") );
                                        wxFALLTHROUGH;

                                    case wxDIR_STOP:
                                        cont = false;
                                        wxFALLTHROUGH;

                                    case wxDIR_IGNORE:
                                        tryagain = false;
                                        break;

                                    case wxDIR_CONTINUE:
                                        tryagain = true;
                                }

                                if ( !tryagain )
                                    break;
                            }
                        }
                        while ( !ok );

                        if ( ok )
                        {
                            nFiles += subdir.Traverse(sink, filespec, flags);
                        }
                    }
                    break;

                case wxDIR_IGNORE:
                    // nothing to do
                    ;
            }
        }
    }

    // now enum our own files
    if ( flags & wxDIR_FILES )
    {
        flags &= ~wxDIR_DIRS;

        wxString filename;
        bool cont = GetFirst(&filename, filespec, flags);
        while ( cont )
        {
            wxDirTraverseResult res = sink.OnFile(prefix + filename);
            if ( res == wxDIR_STOP )
                break;

            wxASSERT_MSG( res == wxDIR_CONTINUE,
                          wxT("unexpected OnFile() return value") );

            nFiles++;

            cont = GetNext(&filename);
        }
    }

    return nFiles;
}
Ejemplo n.º 2
0
	void* AOScanningThread::Entry()
	{
		_aoHandler->_volumes.clear();
		_aoHandler->_aoUserCacheFolder = _pstFileName.GetPathWithSep() + "Cache" + _pstFileName.GetPathSeparator();

		// Open Cache folder
		wxDir cacheDir(_aoHandler->_aoUserCacheFolder.GetFullPath());

		// Unable to open cache folder, abort
		if (!cacheDir.IsOpened())
		{
			return 0;
		}

		wxString outDir = _aoHandler->GetAOUsersFolder().GetFullPath() + "\\" + _aoHandler->GetAOUserName() + "\\Temp\\";

		// Scan for volumes
		wxString volumeFolderName;
		bool volumeFolderExists = cacheDir.GetFirst(&volumeFolderName, "*.vol", wxDIR_DIRS);
		while (volumeFolderExists && !TestDestroy())
		{
			// Convert relative path to absolute path
			volumeFolderName = _aoHandler->_aoUserCacheFolder.GetFullPath() + volumeFolderName;

			// Open folder
			AOCVolume volumeFolder(volumeFolderName);
			{
				auto dirHandler = std::make_shared<wxDir>(volumeFolder._volumeName.GetFullPath());

				if (_eventReceiver)
				{
					auto event = new StatusUpdateEvent("Scanning Volume: " + volumeFolder._volumeName.GetFullName());
					wxQueueEvent(_eventReceiver, event);
				}

				// Scan for AOC files
				wxString aocFileName;
				bool aocFileExists = dirHandler->GetFirst(&aocFileName, "*.aoc", wxDIR_FILES);
				while (aocFileExists && !TestDestroy())
				{
					// Convert relative path to absolute path
					aocFileName = dirHandler->GetNameWithSep() + aocFileName;

					// Create file handler
					AOCFile aocFile(aocFileName);
					//auto fileHandler = std::make_shared<wxFile>(aocFile._fileName.GetFullPath());
					//auto outFileHandler = std::make_shared<wxFile>(outDir + aocFile._fileName.GetName() + ".msg", wxFile::write);

					volumeFolder._files.push_back(aocFile);

					aocFileExists = dirHandler->GetNext(&aocFileName);
				}
				wxString logMessage;
				logMessage << "Finished scanning volume " << volumeFolder._volumeName.GetFullName() << " (" << volumeFolder.GetAOCFiles().size() << " items)";
				wxLogMessage(logMessage);
			}
			_aoHandler->_volumes.push_back(volumeFolder);

			volumeFolderExists = cacheDir.GetNext(&volumeFolderName);
		}

		return 0;
	}