Exemplo n.º 1
0
Calamares::JobResult
SetTimezoneJob::exec()
{
    // do not call timedatectl in a chroot, it is not safe (timedatectl talks
    // to a running timedated over D-Bus), and we have code that works
    if ( !Calamares::Settings::instance()->doChroot() )
    {
        int ec = CalamaresUtils::System::instance()->
                              targetEnvCall( { "timedatectl",
                                               "set-timezone",
                                               m_region + '/' + m_zone } );

        if ( !ec )
            return Calamares::JobResult::ok();
    }

    QString localtimeSlink( "/etc/localtime" );
    QString zoneinfoPath( "/usr/share/zoneinfo" );
    zoneinfoPath.append( QDir::separator() + m_region );
    zoneinfoPath.append( QDir::separator() + m_zone );

    Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
    QFileInfo zoneFile( gs->value( "rootMountPoint" ).toString() + zoneinfoPath );
    if ( !zoneFile.exists() || !zoneFile.isReadable() )
        return Calamares::JobResult::error( tr( "Cannot access selected timezone path." ),
                                            tr( "Bad path: %1" ).arg( zoneFile.absolutePath() ) );

    // Make sure /etc/localtime doesn't exist, otherwise symlinking will fail
    CalamaresUtils::System::instance()->
                 targetEnvCall( { "rm",
                                  "-f",
                                  localtimeSlink } );

    int ec = CalamaresUtils::System::instance()->
                          targetEnvCall( { "ln",
                                           "-s",
                                           zoneinfoPath,
                                           localtimeSlink } );
    if ( ec )
        return Calamares::JobResult::error( tr( "Cannot set timezone." ),
                                            tr( "Link creation failed, target: %1; link name: %2" )
                                                .arg( zoneinfoPath )
                                                .arg( "/etc/localtime" ) );

    QFile timezoneFile( gs->value( "rootMountPoint" ).toString() + "/etc/timezone" );

    if ( !timezoneFile.open( QIODevice::WriteOnly |
                             QIODevice::Text |
                             QIODevice::Truncate ) )
        return Calamares::JobResult::error( tr( "Cannot set timezone,"),
                                            tr( "Cannot open /etc/timezone for writing"));

    QTextStream out(&timezoneFile);
    out << m_region << '/' << m_zone << "\n";
    timezoneFile.close();

    return Calamares::JobResult::ok();
}
Exemplo n.º 2
0
bool CVegetableEditor::createVegetableLandscape()
{
	/// TODO: switch from C to U classes, if possible
	// If not already done.
	if(!_VegetableLandscape)
	{
		// load general landscape param
		loadLandscapeSetup();

		// create the landscape.
		_VegetableLandscape= static_cast<NL3D::CLandscapeModel *>(Modules::veget().getScene()->createModel(NL3D::LandscapeModelId));

		// create progress dialog
		QProgressDialog progress("Loading TileBanks....", "Cancel", 0, 100);
		progress.show();
		progress.setWindowModality(Qt::WindowModal);
		progress.setValue(0);
		try
		{
			if((_VegetableLandscapeTileBank.empty()) || (_VegetableLandscapeTileFarBank.empty()) || (_VegetableLandscapeZoneNames.empty()))
			{
				throw NLMISC::Exception("Landscape section object_viewer_qt.cfg not fully defined");
			}

			// Load The Bank files (copied from CLandscapeUser :) ).
			// ================
			// load
			NLMISC::CIFile bankFile(NLMISC::CPath::lookup(_VegetableLandscapeTileBank));
			_VegetableLandscape->Landscape.TileBank.serial(bankFile);
			_VegetableLandscape->Landscape.TileBank.makeAllPathRelative();
			_VegetableLandscape->Landscape.TileBank.makeAllExtensionDDS();
			_VegetableLandscape->Landscape.TileBank.setAbsPath ("");

			// load
			NLMISC::CIFile farbankFile(NLMISC::CPath::lookup(_VegetableLandscapeTileFarBank));
			_VegetableLandscape->Landscape.TileFarBank.serial(farbankFile);
			if ( ! _VegetableLandscape->Landscape.initTileBanks() )
			{
				nlwarning( "You need to recompute bank.farbank for the far textures" );
			}
			bankFile.close();
			farbankFile.close();

			// flushTiles.
			// ================
			if(Modules::veget().getDriver())
			{
				// progress
				progress.setLabelText("Start loading Tiles...");
				// count nbText to load.
				sint	ts;
				sint	nbTextTotal = 0;
				for (ts=0; ts < _VegetableLandscape->Landscape.TileBank.getTileSetCount (); ++ts)
				{
					NL3D::CTileSet *tileSet =_VegetableLandscape->Landscape.TileBank.getTileSet (ts);
					nbTextTotal += tileSet->getNumTile128();
					nbTextTotal += tileSet->getNumTile256();
					nbTextTotal += NL3D::CTileSet::count;
				}

				// load.
				sint nbTextDone= 0;
				for (ts=0; ts < _VegetableLandscape->Landscape.TileBank.getTileSetCount (); ++ts)
				{
					NL3D::CTileSet *tileSet=_VegetableLandscape->Landscape.TileBank.getTileSet (ts);
					sint tl;
					for (tl=0; tl<tileSet->getNumTile128(); tl++, nbTextDone++)
					{
						_VegetableLandscape->Landscape.flushTiles (Modules::veget().getDriver(), (uint16)tileSet->getTile128(tl), 1);
						progress.setValue(nbTextDone * 100 / nbTextTotal);
					}
					for (tl=0; tl<tileSet->getNumTile256(); tl++, nbTextDone++)
					{
						_VegetableLandscape->Landscape.flushTiles (Modules::veget().getDriver(), (uint16)tileSet->getTile256(tl), 1);
						progress.setValue(nbTextDone * 100 / nbTextTotal);
					}
					for (tl=0; tl < NL3D::CTileSet::count; tl++, nbTextDone++)
					{
						_VegetableLandscape->Landscape.flushTiles (Modules::veget().getDriver(), (uint16)tileSet->getTransition(tl)->getTile (), 1);
						progress.setValue(nbTextDone * 100 / nbTextTotal);
					}
				}
				progress.setValue(100);
			}

			// misc setup.
			// ================
			_VegetableLandscape->Landscape.setThreshold(_VegetableLandscapeThreshold);
			_VegetableLandscape->Landscape.setTileNear(_VegetableLandscapeTileNear);
			_VegetableLandscape->Landscape.setupStaticLight(_VegetableLandscapeDiffuse, _VegetableLandscapeAmbient, 1);
			_VegetableLandscape->Landscape.loadVegetableTexture(_VegetableTexture);
			_VegetableLandscape->Landscape.setupVegetableLighting(_VegetableAmbient, _VegetableDiffuse, _VegetableLightDir);
			_VegetableLandscape->Landscape.setVegetableWind(_VegetableWindDir, _VegetableWindFreq, _VegetableWindPower, _VegetableWindBendMin);
			_VegetableLandscape->Landscape.setUpdateLightingFrequency(1);
			_VegetableLandscape->enableAdditive(true);
			// Load the zones.
			// ================
			// landscape recentering.
			bool zoneLoaded = false;
			NL3D::CAABBox landscapeBBox;
			// progress
			progress.setLabelText("Start loading Zones...");
			progress.setValue(0);
			uint	nbZones= (uint)_VegetableLandscapeZoneNames.size();
			for(uint i = 0; i < nbZones; i++)
			{
				// open the file
				NLMISC::CIFile zoneFile(NLMISC::CPath::lookup(_VegetableLandscapeZoneNames[i]));
				NL3D::CZone zone;
				// load
				zoneFile.serial(zone);
				// append to landscape
				_VegetableLandscape->Landscape.addZone(zone);
				// progress
				progress.setValue(i * 100 / nbZones);
				// Add to the bbox.
				if(!zoneLoaded)
				{
					zoneLoaded= true;
					landscapeBBox.setCenter(zone.getZoneBB().getCenter());
				}
				else
					landscapeBBox.extend(zone.getZoneBB().getCenter());
			}

			// After All zone loaded, recenter the mouse listener on the landscape.
			if(zoneLoaded)
			{
				NL3D::CMatrix matrix;
				Modules::objView().get3dMouseListener()->setHotSpot(landscapeBBox.getCenter());
				matrix.setPos(landscapeBBox.getCenter());
				matrix.rotateX(-(float)NLMISC::Pi / 4);
				matrix.translate(NLMISC::CVector(0, -1000, 0));
				Modules::objView().get3dMouseListener()->setMatrix(matrix);
			}

			// Create collisions objects.
			_VegetableCollisionManager= new NL3D::CVisualCollisionManager;
			_VegetableCollisionManager->setLandscape(&_VegetableLandscape->Landscape);
			_VegetableCollisionEntity= _VegetableCollisionManager->createEntity();
			progress.setValue(100);
		}
		catch (NLMISC::Exception &e)
		{
			// remove first possibly created collisions objects.
			if(_VegetableCollisionEntity)
			{
				_VegetableCollisionManager->deleteEntity(_VegetableCollisionEntity);
				_VegetableCollisionEntity= NULL;
			}

			if(_VegetableCollisionManager)
			{
				delete _VegetableCollisionManager;
				_VegetableCollisionManager= NULL;
			}

			// remove the landscape
			Modules::veget().getScene()->deleteModel(_VegetableLandscape);

			_VegetableLandscape= NULL;

			QMessageBox::critical(&Modules::mainWin(), "Failed to Load landscape", QString(e.what()), QMessageBox::Ok);

			return false;
		}
	}
	Modules::objView().getScene()->setCoarseMeshManagerTexture(_CoarseMeshTexture.c_str());
	return true;
}