Ejemplo n.º 1
0
AsyncFile*
Ndbfs::createAsyncFile(){

  // Check limit of open files
  if (m_maxFiles !=0 && theFiles.size() ==  m_maxFiles) {
    // Print info about all open files
    for (unsigned i = 0; i < theFiles.size(); i++){
      AsyncFile* file = theFiles[i];
      ndbout_c("%2d (0x%lx): %s", i, (long) file, file->isOpen()?"OPEN":"CLOSED");
    }
    ERROR_SET(fatal, NDBD_EXIT_AFS_MAXOPEN,""," Ndbfs::createAsyncFile");
  }

  AsyncFile* file = new AsyncFile(* this);
  file->doStart();

  // Put the file in list of all files
  theFiles.push_back(file);

#ifdef VM_TRACE
  infoEvent("NDBFS: Created new file thread %d", theFiles.size());
#endif
  
  return file;
}
Ejemplo n.º 2
0
void
Restore::execDUMP_STATE_ORD(Signal* signal){
  jamEntry();

  if (signal->theData[0] == DumpStateOrd::RestoreRates)
  {
    jam();
    Uint64 rate = m_bytes_restored * 1000 /
      (m_millis_spent == 0? 1: m_millis_spent);
    
    g_eventLogger->info("LDM instance %u: Restored LCP : %u fragments,"
                        " %llu rows, " 
                        "%llu bytes, %llu millis, %llu bytes/s",
                        instance(),
                        m_frags_restored, 
                        m_rows_restored,
                        m_bytes_restored,
                        m_millis_spent,
                        rate);
    infoEvent("LDM instance %u: Restored LCP : %u fragments, %llu rows, " 
              "%llu bytes, %llu millis, %llu bytes/s",
              instance(),
              m_frags_restored, 
              m_rows_restored,
              m_bytes_restored,
              m_millis_spent,
              rate);
  }
}
Ejemplo n.º 3
0
void WorkerThread::runRezip() {
	emit(beginRunRezip());
	emit(stageEvent("Finding and saving modified game data"));
	
	emit(infoEvent("Identifying modified files (including previously modified files)"));
	QMap<QString, uint32_t> newChecksums;
	collectFiles(m_tempPath, &newChecksums);
	QStringList modified; // TODO: also determine removed files?
	QMapIterator<QString, uint32_t> i(newChecksums);
	while (i.hasNext()) {
		i.next();
		if(!m_checksums.contains(i.key()) || m_checksums[i.key()] != i.value()) { modified << i.key(); }
	}
	
	if(modified.empty()) {
		emit(infoEvent("No modified files found"));
		return;
	}
	
	emit(infoEvent("Rezipping modified files"));

	QString gameFileBase = QFileInfo(m_gameFileName).baseName();
	QString diffFileName = m_dataPath + "/" + gameFileBase + __WHDRun__DiffSuffix;
	CZipArchive zip;
	try {
		zip.Open(diffFileName.toUtf8(), CZipArchive::zipCreate);

		// TODO: review that path finding stuff some time.
		QDir tempDir(m_tempPath); tempDir.makeAbsolute();
		foreach(QString externalPath, modified) {
			QDir externalDir(externalPath); externalDir.makeAbsolute();
			QString internalPath = tempDir.relativeFilePath(externalDir.absolutePath());
			zip.AddNewFile((LPCTSTR)externalPath.toUtf8(),
				(LPCTSTR)internalPath.toUtf8(), CZipCompressor::levelBest);
		}

		zip.Close();
	} catch(CZipException ex) {
Ejemplo n.º 4
0
void WorkerThread::runEmulator() {
	emit(beginRunEmulator());
	emit(stageEvent("Running game in WinUAE"));
	QProcess emulatorProcess(NULL);
	m_emulatorProcess = &emulatorProcess;
	emulatorProcess.start(m_emuFileName, QStringList() << "-f" << m_configFileName, QIODevice::NotOpen);
	if(!emulatorProcess.waitForStarted()) {
		m_emulatorProcess = NULL;
		emit(errorEvent("Error while starting WinUAE"));
		m_die = true; // no need to rezip
		return;
	}
	emit(emulatorRunning(true));
	emit(infoEvent("Waiting for WinUAE to finish"));
	emulatorProcess.waitForFinished(-1); // wait until WinUAE is actually done
	emit(emulatorRunning(false));
	m_emulatorProcess = NULL;
	if(emulatorProcess.exitCode() == 0) {
		emit(infoEvent("WinUAE finished without errors"));
	} else {
		emit(errorEvent(QString("WinUAE finished with error code %1").arg(emulatorProcess.exitCode())));
	}
	emit(endRunEmulator());
}
Ejemplo n.º 5
0
void wxSashLayoutWindow::OnCalculateLayout(wxCalculateLayoutEvent& event)
{
    wxRect clientSize(event.GetRect());

    int flags = event.GetFlags();

    if (!IsShown())
        return;

    // Let's assume that all windows stretch the full extent of the window in
    // the direction of that window orientation. This will work for non-docking toolbars,
    // and the status bar. Note that the windows have to have been created in a certain
    // order to work, else you might get a left-aligned window going to the bottom
    // of the window, and the status bar appearing to the right of it. The
    // status bar would have to be created after or before the toolbar(s).

    wxRect thisRect;

    // Try to stretch
    int length = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? clientSize.width : clientSize.height;
    wxLayoutOrientation orient = GetOrientation();

    // We assume that a window that says it's horizontal, wants to be stretched in that
    // direction. Is this distinction too fine? Do we assume that any horizontal
    // window needs to be stretched in that direction? Possibly.
    int whichDimension = (GetOrientation() == wxLAYOUT_HORIZONTAL) ? wxLAYOUT_LENGTH_X : wxLAYOUT_LENGTH_Y;

    wxQueryLayoutInfoEvent infoEvent(GetId());
    infoEvent.SetEventObject(this);
    infoEvent.SetRequestedLength(length);
    infoEvent.SetFlags(orient | whichDimension);

    if (!GetEventHandler()->ProcessEvent(infoEvent))
        return;

    wxSize sz = infoEvent.GetSize();

    if (sz.x == 0 && sz.y == 0) // Assume it's invisible
        return;

    // Now we know the size it wants to be. We wish to decide where to place it, i.e.
    // how it's aligned.
    switch (GetAlignment())
    {
        case wxLAYOUT_TOP:
        {
            thisRect.x = clientSize.x; thisRect.y = clientSize.y;
            thisRect.width = sz.x; thisRect.height = sz.y;
            clientSize.y += thisRect.height;
            clientSize.height -= thisRect.height;
            break;
        }
        case wxLAYOUT_LEFT:
        {
            thisRect.x = clientSize.x; thisRect.y = clientSize.y;
            thisRect.width = sz.x; thisRect.height = sz.y;
            clientSize.x += thisRect.width;
            clientSize.width -= thisRect.width;
            break;
        }
        case wxLAYOUT_RIGHT:
        {
            thisRect.x = clientSize.x + (clientSize.width - sz.x); thisRect.y = clientSize.y;
            thisRect.width = sz.x; thisRect.height = sz.y;
            clientSize.width -= thisRect.width;
            break;
        }
        case wxLAYOUT_BOTTOM:
        {
            thisRect.x = clientSize.x; thisRect.y = clientSize.y + (clientSize.height - sz.y);
            thisRect.width = sz.x; thisRect.height = sz.y;
            clientSize.height -= thisRect.height;
            break;
        }
        case wxLAYOUT_NONE:
        {
            break;
        }

    }

    if ((flags & wxLAYOUT_QUERY) == 0)
    {
        // If not in query mode, resize the window.
        // TODO: add wxRect& form to wxWindow::SetSize
        wxSize sz2 = GetSize();
        wxPoint pos = GetPosition();
        SetSize(thisRect.x, thisRect.y, thisRect.width, thisRect.height);

        // Make sure the sash is erased when the window is resized
        if ((pos.x != thisRect.x || pos.y != thisRect.y || sz2.x != thisRect.width || sz2.y != thisRect.height) &&
            (GetSashVisible(wxSASH_TOP) || GetSashVisible(wxSASH_RIGHT) || GetSashVisible(wxSASH_BOTTOM) || GetSashVisible(wxSASH_LEFT)))
            Refresh(true);

    }

    event.SetRect(clientSize);
}
Ejemplo n.º 6
0
void
Ndbfs::execDUMP_STATE_ORD(Signal* signal)
{
  if(signal->theData[0] == 19){
    return;
  }
  if(signal->theData[0] == DumpStateOrd::NdbfsDumpFileStat){
    infoEvent("NDBFS: Files: %d Open files: %d",
	      theFiles.size(),
	      theOpenFiles.size());
    infoEvent(" Idle files: %d Max opened files: %d",
	       theIdleFiles.size(),
	       m_maxOpenedFiles);
    infoEvent(" Max files: %d",
	      m_maxFiles);
    infoEvent(" Requests: %d",
	      theRequestPool->size());

    return;
  }
  if(signal->theData[0] == DumpStateOrd::NdbfsDumpOpenFiles){
    infoEvent("NDBFS: Dump open files: %d", theOpenFiles.size());
    
    for (unsigned i = 0; i < theOpenFiles.size(); i++){
      AsyncFile* file = theOpenFiles.getFile(i);
      infoEvent("%2d (0x%x): %s", i,file, file->theFileName.c_str());
    }
    return;
  }
  if(signal->theData[0] == DumpStateOrd::NdbfsDumpAllFiles){
    infoEvent("NDBFS: Dump all files: %d", theFiles.size());
    
    for (unsigned i = 0; i < theFiles.size(); i++){
      AsyncFile* file = theFiles[i];
      infoEvent("%2d (0x%x): %s", i,file, file->isOpen()?"OPEN":"CLOSED");
    }
    return;
  }
  if(signal->theData[0] == DumpStateOrd::NdbfsDumpIdleFiles){
    infoEvent("NDBFS: Dump idle files: %d", theIdleFiles.size());
    
    for (unsigned i = 0; i < theIdleFiles.size(); i++){
      AsyncFile* file = theIdleFiles[i];
      infoEvent("%2d (0x%x): %s", i,file, file->isOpen()?"OPEN":"CLOSED");
    }
    return;
  }

  if(signal->theData[0] == 404)
  {
    ndbrequire(signal->getLength() == 2);
    Uint32 file= signal->theData[1];
    AsyncFile* openFile = theOpenFiles.find(file);
    ndbrequire(openFile != 0);
    ndbout_c("File: %s %p", openFile->theFileName.c_str(), openFile);
    Request* curr = openFile->m_current_request;
    Request* last = openFile->m_last_request;
    if(curr)
      ndbout << "Current request: " << *curr << endl;
    if(last)
       ndbout << "Last request: " << *last << endl;

    ndbout << "theReportTo " << *openFile->theReportTo << endl;
    ndbout << "theMemoryChannelPtr" << *openFile->theMemoryChannelPtr << endl;

    ndbout << "All files: " << endl;
    for (unsigned i = 0; i < theFiles.size(); i++){
      AsyncFile* file = theFiles[i];
      ndbout_c("%2d (0x%lx): %s", i, (long) file, file->isOpen()?"OPEN":"CLOSED");
    }
  }
}//Ndbfs::execDUMP_STATE_ORD()
Ejemplo n.º 7
0
void WorkerThread::runUnzip() {
	emit(beginRunUnzip());
	emit(stageEvent("Extracting and merging game data"));
	
	emit(infoEvent("Unzipping original game files"));
	CZipArchive zip;
	try {
	    zip.Open(m_gameFileName.toStdString().c_str(), CZipArchive::zipOpenReadOnly);
		
		ZIP_SIZE_TYPE totalSize = 0;
		for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
			totalSize += zip.GetFileInfo(i)->m_uUncomprSize; // uncompressed size
			QString name = QString::fromUtf8(zip.GetFileInfo(i)->GetFileName());
			if(!validName(name)) {
				emit(errorEvent("Game pack contains illegal file names (e.g. " + name + ")"));
				emit(infoEvent("A near future release of WHDRun will fix this problem, sorry for the inconvenience"));
				m_die = true;
				return;
			}
		}
		emit(unzipTotalSize(totalSize));

		ZIP_SIZE_TYPE progress = 0;
		for(ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
			progress += zip.GetFileInfo(i)->m_uUncomprSize;
			zip.ExtractFile(i, m_tempPath.toUtf8());
			emit(unzipProgress(progress));
		}

	    zip.Close();
    } catch(CZipException ex) {
		zip.Close(CZipArchive::afAfterException);
		emit(errorEvent(QString("Error while unzipping: %1").arg((LPCTSTR)ex.GetErrorDescription())));
		m_die = true; // no need to rezip
		return;
	}

	emit(infoEvent("Collecting checksums of unmodified files"));
	emit(beginCollect());
	m_checksums.clear();
	collectFiles(m_tempPath, &m_checksums); // TODO: progress for this? (should always be quick)
	
	QString gameFileBase = QFileInfo(m_gameFileName).baseName();
	QString diffFileName = m_dataPath + "/" + gameFileBase + __WHDRun__DiffSuffix;
	if(QFileInfo(diffFileName).exists()) {
		emit(infoEvent("Merging original game files with previously modified files"));
		CZipArchive zip;
		try {
		    zip.Open(diffFileName.toUtf8(), CZipArchive::zipOpenReadOnly);

			//TODO: progress infoEvent for this? (should always be quick)
			for (ZIP_INDEX_TYPE i = 0; i < zip.GetCount(); i++) {
				zip.ExtractFile(i, m_tempPath.toUtf8());
			}

		    zip.Close();
	    } catch(CZipException ex) {
			zip.Close(CZipArchive::afAfterException);
			emit(errorEvent(QString("Error while unzipping changes: %1").arg((LPCTSTR)ex.GetErrorDescription())));
			m_die = true; // no need to rezip
			return;
		}
	}
	
	emit(endRunUnzip());
}