Beispiel #1
0
void DOMFileSystemBase::copy(const EntryBase* source,
                             EntryBase* parent,
                             const String& newName,
                             EntryCallback* successCallback,
                             ErrorCallbackBase* errorCallback,
                             SynchronousType synchronousType) {
  if (!fileSystem()) {
    reportError(errorCallback, FileError::kAbortErr);
    return;
  }

  String destinationPath;
  if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName,
                                                destinationPath)) {
    reportError(errorCallback, FileError::kInvalidModificationErr);
    return;
  }

  std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(
      successCallback, errorCallback, m_context, parent->filesystem(),
      destinationPath, source->isDirectory()));
  callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);

  fileSystem()->copy(createFileSystemURL(source),
                     parent->filesystem()->createFileSystemURL(destinationPath),
                     std::move(callbacks));
}
Beispiel #2
0
void DOMFileSystemBase::getDirectory(const EntryBase* entry,
                                     const String& path,
                                     const FileSystemFlags& flags,
                                     EntryCallback* successCallback,
                                     ErrorCallbackBase* errorCallback,
                                     SynchronousType synchronousType) {
  if (!fileSystem()) {
    reportError(errorCallback, FileError::kAbortErr);
    return;
  }

  String absolutePath;
  if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) {
    reportError(errorCallback, FileError::kInvalidModificationErr);
    return;
  }

  std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(
      successCallback, errorCallback, m_context, this, absolutePath, true));
  callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);

  if (flags.createFlag())
    fileSystem()->createDirectory(createFileSystemURL(absolutePath),
                                  flags.exclusive(), std::move(callbacks));
  else
    fileSystem()->directoryExists(createFileSystemURL(absolutePath),
                                  std::move(callbacks));
}
void DOMFileSystemBase::getMetadata(const EntryBase* entry, MetadataCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
    if (!fileSystem()) {
        reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
        return;
    }

    std::unique_ptr<AsyncFileSystemCallbacks> callbacks(MetadataCallbacks::create(successCallback, errorCallback, m_context, this));
    callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);
    fileSystem()->readMetadata(createFileSystemURL(entry), std::move(callbacks));
}
void LocalFileSystem::resolveURLInternal(
    RawPtr<ExecutionContext> context,
    const KURL& fileSystemURL,
    CallbackWrapper* callbacks)
{
    if (!fileSystem()) {
        fileSystemNotAvailable(context, callbacks);
        return;
    }
    fileSystem()->resolveURL(fileSystemURL, callbacks->release());
}
void LocalFileSystem::deleteFileSystemInternal(
    RawPtr<ExecutionContext> context,
    FileSystemType type,
    CallbackWrapper* callbacks)
{
    if (!fileSystem()) {
        fileSystemNotAvailable(context, callbacks);
        return;
    }
    KURL storagePartition = KURL(KURL(), context->getSecurityOrigin()->toString());
    fileSystem()->deleteFileSystem(storagePartition, static_cast<WebFileSystemType>(type), callbacks->release());
}
void DOMFileSystemBase::getParent(const EntryBase* entry, EntryCallback* successCallback, ErrorCallback* errorCallback)
{
    if (!fileSystem()) {
        reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
        return;
    }

    ASSERT(entry);
    String path = DOMFilePath::getDirectory(entry->fullPath());

    fileSystem()->directoryExists(createFileSystemURL(path), EntryCallbacks::create(successCallback, errorCallback, m_context, this, path, true));
}
Beispiel #7
0
void DOMFileSystem::createFile(const FileEntry* fileEntry,
                               BlobCallback* successCallback,
                               ErrorCallbackBase* errorCallback) {
  KURL fileSystemURL = createFileSystemURL(fileEntry);
  if (!fileSystem()) {
    reportError(errorCallback, FileError::kAbortErr);
    return;
  }

  fileSystem()->createSnapshotFileAndReadMetadata(
      fileSystemURL,
      SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL,
                                   successCallback, errorCallback, m_context));
}
int DOMFileSystemBase::readDirectory(DirectoryReaderBase* reader, const String& path, EntriesCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
    if (!fileSystem()) {
        reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
        return 0;
    }

    ASSERT(DOMFilePath::isAbsolute(path));

    std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntriesCallbacks::create(successCallback, errorCallback, m_context, reader, path));
    callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);

    return fileSystem()->readDirectory(createFileSystemURL(path), std::move(callbacks));
}
Beispiel #9
0
// static
PassRefPtr<DOMFileSystem> DOMFileSystem::create(ScriptExecutionContext* context, const String& name, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
{
    RefPtr<DOMFileSystem> fileSystem(adoptRef(new DOMFileSystem(context, name, asyncFileSystem)));
    fileSystem->suspendIfNeeded();
    InspectorInstrumentation::didOpenFileSystem(fileSystem.get());
    return fileSystem.release();
}
Beispiel #10
0
// static
DOMFileSystem* DOMFileSystem::create(ExecutionContext* context,
                                     const String& name,
                                     FileSystemType type,
                                     const KURL& rootURL) {
  DOMFileSystem* fileSystem(new DOMFileSystem(context, name, type, rootURL));
  fileSystem->suspendIfNeeded();
  return fileSystem;
}
void DOMFileSystemBase::copy(const EntryBase* source, EntryBase* parent, const String& newName, EntryCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
    if (!fileSystem()) {
        reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
        return;
    }

    String destinationPath;
    if (!verifyAndGetDestinationPathForCopyOrMove(source, parent, newName, destinationPath)) {
        reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
        return;
    }

    OwnPtr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, m_context, parent->filesystem(), destinationPath, source->isDirectory()));
    callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);

    fileSystem()->copy(createFileSystemURL(source), parent->filesystem()->createFileSystemURL(destinationPath), callbacks.release());
}
Beispiel #12
0
void DOMFileSystem::createWriter(const FileEntry* fileEntry, PassOwnPtr<FileWriterCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
    ASSERT(fileEntry);

    RefPtrWillBeRawPtr<FileWriter> fileWriter = FileWriter::create(executionContext());
    OwnPtr<FileWriterBaseCallback> conversionCallback = ConvertToFileWriterCallback::create(successCallback);
    OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create(fileWriter, conversionCallback.release(), errorCallback, m_context);
    fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter.get(), callbacks.release());
}
Beispiel #13
0
void DOMFileSystem::createWriter(const FileEntry* fileEntry,
                                 FileWriterCallback* successCallback,
                                 ErrorCallbackBase* errorCallback) {
  ASSERT(fileEntry);

  if (!fileSystem()) {
    reportError(errorCallback, FileError::kAbortErr);
    return;
  }

  FileWriter* fileWriter = FileWriter::create(getExecutionContext());
  FileWriterBaseCallback* conversionCallback =
      ConvertToFileWriterCallback::create(successCallback);
  std::unique_ptr<AsyncFileSystemCallbacks> callbacks =
      FileWriterBaseCallbacks::create(fileWriter, conversionCallback,
                                      errorCallback, m_context);
  fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter,
                                 std::move(callbacks));
}
void DOMFileSystemBase::removeRecursively(const EntryBase* entry, VoidCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
    if (!fileSystem()) {
        reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
        return;
    }

    ASSERT(entry && entry->isDirectory());
    // We don't allow calling remove() on the root directory.
    if (entry->fullPath() == String(DOMFilePath::root)) {
        reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
        return;
    }

    std::unique_ptr<AsyncFileSystemCallbacks> callbacks(VoidCallbacks::create(successCallback, errorCallback, m_context, this));
    callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);

    fileSystem()->removeRecursively(createFileSystemURL(entry), std::move(callbacks));
}
File* DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, ExceptionState& exceptionState)
{
    KURL fileSystemURL = createFileSystemURL(fileEntry);
    CreateFileHelper::CreateFileResult* result(CreateFileHelper::CreateFileResult::create());
    fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, CreateFileHelper::create(result, fileEntry->name(), fileSystemURL, type()));
    if (result->m_failed) {
        exceptionState.throwDOMException(result->m_code, "Could not create '" + fileEntry->name() + "'.");
        return nullptr;
    }
    return result->m_file.get();
}
/** @return the sectors used in the Partition's FileSystem or, in case of an extended partition, the sum of used sectors of the Partition's children */
qint64 Partition::sectorsUsed() const
{
	if (!roles().has(PartitionRole::Extended))
		return fileSystem().sectorsUsed();

	qint64 result = 0;
	foreach (const Partition* p, children())
		if (!p->roles().has(PartitionRole::Unallocated))
			result += p->length();

	return result;
}
void DOMFileSystemBase::getFile(const EntryBase* entry, const String& path, const FileSystemFlags& flags, EntryCallback* successCallback, ErrorCallback* errorCallback, SynchronousType synchronousType)
{
    if (!fileSystem()) {
        reportError(errorCallback, FileError::create(FileError::ABORT_ERR));
        return;
    }

    String absolutePath;
    if (!pathToAbsolutePath(m_type, entry, path, absolutePath)) {
        reportError(errorCallback, FileError::create(FileError::INVALID_MODIFICATION_ERR));
        return;
    }

    std::unique_ptr<AsyncFileSystemCallbacks> callbacks(EntryCallbacks::create(successCallback, errorCallback, m_context, this, absolutePath, false));
    callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);

    if (flags.createFlag())
        fileSystem()->createFile(createFileSystemURL(absolutePath), flags.exclusive(), std::move(callbacks));
    else
        fileSystem()->fileExists(createFileSystemURL(absolutePath), std::move(callbacks));
}
Beispiel #18
0
void DOMFileSystemBase::remove(const EntryBase* entry,
                               VoidCallback* successCallback,
                               ErrorCallbackBase* errorCallback,
                               SynchronousType synchronousType) {
  if (!fileSystem()) {
    reportError(errorCallback, FileError::kAbortErr);
    return;
  }

  ASSERT(entry);
  // We don't allow calling remove() on the root directory.
  if (entry->fullPath() == String(DOMFilePath::root)) {
    reportError(errorCallback, FileError::kInvalidModificationErr);
    return;
  }

  std::unique_ptr<AsyncFileSystemCallbacks> callbacks(
      VoidCallbacks::create(successCallback, errorCallback, m_context, this));
  callbacks->setShouldBlockUntilCompletion(synchronousType == Synchronous);

  fileSystem()->remove(createFileSystemURL(entry), std::move(callbacks));
}
static void JNICALL JniSetDefaultFileSystem(JNIEnv* env, jclass clazz, jlong ptr, jstring jBasePath)
{
  AdblockPlus::JsEnginePtr& engine = *JniLongToTypePtr<AdblockPlus::JsEnginePtr>(ptr);

  try
  {
    AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem());

    std::string basePath = JniJavaToStdString(env, jBasePath);
    reinterpret_cast<AdblockPlus::DefaultFileSystem*>(fileSystem.get())->SetBasePath(basePath);

    engine->SetFileSystem(fileSystem);
  }
  CATCH_AND_THROW(env)
}
Beispiel #20
0
static int LiquidValidate_Command(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[])
{
    // * Check the number of arguments
    if (objc != 3)
    {
        Tcl_WrongNumArgs(interp, 1, objv, "<templates> <root template>");
        return TCL_ERROR;
    }

    // Parse the data into a file system
    TclLiquid::FileSystem fileSystem(interp,
                                     objv[1]);

    // Get the template name
    const char* templateNameChars = Tcl_GetStringFromObj(objv[2], NULL);
    std::string templateName(templateNameChars);

    // Try to get the template source
    std::string templateSource;

    if (!fileSystem.TryFind(templateName,
                            templateSource))
        LiquidError(LiquidDataError, "Template not found in template list");

    // Try to parse the template
    Liquid::ParserError parserError;
    Liquid::RenderError renderError;
    Liquid::Strainer strainer;

    Liquid::Template* templ = Liquid::Template::Parse(templateSource,
                                                      strainer,
                                                      parserError);

    if (!templ)
    {
        // Set the error
        std::stringstream errorStream;
        errorStream << parserError;

        LiquidError(LiquidParseError,
                    errorStream.str().c_str());
    }

    // Clean up the data.
    delete templ;

    return TCL_OK;
}
FileWriterSync* DOMFileSystemSync::createWriter(const FileEntrySync* fileEntry, ExceptionState& exceptionState)
{
    ASSERT(fileEntry);

    FileWriterSync* fileWriter = FileWriterSync::create();
    ReceiveFileWriterCallback* successCallback = ReceiveFileWriterCallback::create();
    FileError::ErrorCode errorCode = FileError::OK;
    LocalErrorCallback* errorCallback = LocalErrorCallback::create(errorCode);

    OwnPtr<AsyncFileSystemCallbacks> callbacks = FileWriterBaseCallbacks::create(fileWriter, successCallback, errorCallback, m_context);
    callbacks->setShouldBlockUntilCompletion(true);

    fileSystem()->createFileWriter(createFileSystemURL(fileEntry), fileWriter, callbacks.release());
    if (errorCode != FileError::OK) {
        FileError::throwDOMException(exceptionState, errorCode);
        return 0;
    }
    return fileWriter;
}
Beispiel #22
0
TEST(NewJsEngineTest, CallbackGetSet)
{
  AdblockPlus::JsEnginePtr jsEngine(AdblockPlus::JsEngine::New());

  ASSERT_TRUE(jsEngine->GetLogSystem());
  ASSERT_ANY_THROW(jsEngine->SetLogSystem(AdblockPlus::LogSystemPtr()));
  AdblockPlus::LogSystemPtr logSystem(new AdblockPlus::DefaultLogSystem());
  jsEngine->SetLogSystem(logSystem);
  ASSERT_EQ(logSystem, jsEngine->GetLogSystem());

  ASSERT_TRUE(jsEngine->GetFileSystem());
  ASSERT_ANY_THROW(jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr()));
  AdblockPlus::FileSystemPtr fileSystem(new AdblockPlus::DefaultFileSystem());
  jsEngine->SetFileSystem(fileSystem);
  ASSERT_EQ(fileSystem, jsEngine->GetFileSystem());

  ASSERT_TRUE(jsEngine->GetWebRequest());
  ASSERT_ANY_THROW(jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr()));
  AdblockPlus::WebRequestPtr webRequest(new AdblockPlus::DefaultWebRequest());
  jsEngine->SetWebRequest(webRequest);
  ASSERT_EQ(webRequest, jsEngine->GetWebRequest());
}
Beispiel #23
0
bool MeshManager::convertMeshToNativeFormat(const String& name)
{
    auto mesh = Mesh();
    if (!MeshFormatRegistry::loadMeshFile(Mesh::MeshDirectory + name, mesh))
    {
        LOG_ERROR << "Failed converting mesh: " << name;
        return false;
    }

    try
    {
        auto file = FileWriter();
        fileSystem().open(Mesh::MeshDirectory + name + Mesh::MeshExtension, file);
        file.write(mesh);
    }
    catch (const Exception& e)
    {
        LOG_ERROR << name << " - " << e;
        return false;
    }

    return true;
}
Beispiel #24
0
void DOMFileSystem::createFile(const FileEntry* fileEntry, PassOwnPtr<FileCallback> successCallback, PassOwnPtr<ErrorCallback> errorCallback)
{
    KURL fileSystemURL = createFileSystemURL(fileEntry);
    fileSystem()->createSnapshotFileAndReadMetadata(fileSystemURL, SnapshotFileCallback::create(this, fileEntry->name(), fileSystemURL, successCallback, errorCallback, m_context));
}
bool DOMFileSystemBase::waitForAdditionalResult(int callbacksId)
{
    if (!fileSystem())
        return false;
    return fileSystem()->waitForAdditionalResult(callbacksId);
}
Beispiel #26
0
// static
PassRefPtrWillBeRawPtr<DOMFileSystem> DOMFileSystem::create(ExecutionContext* context, const String& name, FileSystemType type, const KURL& rootURL)
{
    RefPtrWillBeRawPtr<DOMFileSystem> fileSystem(adoptRefWillBeRefCountedGarbageCollected(new DOMFileSystem(context, name, type, rootURL)));
    fileSystem->suspendIfNeeded();
    return fileSystem.release();
}
/** @return the maximum number of sectors this Partition may be long */
qint64 Partition::maximumSectors() const
{
	return fileSystem().maxCapacity() / sectorSize();
}
Beispiel #28
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowSmd)
{
	FileSystem fileSystem("../../Resources");
	Console console(fileSystem, false);
	
	ResourceManager resourceManager(fileSystem, console);

	InputDevice input(console);

	Window window("Void", console, input, resourceManager, fileSystem, 1280, 720, true, false);
	//Window window("Void", console, input, resourceManager, fileSystem);
	if(window.Initialise()) return 0;

	ConsoleEvent shouldQuitConsole(console, input, "Game.Quit");
	input.addDefaultBinding(Key::Q, shouldQuitConsole);
	input.addDefaultBinding(Key::Escape, shouldQuitConsole);

	ConsoleEvent cameraForward(console, input, "Camera.Move.Forward");
	input.addDefaultBinding(Key::W, cameraForward);
	ConsoleEvent cameraBackward(console, input, "Camera.Move.Backward");
	input.addDefaultBinding(Key::S, cameraBackward);
	ConsoleEvent cameraLeft(console, input, "Camera.Move.Left");
	input.addDefaultBinding(Key::A, cameraLeft);
	ConsoleEvent cameraRight(console, input, "Camera.Move.Right");
	input.addDefaultBinding(Key::D, cameraRight);
	ConsoleEvent cameraUp(console, input, "Camera.Move.Up");
	input.addDefaultBinding(Key::Space, cameraUp);
	ConsoleEvent cameraDown(console, input, "Camera.Move.Down");
	input.addDefaultBinding(Key::LCtrl, cameraDown);
	ConsoleEvent cameraSprint(console, input, "Camera.Move.Sprint");
	input.addDefaultBinding(Key::LShift, cameraSprint);

	window.GetGraphicsDevice().getRenderer3D().setSkybox(resourceManager.getResourceReference<TextureResource>("[Texture] Clouds.dds"));

	Camera &camera = window.GetGraphicsDevice().getRenderer3D().getCamera();
	camera.rotateY(Math::DegreesToRadians(90));
	camera.setPosition(-1100.0f, -170.0f, 0.0f);

	std::vector<PointLight> lights;

	ResourceReference<ModelResource> visibleLion = resourceManager.getResourceReference<ModelResource>("[Model] Lion.smdf");

	std::vector<ResourceReference<MaterialResource>> materials;
#define add_model(x) materials.push_back(resourceManager.getResourceReference<MaterialResource>("[Material] " x ".smtf"))
	add_model("Lion");add_model("Lionbackground"); add_model("VaseRound"); add_model("Ceiling");
	add_model("ColumnA"); add_model("ColumnB"); add_model("ColumnC"); add_model("Floor"); add_model("FabricGreen");
	add_model("FabricBlue"); add_model("FabricRed"); add_model("CurtainBlue"); add_model("CurtainRed");
	add_model("CurtainGreen"); add_model("VaseHanging"); add_model("Vase"); add_model("Bricks");
	add_model("Arch"); add_model("Details"); add_model("Roof");	add_model("VasePlant");
	add_model("Chain"); add_model("Thorn");add_model("Vase");

	Timer gameTime;

	bool isMousePressed = false;
	int oldMouseX = 0;
	int oldMouseY = 0;

	for(;;)
	{
		uint64 frameTime = gameTime.getElapsedReset();
		float frameSeconds = frameTime / 1000.0f;

		resourceManager.Update();
		console.update();

		if(window.Update()) break;
		input.Update();

		if(shouldQuitConsole.isPress()) break;

		if(isMousePressed != input.IsKeyDown(Key::LButton))
		{
			isMousePressed = !isMousePressed;
			if(isMousePressed)
			{
				window.setMouseClipping(true);
				oldMouseX = input.GetMouseXPositionAbsolute();
				oldMouseY = input.GetMouseYPositionAbsolute();
				window.setMouseVisibility(true);
			}
			else
			{
				window.setMouseClipping(false);
				window.SetMousePosition(oldMouseX, oldMouseY);
				window.setMouseVisibility(false);
			}
		}

		if(isMousePressed)
		{
			camera.rotateY(Math::DegreesToRadians(input.GetMouseXPositionRelative()));
			camera.rotateX(Math::DegreesToRadians(input.GetMouseYPositionRelative()));
		}

		float distance = 100.0f * frameSeconds;
		if(cameraSprint.isHeld()) distance *= 6;

		if(cameraForward.isHeld()) camera.moveX(distance);
		if(cameraBackward.isHeld()) camera.moveX(-distance);
		if(cameraRight.isHeld()) camera.moveZ(distance);
		if(cameraLeft.isHeld()) camera.moveZ(-distance);
		if(cameraUp.isHeld()) camera.moveY(distance);
		if(cameraDown.isHeld()) camera.moveY(-distance);

		visibleLion->Render();

		if(resourceManager.isLoading())
		{
			if(lights.empty())
				fillLightsGrid(lights, window);
		}
		else if(!lights.empty())
			lights.clear();

		if(input.IsKeyPress(Key::Num1))
			fillLightsGrid(lights, window);

		Vector3 lightChange;
		if(input.IsKeyDown(Key::Up)) lightChange.y += distance;
		if(input.IsKeyDown(Key::Down)) lightChange.y -= distance;
		if(input.IsKeyDown(Key::Left)) lightChange.x += distance;
		if(input.IsKeyDown(Key::Right)) lightChange.x -= distance;

		if(lightChange != Vector3::Zero)
		{
			for(PointLight &light : lights)
				light.setPosition(light.getPosition() + lightChange);
		}
			
		if(window.Render()) break;
	}

	return 0;
}
// static
PassRefPtr<DOMFileSystem> DOMFileSystem::create(ScriptExecutionContext* context, const String& name, FileSystemType type, const KURL& rootURL, PassOwnPtr<AsyncFileSystem> asyncFileSystem)
{
    RefPtr<DOMFileSystem> fileSystem(adoptRef(new DOMFileSystem(context, name, type, rootURL, asyncFileSystem)));
    fileSystem->suspendIfNeeded();
    return fileSystem.release();
}
Beispiel #30
0
void MainWindow::install()
{
    ui->statusLabel->setFont(getFont(ui->statusLabel, FONT_STATUSLABEL_RATIO));
    ui->statusProgressBar->setFont(getFont(ui->statusProgressBar, FONT_PROGRESSBAR_RATIO));

    qApp->processEvents();
    /* Find out what device we are running on */
    logger->addLine("Detecting device we are running on");
    device = targetList->getTarget(utils->getOSMCDev());
    if (device == NULL)
    {
        haltInstall("unsupported device"); /* No tr here as not got lang yet */
        return;
    }
    /* Mount the BOOT filesystem */
    logger->addLine("Mounting boot filesystem");
    bool hasMount = false;
    hasMount = utils->mountPartition(device, MNT_BOOT);
    if (! hasMount && utils->getOSMCDev() == "atv")
    {
        /* Super hacky for Apple TV 1st gen. Sometimes no internal disk */
        hasMount = utils->mountPartition(device, "/dev/sda1");
        device->setRoot("/dev/sda2");
    }
    if (! hasMount)
    {
        haltInstall("could not mount bootfs");
        return;
    }
    /* Sanity check: need filesystem.tar.xz */
    QFile fileSystem(QString(MNT_BOOT) + "/filesystem.tar.xz");
    if (! fileSystem.exists())
    {
        haltInstall("no filesystem found");
        return;
    }
    /* Load in preseeded values */
    preseed = new PreseedParser();
    if (preseed->isLoaded())
    {
        logger->addLine("Preseed file found, will attempt to parse");
        /* Locales */
        locale = preseed->getStringValue("globe/locale");
        if (! locale.isEmpty())
        {
            logger->addLine("Found a definition for globalisation: " + locale);
            QTranslator translator;
            if (translator.load(qApp->applicationDirPath() + "/osmc_" + locale + ".qm"))
            {
                logger->addLine("Translation loaded successfully!");
                qApp->installTranslator(&translator);
                ui->retranslateUi(this);
            }
            else
                logger->addLine("Could not load translation");
        }
        /* Install target */
        installTarget = preseed->getStringValue("target/storage");
        if (! installTarget.isEmpty())
        {
            logger->addLine("Found a definition for storage: " + installTarget);
            if (installTarget == "nfs")
            {
                QString nfsPath = preseed->getStringValue("target/storagePath");
                if (! nfsPath.isEmpty())
                {
                    device->setRoot(nfsPath);
                    useNFS = true;
                }
            }
            if (installTarget == "usb")
            {
                /* Behaviour for handling USB installs */
                if (utils->getOSMCDev() == "rbp1") { device->setRoot("/dev/sda1"); }
                if (utils->getOSMCDev() == "rbp2") { device->setRoot("/dev/sda1"); }
                if (utils->getOSMCDev() == "vero1") { device->setRoot("/dev/sda1"); }
                for (int i = 0; i <= 60; i++)
                {
                    ui->statusLabel->setText(tr("USB install:") + " " + QString::number(60 - i) + " " + ("seconds to remove device before data loss"));
                    qApp->processEvents();
                    system("/bin/sleep 1");
                }
            }
        }
        /* Bring up network if using NFS */
        if (useNFS)
        {
            logger->addLine("NFS installation chosen, must bring up network");
            nw = new Network();
            nw->setIP(preseed->getStringValue("network/ip"));
            nw->setMask(preseed->getStringValue("network/mask"));
            nw->setGW(preseed->getStringValue("network/gw"));
            nw->setDNS1(preseed->getStringValue("network/dns1"));
            nw->setDNS2(preseed->getStringValue("network/dns2"));
            if (! nw->isDefined())
            {
                logger->addLine("Either network preseed definition incomplete, or user wants DHCP");
                nw->setAuto();
            }
            logger->addLine("Attempting to bring up eth0");
            ui->statusLabel->setText(tr("Configuring Network"));
            nw->bringUp();
        }
    }
    else
    {
        logger->addLine("No preseed file was found");
    }
    /* If !nfs, create necessary partitions */
    if (! useNFS)
    {
        logger->addLine("Creating root partition");
        ui->statusLabel->setText(tr("Formatting device"));
        qApp->processEvents(); /* Force GUI update */
        QString rootBase = device->getRoot();
        if (rootBase.contains("mmcblk"))
            rootBase.chop(2);
        else
            rootBase.chop(1);
        logger->addLine("From a root partition of " + device->getRoot() + ", I have deduced a base device of " + rootBase);
        if (device->hasRootChanged() && utils->getOSMCDev() != "atv")
        {
            logger->addLine("Must mklabel as root fs is on another device");
            utils->mklabel(rootBase, false);
            utils->mkpart(rootBase, "ext4", "4096s", "100%");
            utils->fmtpart(device->getRoot(), "ext4");
        }
        else
        {
            int size = utils->getPartSize(rootBase, (device->getBootFS() == "vfat" ? "fat32" : "ext4"));
            if (size == -1)
            {
                logger->addLine("Issue getting size of device");
                haltInstall(tr("cannot work out partition size"));
                return;
            }
            logger->addLine("Determined " + QString::number(size) + " MB as end of first partition");
            utils->mkpart(rootBase, "ext4", QString::number(size + 2) + "M", "100%");
            utils->fmtpart(device->getRoot(), "ext4");
        }
    }
    /* Mount root filesystem */
    if (useNFS)
        bc = new BootloaderConfig(device, nw, utils, logger);
    else
        bc = new BootloaderConfig(device, NULL, utils, logger);
    logger->addLine("Mounting root");
    if ( ! utils->mountPartition(device, MNT_ROOT))
    {
        logger->addLine("Error occured trying to mount root of " + device->getRoot());
        haltInstall(tr("can't mount root"));
        return;
    }
    if (useNFS)
        system("rm -rf /mnt/root/*"); /* BusyBox tar does not like overwrites. Clear nfsroot first */
   /* Extract root filesystem */
   ui->statusLabel->setText(tr("Installing files"));
   logger->addLine("Extracting files to root filesystem");
   ui->statusProgressBar->setMinimum(0);
   ui->statusProgressBar->setMaximum(100);

   QThread* thread = new QThread(this);
   ExtractWorker *worker = new ExtractWorker(fileSystem.fileName(), MNT_ROOT, logger);
   worker->moveToThread(thread);
   connect(thread, SIGNAL(started()), worker, SLOT(extract()));
   connect(worker, SIGNAL(progressUpdate(unsigned)), this, SLOT(setProgress(unsigned)));
   connect(worker, SIGNAL(error(QString)), this, SLOT(haltInstall(QString)));
   connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
   connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()));
   connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
   connect(thread, SIGNAL(finished()), this, SLOT(finished()));
   thread->start();
}