OGRLayer *OGRAmigoCloudDataSource::ICreateLayer( const char *pszNameIn, OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType, char ** papszOptions ) { if( !bReadWrite ) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in read-only mode"); return nullptr; } CPLString osName(pszNameIn); OGRAmigoCloudTableLayer* poLayer = new OGRAmigoCloudTableLayer(this, osName); const bool bGeomNullable = CPLFetchBool(papszOptions, "GEOMETRY_NULLABLE", true); OGRSpatialReference* poSRSClone = poSpatialRef; if( poSRSClone ) { poSRSClone = poSRSClone->Clone(); poSRSClone->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); } poLayer->SetDeferredCreation(eGType, poSRSClone, bGeomNullable); if( poSRSClone ) poSRSClone->Release(); papoLayers = (OGRAmigoCloudTableLayer**) CPLRealloc( papoLayers, (nLayers + 1) * sizeof(OGRAmigoCloudTableLayer*)); papoLayers[nLayers ++] = poLayer; return poLayer; }
void collectData(string& content) { content.append(Html::h2("Operating System")); content.append(Html::table_open()); content.append(Html::tr(Html::td2("Operating system information"))); content.append(Html::tr(Html::td("Machine name") + Html::td(computerName()))); content.append(Html::tr(Html::td("Full name") + Html::td(osName()))); content.append(Html::tr(Html::td("Root directory") + Html::td(osRootDir()))); content.append(Html::tr(Html::td("Language") + Html::td(OsLanguage()))); content.append(Html::tr(Html::td("Locale") + Html::td(getLocale()))); content.append(Html::tr(Html::td("Is OS Virtualized?") + Html::td(""))); content.append(Html::tr(Html::td("Is 3GB switch enabled?") + Html::td(""))); content.append(Html::tr(Html::td("Data Execution Prevention") + Html::td(DepInfo()))); content.append(Html::tr(Html::td("User Account Control") + Html::td(UAC()))); content.append(Html::tr(Html::td("Is user Admin?") + Html::td(Html::boolToYesNo(IsUserAdmin())))); content.append(Html::tr(Html::td("Is user connected remotely?") + Html::td(""))); content.append(Html::tr(Html::td("Is Windows firewall enabled?") + Html::td(WindowsFirewall()))); content.append(Html::tr(Html::td("Is secondary logon enabled?") + Html::td(""))); content.append(Html::tr(Html::td2("Environment information"))); content.append(Html::tr(Html::td("System environment variables") + Html::td(get_os_env_vars()))); content.append(Html::tr(Html::td("User environment variables") + Html::td(UserEnvVars()))); content.append(Html::tr(Html::td("Kerberos configuration") + Html::td(""))); content.append(Html::tr(Html::td("Layered Service Providers") + Html::td(""))); content.append(Html::tr(Html::td("AppInit_DLLs registry value") + Html::td(get_AppInit_DLLs()))); content.append(Html::tr(Html::td("LoadAppInit_DLLs registry value") + Html::td(get_LoadAppInit_DLLs()))); content.append(Html::table_close); }
std::string CSysInfo::GetOsPrettyNameWithVersion(void) { static std::string osNameVer; if (!osNameVer.empty()) return osNameVer; #if defined(TARGET_FREEBSD) || defined(TARGET_DARWIN_IOS) || defined(TARGET_DARWIN_OSX) osNameVer = GetOsName() + " " + GetOsVersion(); #elif defined(TARGET_ANDROID) osNameVer = GetOsName() + " " + GetOsVersion() + " API level " + StringUtils::Format("%d", CJNIBuild::SDK_INT); #elif defined(TARGET_LINUX) osNameVer = getValueFromOs_release("PRETTY_NAME"); if (osNameVer.empty()) { osNameVer = getValueFromLsb_release(lsb_rel_description); std::string osName(GetOsName(true)); if (!osName.empty() && osNameVer.find(osName) == std::string::npos) osNameVer = osName + osNameVer; if (osNameVer.empty()) osNameVer = "Unknown Linux Distribution"; } if (osNameVer.find(GetOsVersion()) == std::string::npos) osNameVer += " " + GetOsVersion(); #endif // defined(TARGET_LINUX) if (osNameVer.empty()) osNameVer = "Unknown OS Unknown version"; return osNameVer; }
OGRLayer *OGRAmigoCloudDataSource::ICreateLayer( const char *pszNameIn, OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType, char ** papszOptions ) { if( !bReadWrite ) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in read-only mode"); return NULL; } /* -------------------------------------------------------------------- */ /* Do we already have this layer? If so, should we blow it */ /* away? */ /* -------------------------------------------------------------------- */ CPLString osName(pszNameIn); OGRAmigoCloudTableLayer* poLayer = new OGRAmigoCloudTableLayer(this, osName); const bool bGeomNullable = CPLFetchBool(papszOptions, "GEOMETRY_NULLABLE", true); poLayer->SetDeferredCreation(eGType, poSpatialRef, bGeomNullable); papoLayers = (OGRAmigoCloudTableLayer**) CPLRealloc( papoLayers, (nLayers + 1) * sizeof(OGRAmigoCloudTableLayer*)); papoLayers[nLayers ++] = poLayer; return poLayer; }
OGRLayer *OGRCARTODBDataSource::ICreateLayer( const char *pszName, OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType, char ** papszOptions ) { if (!bReadWrite) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in read-only mode"); return NULL; } /* -------------------------------------------------------------------- */ /* Do we already have this layer? If so, should we blow it */ /* away? */ /* -------------------------------------------------------------------- */ int iLayer; for( iLayer = 0; iLayer < nLayers; iLayer++ ) { if( EQUAL(pszName,papoLayers[iLayer]->GetName()) ) { if( CSLFetchNameValue( papszOptions, "OVERWRITE" ) != NULL && !EQUAL(CSLFetchNameValue(papszOptions,"OVERWRITE"),"NO") ) { DeleteLayer( iLayer ); } else { CPLError( CE_Failure, CPLE_AppDefined, "Layer %s already exists, CreateLayer failed.\n" "Use the layer creation option OVERWRITE=YES to " "replace it.", pszName ); return NULL; } } } CPLString osName(pszName); if( CSLFetchBoolean(papszOptions,"LAUNDER", TRUE) ) { char* pszTmp = OGRPGCommonLaunderName(pszName); osName = pszTmp; CPLFree(pszTmp); } OGRCARTODBTableLayer* poLayer = new OGRCARTODBTableLayer(this, osName); int bGeomNullable = CSLFetchBoolean(papszOptions, "GEOMETRY_NULLABLE", TRUE); int bCartoDBify = CSLFetchBoolean(papszOptions, "CARTODBFY", CSLFetchBoolean(papszOptions, "CARTODBIFY", TRUE)); poLayer->SetLaunderFlag( CSLFetchBoolean(papszOptions,"LAUNDER",TRUE) ); poLayer->SetDeferedCreation(eGType, poSpatialRef, bGeomNullable, bCartoDBify); papoLayers = (OGRCARTODBTableLayer**) CPLRealloc( papoLayers, (nLayers + 1) * sizeof(OGRCARTODBTableLayer*)); papoLayers[nLayers ++] = poLayer; return poLayer; }
void Log2File::writeLogHeader() { if (logHeaderProvider) logfile << "========================================\n" << logHeaderProvider() << "\n========================================\n"; else logfile << "========================================\n" << "Logger built " __TIMESTAMP__ << "\nis running on " << pcType() << " powered by " << osName() << " " << osVer() << "\n========================================\n"; }
void CliApplication::about() const { // Output some information about OpenCOR version(); std::cout << osName().toStdString() << std::endl; std::cout << copyright().toStdString() << std::endl; std::cout << std::endl; std::cout << mApp->applicationName().toStdString() << " is a cross-platform CellML-based modelling environment," << " which can be used to organise, edit," << " simulate and analyse CellML files." << std::endl; }
void UpdatingWindow::startDownload() { QDir dir; QStringList path = pathToDownload.split("/"); path.removeLast(); QString oldPath = path.join("/")+"_old/"; QString resourcesPath = pathToDownload; if(osName() == "win") { resourcesPath = AppData::Instance()->executablePath(pathToDownload).replace(".exe", "")+ "/"; } QDir old(oldPath); dir.mkpath(oldPath); if(!dir.rename(resourcesPath+"settings.json", oldPath+"settings.json")) { qDebug() << "Move failed!" << resourcesPath; } if(!dir.rename(resourcesPath+"list.json", oldPath+"list.json")) { qDebug() << "Move failed!" << resourcesPath+"list.json" << oldPath+"list.json"; } connect(&manager, SIGNAL(finished(QNetworkReply*)), SLOT(fileDownloaded(QNetworkReply*))); writeToFile = new QFile(pathToDownload + fileToDownload); writeToFile->open(QIODevice::ReadWrite | QIODevice::Truncate); //writeToFile->resize(0); QNetworkRequest request(AppData::Instance()->settings["url"].toString() + "download_update.php?file=" + fileToDownload + "&os="+ osName()); qDebug() << AppData::Instance()->settings["url"].toString() + "download_update.php?file=" + fileToDownload + "&os="+ osName(); this->reply = manager.get(request); connect(this->reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(downloadProgress(qint64,qint64))); connect(this->reply, SIGNAL(readyRead()), this, SLOT(readyRead())); }
std::string osNameBit() { return osName()+"-x"+std::to_string(osBit()); }
void UpdatingWindow::fileDownloaded(QNetworkReply* pReply) { //emit a signal pReply->deleteLater(); writeToFile->close(); this->ui->label->setText("Unpacking"); QDir dir; QStringList path = pathToDownload.split("/"); path.removeLast(); QString oldPath = path.join("/")+"_old/"; QString exeName = fileToDownload.replace(".zip", ""); qDebug() << exeName << AppData::Instance()->executablePath(pathToDownload+exeName) << AppData::Instance()->executablePath(pathToDownload+exeName).replace(exeName, "").replace(".app", exeName+".app"); QString resourcesPath = pathToDownload; if(osName() == "win") { resourcesPath = AppData::Instance()->executablePath(pathToDownload).replace(".exe", "")+ "/"; } QString program; QStringList arguments; if(osName() == "osx" || osName()=="linux") { program = "unzip"; arguments << "-o" << pathToDownload + fileToDownload << "-d " << pathToDownload; QProcess::execute("unzip -o " + pathToDownload + fileToDownload + " -d " + pathToDownload); } else if(osName()== "win") { program = "7za.exe"; QString test = QString("-o")+pathToDownload; arguments << "x" << pathToDownload + fileToDownload << "-aoa" <<test; } QProcess *myProcess = new QProcess(); qDebug() << program; myProcess->setProcessChannelMode(QProcess::MergedChannels); myProcess->start(program, arguments); //sleep(10); myProcess->waitForFinished(-1); //qDebug() << myProcess->program() << myProcess->arguments().at(3); qDebug() << myProcess->readAll(); if (QFile::exists(resourcesPath+"settings.json")) { if(QFile::remove(resourcesPath+"settings.json")){ qDebug() << "removed settings.json"; } } if (QFile::exists(resourcesPath+"list.json")) { QFile::remove(resourcesPath+"list.json"); } qDebug() << resourcesPath; qDebug() << oldPath; QFile file(oldPath+"settings.json"); if(!file.rename(resourcesPath+"settings.json")){ qWarning() << "Settings.json move failed!!!"; } QFile file2(oldPath+"list.json"); file2.rename(resourcesPath+"list.json"); QDir old(oldPath); old.removeRecursively(); if(writeToFile->remove()){ qDebug() << "Removed Zip File"; QDir macJunkDir(pathToDownload + "__MACOSX"); macJunkDir.removeRecursively(); writeToFile->close(); } else { qDebug() << "Failed to remove zip file"; } this->ui->label->setText("Done!"); this->ui->progressBar->setValue(120); QString execPath; if(osName()=="osx") { QProcess::execute(QString("chmod +x %1").arg(pathToDownload + fileToDownload.replace(".zip", "")+ + ".app/Contents/MacOS/" + fileToDownload.replace(".zip", ""))); QProcess::execute(QString("chmod +x %1").arg(pathToDownload + fileToDownload.replace(".zip", "")+ ".app")); execPath = QString("open %1").arg(pathToDownload + fileToDownload.replace(".zip", "")+ ".app"); system(execPath.toLatin1()); }else if(osName()=="win"){ execPath = AppData::Instance()->executablePath("start " +pathToDownload+fileToDownload.replace(".zip", ".exe")); system(execPath.toLatin1()); } QProcess::startDetached(execPath); qDebug() << execPath; //qDebug() << process->errorString(); this->close(); }
void DiagnosticsAgent::handle(const QXmppDiagnosticIq &request) { iq.setId(request.id()); iq.setFrom(request.to()); iq.setTo(request.from()); iq.setType(QXmppIq::Result); /* software versions */ QList<Software> softwares; Software os; os.setType("os"); os.setName(osName()); os.setVersion(QSysInfo::productVersion()); softwares << os; Software app; app.setType("application"); app.setName(qApp->applicationName()); app.setVersion(qApp->applicationVersion()); softwares << app; iq.setSoftwares(softwares); /* get DNS servers */ iq.setNameServers(NetworkInfo::nameServers()); /* discover interfaces */ QList<Interface> interfaceResults; foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces()) { if (!(interface.flags() & QNetworkInterface::IsRunning) || (interface.flags() & QNetworkInterface::IsLoopBack)) continue; Interface result; #if QT_VERSION >= 0x040500 result.setName(interface.humanReadableName()); #else result.setName(interface.name()); #endif // addresses result.setAddressEntries(interface.addressEntries()); // wireless WirelessInterface wireless(interface); if (wireless.isValid()) { QList<WirelessNetwork> networks = wireless.availableNetworks(); WirelessNetwork current = wireless.currentNetwork(); if (current.isValid()) { networks.removeAll(current); networks.prepend(current); } result.setWirelessNetworks(networks); result.setWirelessStandards(wireless.supportedStandards()); } interfaceResults << result; } iq.setInterfaces(interfaceResults); /* try to determine gateways */ QList<QHostAddress> pingAddresses; foreach (const QNetworkInterface &interface, QNetworkInterface::allInterfaces()) { if (!(interface.flags() & QNetworkInterface::IsRunning) || (interface.flags() & QNetworkInterface::IsLoopBack)) continue; foreach (const QNetworkAddressEntry &entry, interface.addressEntries()) { if (entry.ip().protocol() == QAbstractSocket::IPv4Protocol && !entry.netmask().isNull() && entry.netmask() != QHostAddress::Broadcast) { const QHostAddress gateway((entry.ip().toIPv4Address() & entry.netmask().toIPv4Address()) + 1); if (!pingAddresses.contains(gateway)) pingAddresses.append(gateway); break; } } } /* run DNS tests */ foreach (const QString &hostName, m_config.pingHosts) { QHostAddress address; if (resolve(hostName, address)) { if (!pingAddresses.contains(address)) pingAddresses.append(address); } } /* run ping tests */ QList<Ping> pings; foreach (const QHostAddress &address, pingAddresses) { const Ping ping = NetworkInfo::ping(address, 3); pings.append(ping); if (address == QHostAddress("8.8.8.8") && ping.sentPackets() != ping.receivedPackets()) pings.append(NetworkInfo::ping(address, 30)); } iq.setPings(pings); /* run traceroute */ QList<Traceroute> traceroutes; foreach (const QString &hostName, m_config.tracerouteHosts) { QHostAddress address; if (resolve(hostName, address)) { traceroutes << NetworkInfo::traceroute(address, 3, 4); } } iq.setTraceroutes(traceroutes); /* run download */ if (m_config.transferUrl.isValid()) { TransferTester *runner = new TransferTester(this); connect(runner, SIGNAL(finished(QList<Transfer>)), this, SLOT(transfersFinished(QList<Transfer>))); runner->start(m_config.transferUrl); } else { emit finished(iq); } }
OGRErr FGdbDriver::StartTransaction(OGRDataSource*& poDSInOut, int& bOutHasReopenedDS) { CPLMutexHolderOptionalLockD(hMutex); bOutHasReopenedDS = FALSE; OGRMutexedDataSource* poMutexedDS = (OGRMutexedDataSource*)poDSInOut; FGdbDataSource* poDS = (FGdbDataSource* )poMutexedDS->GetBaseDataSource(); if( !poDS->GetUpdate() ) return OGRERR_FAILURE; FGdbDatabaseConnection* pConnection = poDS->GetConnection(); if( pConnection->GetRefCount() != 1 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot start transaction as database is opened in another connection"); return OGRERR_FAILURE; } if( pConnection->IsLocked() ) { CPLError(CE_Failure, CPLE_AppDefined, "Transaction is already in progress"); return OGRERR_FAILURE; } bOutHasReopenedDS = TRUE; CPLString osName(poMutexedDS->GetName()); CPLString osNameOri(osName); if( osName[osName.size()-1] == '/' || osName[osName.size()-1] == '\\' ) osName.resize(osName.size()-1); #ifndef WIN32 int bPerLayerCopyingForTransaction = poDS->HasPerLayerCopyingForTransaction(); #endif pConnection->m_nRefCount ++; delete poDSInOut; poDSInOut = NULL; poMutexedDS = NULL; poDS = NULL; pConnection->CloseGeodatabase(); CPLString osEditedName(osName); osEditedName += ".ogredited"; CPLPushErrorHandler(CPLQuietErrorHandler); CPL_IGNORE_RET_VAL(CPLUnlinkTree(osEditedName)); CPLPopErrorHandler(); OGRErr eErr = OGRERR_NONE; CPLString osDatabaseToReopen; #ifndef WIN32 if( bPerLayerCopyingForTransaction ) { int bError = FALSE; if( VSIMkdir( osEditedName, 0755 ) != 0 ) { CPLError( CE_Failure, CPLE_AppDefined, "Cannot create directory '%s'.", osEditedName.c_str() ); bError = TRUE; } // Only copy a0000000X.Y files with X >= 1 && X <= 8, gdb and timestamps // and symlink others char** papszFiles = VSIReadDir(osName); for(char** papszIter = papszFiles; !bError && *papszIter; ++papszIter) { if( strcmp(*papszIter, ".") == 0 || strcmp(*papszIter, "..") == 0 ) continue; if( ((*papszIter)[0] == 'a' && atoi((*papszIter)+1) >= 1 && atoi((*papszIter)+1) <= 8) || EQUAL(*papszIter, "gdb") || EQUAL(*papszIter, "timestamps") ) { if( CPLCopyFile(CPLFormFilename(osEditedName, *papszIter, NULL), CPLFormFilename(osName, *papszIter, NULL)) != 0 ) { bError = TRUE; CPLError(CE_Failure, CPLE_AppDefined, "Cannot copy %s", *papszIter); } } else { CPLString osSourceFile; if( CPLIsFilenameRelative(osName) ) osSourceFile = CPLFormFilename(CPLSPrintf("../%s", CPLGetFilename(osName.c_str())), *papszIter, NULL); else osSourceFile = osName; if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE1") || CPLSymlink( osSourceFile, CPLFormFilename(osEditedName.c_str(), *papszIter, NULL), NULL ) != 0 ) { bError = TRUE; CPLError(CE_Failure, CPLE_AppDefined, "Cannot symlink %s", *papszIter); } } } CSLDestroy(papszFiles); if( bError ) { eErr = OGRERR_FAILURE; osDatabaseToReopen = osName; } else osDatabaseToReopen = osEditedName; } else #endif { if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE1") || CPLCopyTree( osEditedName, osName ) != 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot backup geodatabase"); eErr = OGRERR_FAILURE; osDatabaseToReopen = osName; } else osDatabaseToReopen = osEditedName; } pConnection->m_pGeodatabase = new Geodatabase; long hr = ::OpenGeodatabase(StringToWString(osDatabaseToReopen), *(pConnection->m_pGeodatabase)); if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE2") || FAILED(hr)) { delete pConnection->m_pGeodatabase; pConnection->m_pGeodatabase = NULL; Release(osName); GDBErr(hr, CPLSPrintf("Failed to open %s. Dataset should be closed", osDatabaseToReopen.c_str())); return OGRERR_FAILURE; } FGdbDataSource* pDS = new FGdbDataSource(this, pConnection); pDS->Open(osDatabaseToReopen, TRUE, osNameOri); #ifndef WIN32 if( eErr == OGRERR_NONE && bPerLayerCopyingForTransaction ) { pDS->SetPerLayerCopyingForTransaction(bPerLayerCopyingForTransaction); pDS->SetSymlinkFlagOnAllLayers(); } #endif poDSInOut = new OGRMutexedDataSource(pDS, TRUE, hMutex, TRUE); if( eErr == OGRERR_NONE ) pConnection->SetLocked(TRUE); return eErr; }
std::string CSysInfo::GetOsPrettyNameWithVersion(void) { static std::string osNameVer; if (!osNameVer.empty()) return osNameVer; #if defined (TARGET_WINDOWS) OSVERSIONINFOEXW osvi = {}; osNameVer = "Windows "; if (sysGetVersionExWByRef(osvi)) { switch (GetWindowsVersion()) { case WindowsVersionVista: if (osvi.wProductType == VER_NT_WORKSTATION) osNameVer.append("Vista"); else osNameVer.append("Server 2008"); break; case WindowsVersionWin7: if (osvi.wProductType == VER_NT_WORKSTATION) osNameVer.append("7"); else osNameVer.append("Server 2008 R2"); break; case WindowsVersionWin8: if (osvi.wProductType == VER_NT_WORKSTATION) osNameVer.append("8"); else osNameVer.append("Server 2012"); break; case WindowsVersionWin8_1: if (osvi.wProductType == VER_NT_WORKSTATION) osNameVer.append("8.1"); else osNameVer.append("Server 2012 R2"); break; case WindowsVersionFuture: osNameVer.append("Unknown Future Version"); break; default: osNameVer.append("Unknown version"); break; } // Append Service Pack version if any if (osvi.wServicePackMajor > 0 || osvi.wServicePackMinor > 0) { osNameVer.append(StringUtils::Format(" SP%d", osvi.wServicePackMajor)); if (osvi.wServicePackMinor > 0) { osNameVer.append(StringUtils::Format(".%d", osvi.wServicePackMinor)); } } } else osNameVer.append(" unknown"); #elif defined(TARGET_FREEBSD) || defined(TARGET_DARWIN_IOS) || defined(TARGET_DARWIN_OSX) osNameVer = GetOsName() + " " + GetOsVersion(); #elif defined(TARGET_ANDROID) osNameVer = GetOsName() + " " + GetOsVersion() + " API level " + StringUtils::Format("%d", CJNIBuild::SDK_INT); #elif defined(TARGET_LINUX) osNameVer = getValueFromOs_release("PRETTY_NAME"); if (osNameVer.empty()) { osNameVer = getValueFromLsb_release(lsb_rel_description); std::string osName(GetOsName(true)); if (!osName.empty() && osNameVer.find(osName) == std::string::npos) osNameVer = osName + osNameVer; if (osNameVer.empty()) osNameVer = "Unknown Linux Distribution"; } if (osNameVer.find(GetOsVersion()) == std::string::npos) osNameVer += " " + GetOsVersion(); #endif // defined(TARGET_LINUX) if (osNameVer.empty()) osNameVer = "Unknown OS Unknown version"; return osNameVer; }
void OGRPGResultLayer::ResolveSRID(OGRPGGeomFieldDefn* poGFldDefn) { /* We have to get the SRID of the geometry column, so to be able */ /* to do spatial filtering */ int nSRSId = UNDETERMINED_SRID; if( poGFldDefn->ePostgisType == GEOM_TYPE_GEOMETRY ) { if (pszGeomTableName != NULL) { CPLString osName(pszGeomTableSchemaName); osName += "."; osName += pszGeomTableName; OGRPGLayer* poBaseLayer = (OGRPGLayer*) poDS->GetLayerByName(osName); if (poBaseLayer) { int iBaseIdx = poBaseLayer->GetLayerDefn()-> GetGeomFieldIndex( poGFldDefn->GetNameRef() ); if( iBaseIdx >= 0 ) { OGRPGGeomFieldDefn* poBaseGFldDefn = poBaseLayer->myGetLayerDefn()->myGetGeomFieldDefn(iBaseIdx); poBaseGFldDefn->GetSpatialRef(); /* To make sure nSRSId is resolved */ nSRSId = poBaseGFldDefn->nSRSId; } } } if( nSRSId == UNDETERMINED_SRID ) { CPLString osGetSRID; const char* psGetSRIDFct; if (poDS->sPostGISVersion.nMajor >= 2) psGetSRIDFct = "ST_SRID"; else psGetSRIDFct = "getsrid"; osGetSRID += "SELECT "; osGetSRID += psGetSRIDFct; osGetSRID += "("; osGetSRID += OGRPGEscapeColumnName(poGFldDefn->GetNameRef()); osGetSRID += ") FROM("; osGetSRID += pszRawStatement; osGetSRID += ") AS ogrpggetsrid LIMIT 1"; PGresult* hSRSIdResult = OGRPG_PQexec(poDS->GetPGConn(), osGetSRID ); nSRSId = poDS->GetUndefinedSRID(); if( hSRSIdResult && PQresultStatus(hSRSIdResult) == PGRES_TUPLES_OK) { if ( PQntuples(hSRSIdResult) > 0 ) nSRSId = atoi(PQgetvalue(hSRSIdResult, 0, 0)); } else { CPLError( CE_Failure, CPLE_AppDefined, "%s", PQerrorMessage(poDS->GetPGConn()) ); } OGRPGClearResult(hSRSIdResult); } } else if( poGFldDefn->ePostgisType == GEOM_TYPE_GEOGRAPHY ) { nSRSId = 4326; } poGFldDefn->nSRSId = nSRSId; }
OGRLayer *OGRCARTODataSource::ICreateLayer( const char *pszNameIn, OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType, char ** papszOptions ) { if (!bReadWrite) { CPLError(CE_Failure, CPLE_AppDefined, "Operation not available in read-only mode"); return NULL; } /* -------------------------------------------------------------------- */ /* Do we already have this layer? If so, should we blow it */ /* away? */ /* -------------------------------------------------------------------- */ int iLayer; for( iLayer = 0; iLayer < nLayers; iLayer++ ) { if( EQUAL(pszNameIn,papoLayers[iLayer]->GetName()) ) { if( CSLFetchNameValue( papszOptions, "OVERWRITE" ) != NULL && !EQUAL(CSLFetchNameValue(papszOptions,"OVERWRITE"),"NO") ) { DeleteLayer( iLayer ); } else { CPLError( CE_Failure, CPLE_AppDefined, "Layer %s already exists, CreateLayer failed.\n" "Use the layer creation option OVERWRITE=YES to " "replace it.", pszNameIn ); return NULL; } } } CPLString osName(pszNameIn); if( CPLFetchBool(const_cast<const char**>(papszOptions), "LAUNDER", true) ) { char* pszTmp = OGRPGCommonLaunderName(pszNameIn); osName = pszTmp; CPLFree(pszTmp); } OGRCARTOTableLayer* poLayer = new OGRCARTOTableLayer(this, osName); const bool bGeomNullable = CPLFetchBool(const_cast<const char**>(papszOptions), "GEOMETRY_NULLABLE", true); int nSRID = (poSpatialRef && eGType != wkbNone) ? FetchSRSId( poSpatialRef ) : 0; bool bCartoify = CPLFetchBool(const_cast<const char**>(papszOptions), "CARTODBFY", CPLFetchBool(const_cast<const char**>(papszOptions), "CARTODBIFY", true)); if( bCartoify ) { if( nSRID != 4326 ) { if( eGType != wkbNone ) { CPLError(CE_Warning, CPLE_AppDefined, "Cannot register table in dashboard with " "cdb_cartodbfytable() since its SRS is not EPSG:4326"); } bCartoify = false; } } poLayer->SetLaunderFlag( CPLFetchBool(const_cast<const char**>(papszOptions), "LAUNDER", true) ); poLayer->SetDeferredCreation(eGType, poSpatialRef, bGeomNullable, bCartoify); papoLayers = (OGRCARTOTableLayer**) CPLRealloc( papoLayers, (nLayers + 1) * sizeof(OGRCARTOTableLayer*)); papoLayers[nLayers ++] = poLayer; return poLayer; }
int OGROpenFileGDBDataSource::OpenFileGDBv9(int iGDBFeatureClasses, int iGDBObjectClasses, int nInterestTable) { FileGDBTable oTable; int i; CPLDebug("OpenFileGDB", "FileGDB v9"); /* Fetch names of layers */ if( !oTable.Open(CPLFormFilename(m_osDirName, CPLSPrintf("a%08x", iGDBObjectClasses + 1), "gdbtable")) ) return FALSE; int iName = oTable.GetFieldIdx("Name"); int iCLSID = oTable.GetFieldIdx("CLSID"); if( iName < 0 || oTable.GetField(iName)->GetType() != FGFT_STRING || iCLSID < 0 || oTable.GetField(iCLSID)->GetType() != FGFT_STRING ) { CPLError(CE_Failure, CPLE_AppDefined, "Wrong structure for GDB_ObjectClasses table"); return FALSE; } std::vector< std::string > aosName; int nCandidateLayers = 0, nLayersSDC = 0; for(i=0;i<oTable.GetTotalRecordCount();i++) { if( !oTable.SelectRow(i) ) { if( oTable.HasGotError() ) break; aosName.push_back( "" ); continue; } const OGRField* psField = oTable.GetFieldValue(iName); if( psField != NULL ) { std::string osName(psField->String); psField = oTable.GetFieldValue(iCLSID); if( psField != NULL ) { /* Is it a non-spatial table ? */ if( strcmp(psField->String, "{7A566981-C114-11D2-8A28-006097AFF44E}") == 0 ) { aosName.push_back( "" ); AddLayer( osName, nInterestTable, nCandidateLayers, nLayersSDC, "", "", NULL, wkbNone ); } else { /* We should perhaps also check that the CLSID is the one of a spatial table */ aosName.push_back( osName ); } } } } oTable.Close(); /* Find tables that are spatial layers */ if( !oTable.Open(CPLFormFilename(m_osDirName, CPLSPrintf("a%08x", iGDBFeatureClasses + 1), "gdbtable")) ) return FALSE; int iObjectClassID = oTable.GetFieldIdx("ObjectClassID"); int iGeometryType = oTable.GetFieldIdx("GeometryType"); int iShapeField = oTable.GetFieldIdx("ShapeField"); if( iObjectClassID < 0 || iGeometryType < 0 || iShapeField < 0 || oTable.GetField(iObjectClassID)->GetType() != FGFT_INT32 || oTable.GetField(iGeometryType)->GetType() != FGFT_INT32 || oTable.GetField(iShapeField)->GetType() != FGFT_STRING ) { CPLError(CE_Failure, CPLE_AppDefined, "Wrong structure for GDB_FeatureClasses table"); return FALSE; } for(i=0;i<oTable.GetTotalRecordCount();i++) { if( !oTable.SelectRow(i) ) { if( oTable.HasGotError() ) break; continue; } const OGRField* psField; psField = oTable.GetFieldValue(iGeometryType); if( psField == NULL ) continue; int nGeomType = psField->Integer; OGRwkbGeometryType eGeomType = wkbUnknown; switch( nGeomType ) { case FGTGT_NONE: /* doesn't make sense ! */ break; case FGTGT_POINT: eGeomType = wkbPoint; break; case FGTGT_MULTIPOINT: eGeomType = wkbMultiPoint; break; case FGTGT_LINE: eGeomType = wkbMultiLineString; break; case FGTGT_POLYGON: eGeomType = wkbMultiPolygon; break; case FGTGT_MULTIPATCH: eGeomType = wkbMultiPolygon; break; } psField = oTable.GetFieldValue(iShapeField); if( psField == NULL ) continue; CPLString osGeomFieldName(psField->String); psField = oTable.GetFieldValue(iObjectClassID); if( psField == NULL ) continue; int idx = psField->Integer; if( psField != NULL && idx > 0 && idx <= (int)aosName.size() && aosName[idx-1].size() > 0 ) { const std::string osName(aosName[idx-1]); AddLayer( osName, nInterestTable, nCandidateLayers, nLayersSDC, "", "", osGeomFieldName.c_str(), eGeomType); } } if( m_apoLayers.size() == 0 && nCandidateLayers > 0 && nCandidateLayers == nLayersSDC ) return FALSE; return TRUE; }
OGRErr FGdbDriver::CommitTransaction(OGRDataSource*& poDSInOut, int& bOutHasReopenedDS) { CPLMutexHolderOptionalLockD(hMutex); bOutHasReopenedDS = FALSE; OGRMutexedDataSource* poMutexedDS = (OGRMutexedDataSource*)poDSInOut; FGdbDataSource* poDS = (FGdbDataSource* )poMutexedDS->GetBaseDataSource(); FGdbDatabaseConnection* pConnection = poDS->GetConnection(); if( !pConnection->IsLocked() ) { CPLError(CE_Failure, CPLE_NotSupported, "No transaction in progress"); return OGRERR_FAILURE; } bOutHasReopenedDS = TRUE; CPLString osName(poMutexedDS->GetName()); CPLString osNameOri(osName); if( osName[osName.size()-1] == '/' || osName[osName.size()-1] == '\\' ) osName.resize(osName.size()-1); #ifndef WIN32 int bPerLayerCopyingForTransaction = poDS->HasPerLayerCopyingForTransaction(); #endif pConnection->m_nRefCount ++; delete poDSInOut; poDSInOut = NULL; poMutexedDS = NULL; poDS = NULL; pConnection->CloseGeodatabase(); CPLString osEditedName(osName); osEditedName += ".ogredited"; #ifndef WIN32 if( bPerLayerCopyingForTransaction ) { int bError = FALSE; char** papszFiles; std::vector<CPLString> aosTmpFilesToClean; // Check for files present in original copy that are not in edited copy // That is to say deleted layers papszFiles = VSIReadDir(osName); for(char** papszIter = papszFiles; !bError && *papszIter; ++papszIter) { if( strcmp(*papszIter, ".") == 0 || strcmp(*papszIter, "..") == 0 ) continue; VSIStatBufL sStat; if( (*papszIter)[0] == 'a' && VSIStatL( CPLFormFilename(osEditedName, *papszIter, NULL), &sStat ) != 0 ) { if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE1") || VSIRename( CPLFormFilename(osName, *papszIter, NULL), CPLFormFilename(osName, *papszIter, "tmp") ) != 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot rename %s to %s", CPLFormFilename(osName, *papszIter, NULL), CPLFormFilename(osName, *papszIter, "tmp")); bError = TRUE; } else aosTmpFilesToClean.push_back(CPLFormFilename(osName, *papszIter, "tmp")); } } CSLDestroy(papszFiles); // Move modified files from edited directory to main directory papszFiles = VSIReadDir(osEditedName); for(char** papszIter = papszFiles; !bError && *papszIter; ++papszIter) { if( strcmp(*papszIter, ".") == 0 || strcmp(*papszIter, "..") == 0 ) continue; struct stat sStat; if( lstat( CPLFormFilename(osEditedName, *papszIter, NULL), &sStat ) != 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot stat %s", CPLFormFilename(osEditedName, *papszIter, NULL)); bError = TRUE; } else if( !S_ISLNK(sStat.st_mode) ) { // If there was such a file in original directory, first rename it // as a temporary file if( lstat( CPLFormFilename(osName, *papszIter, NULL), &sStat ) == 0 ) { if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE2") || VSIRename( CPLFormFilename(osName, *papszIter, NULL), CPLFormFilename(osName, *papszIter, "tmp") ) != 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot rename %s to %s", CPLFormFilename(osName, *papszIter, NULL), CPLFormFilename(osName, *papszIter, "tmp")); bError = TRUE; } else aosTmpFilesToClean.push_back(CPLFormFilename(osName, *papszIter, "tmp")); } if( !bError ) { if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE3") || CPLMoveFile( CPLFormFilename(osName, *papszIter, NULL), CPLFormFilename(osEditedName, *papszIter, NULL) ) != 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot move %s to %s", CPLFormFilename(osEditedName, *papszIter, NULL), CPLFormFilename(osName, *papszIter, NULL)); bError = TRUE; } else CPLDebug("FileGDB", "Move %s to %s", CPLFormFilename(osEditedName, *papszIter, NULL), CPLFormFilename(osName, *papszIter, NULL)); } } } CSLDestroy(papszFiles); if( !bError ) { for(size_t i=0;i<aosTmpFilesToClean.size();i++) { if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE4") || VSIUnlink(aosTmpFilesToClean[i]) != 0 ) { CPLError(CE_Warning, CPLE_AppDefined, "Cannot remove %s. Manual cleanup required", aosTmpFilesToClean[i].c_str()); } } } if( bError ) { CPLError(CE_Failure, CPLE_AppDefined, "An error occurred while moving files from %s back to %s. " "Manual cleaning must be done and dataset should be closed", osEditedName.c_str(), osName.c_str()); pConnection->SetLocked(FALSE); Release(osName); return OGRERR_FAILURE; } else if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE5") || CPLUnlinkTree(osEditedName) != 0 ) { CPLError(CE_Warning, CPLE_AppDefined, "Cannot remove %s. Manual cleanup required", osEditedName.c_str()); } } else #endif { CPLString osTmpName(osName); osTmpName += ".ogrtmp"; /* Install the backup copy as the main database in 3 steps : */ /* first rename the main directory in .tmp */ /* then rename the edited copy under regular name */ /* and finally dispose the .tmp directory */ /* That way there's no risk definitely losing data */ if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE1") || VSIRename(osName, osTmpName) != 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot rename %s to %s. Edited database during transaction is in %s" "Dataset should be closed", osName.c_str(), osTmpName.c_str(), osEditedName.c_str()); pConnection->SetLocked(FALSE); Release(osName); return OGRERR_FAILURE; } if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE2") || VSIRename(osEditedName, osName) != 0 ) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot rename %s to %s. The original geodatabase is in '%s'. " "Dataset should be closed", osEditedName.c_str(), osName.c_str(), osTmpName.c_str()); pConnection->SetLocked(FALSE); Release(osName); return OGRERR_FAILURE; } if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE3") || CPLUnlinkTree(osTmpName) != 0 ) { CPLError(CE_Warning, CPLE_AppDefined, "Cannot remove %s. Manual cleanup required", osTmpName.c_str()); } } pConnection->m_pGeodatabase = new Geodatabase; long hr = ::OpenGeodatabase(StringToWString(osName), *(pConnection->m_pGeodatabase)); if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE_REOPEN") || FAILED(hr)) { delete pConnection->m_pGeodatabase; pConnection->m_pGeodatabase = NULL; pConnection->SetLocked(FALSE); Release(osName); GDBErr(hr, "Failed to re-open Geodatabase. Dataset should be closed"); return OGRERR_FAILURE; } FGdbDataSource* pDS = new FGdbDataSource(this, pConnection); pDS->Open(osNameOri, TRUE, NULL); //pDS->SetPerLayerCopyingForTransaction(bPerLayerCopyingForTransaction); poDSInOut = new OGRMutexedDataSource(pDS, TRUE, hMutex, TRUE); pConnection->SetLocked(FALSE); return OGRERR_NONE; }
OGRErr FGdbDriver::RollbackTransaction(OGRDataSource*& poDSInOut, int& bOutHasReopenedDS) { CPLMutexHolderOptionalLockD(hMutex); bOutHasReopenedDS = FALSE; OGRMutexedDataSource* poMutexedDS = (OGRMutexedDataSource*)poDSInOut; FGdbDataSource* poDS = (FGdbDataSource* )poMutexedDS->GetBaseDataSource(); FGdbDatabaseConnection* pConnection = poDS->GetConnection(); if( !pConnection->IsLocked() ) { CPLError(CE_Failure, CPLE_NotSupported, "No transaction in progress"); return OGRERR_FAILURE; } bOutHasReopenedDS = TRUE; CPLString osName(poMutexedDS->GetName()); CPLString osNameOri(osName); if( osName[osName.size()-1] == '/' || osName[osName.size()-1] == '\\' ) osName.resize(osName.size()-1); //int bPerLayerCopyingForTransaction = poDS->HasPerLayerCopyingForTransaction(); pConnection->m_nRefCount ++; delete poDSInOut; poDSInOut = NULL; poMutexedDS = NULL; poDS = NULL; pConnection->CloseGeodatabase(); CPLString osEditedName(osName); osEditedName += ".ogredited"; OGRErr eErr = OGRERR_NONE; if( EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE1") || CPLUnlinkTree(osEditedName) != 0 ) { CPLError(CE_Warning, CPLE_AppDefined, "Cannot remove %s. Manual cleanup required", osEditedName.c_str()); eErr = OGRERR_FAILURE; } pConnection->m_pGeodatabase = new Geodatabase; long hr = ::OpenGeodatabase(StringToWString(osName), *(pConnection->m_pGeodatabase)); if (EQUAL(CPLGetConfigOption("FGDB_SIMUL_FAIL", ""), "CASE2") || FAILED(hr)) { delete pConnection->m_pGeodatabase; pConnection->m_pGeodatabase = NULL; pConnection->SetLocked(FALSE); Release(osName); GDBErr(hr, "Failed to re-open Geodatabase. Dataset should be closed"); return OGRERR_FAILURE; } FGdbDataSource* pDS = new FGdbDataSource(this, pConnection); pDS->Open(osNameOri, TRUE, NULL); //pDS->SetPerLayerCopyingForTransaction(bPerLayerCopyingForTransaction); poDSInOut = new OGRMutexedDataSource(pDS, TRUE, hMutex, TRUE); pConnection->SetLocked(FALSE); return eErr; }
bool GMLASXLinkResolutionConf::LoadFromXML(CPLXMLNode* psRoot) { m_nTimeOut = atoi( CPLGetXMLValue( psRoot, "Timeout", "0" ) ); m_nMaxFileSize = atoi( CPLGetXMLValue( psRoot, "MaxFileSize", CPLSPrintf("%d", MAX_FILE_SIZE_DEFAULT)) ); m_nMaxGlobalResolutionTime = atoi( CPLGetXMLValue( psRoot, "MaxGlobalResolutionTime", "0" ) ); m_osProxyServerPort = CPLGetXMLValue( psRoot, "ProxyServerPort", "" ); m_osProxyUserPassword = CPLGetXMLValue( psRoot, "ProxyUserPassword", "" ); m_osProxyAuth = CPLGetXMLValue( psRoot, "ProxyAuth", "" ); m_osCacheDirectory = CPLGetXMLValue( psRoot, "CacheDirectory", "" ); if( m_osCacheDirectory.empty() ) { m_osCacheDirectory = GMLASConfiguration::GetBaseCacheDirectory(); if( !m_osCacheDirectory.empty() ) { m_osCacheDirectory = CPLFormFilename( m_osCacheDirectory, "xlink_resolved_cache", NULL ); } } m_bDefaultResolutionEnabled = CPLGetXMLBoolValue( psRoot, "DefaultResolution.enabled", DEFAULT_RESOLUTION_ENABLED_DEFAULT); m_bDefaultAllowRemoteDownload = CPLGetXMLBoolValue( psRoot, "DefaultResolution.AllowRemoteDownload", ALLOW_REMOTE_DOWNLOAD_DEFAULT); // TODO when we support other modes // m_eDefaultResolutionMode = m_nDefaultResolutionDepth = atoi( CPLGetXMLValue( psRoot, "DefaultResolution.ResolutionDepth", "1") ); m_bDefaultCacheResults = CPLGetXMLBoolValue( psRoot, "DefaultResolution.CacheResults", CACHE_RESULTS_DEFAULT); CPLXMLNode* psIterURL = psRoot->psChild; for( ; psIterURL != NULL; psIterURL = psIterURL->psNext ) { if( psIterURL->eType == CXT_Element && strcmp(psIterURL->pszValue, "URLSpecificResolution") == 0 ) { GMLASXLinkResolutionConf::URLSpecificResolution oItem; oItem.m_osURLPrefix = CPLGetXMLValue(psIterURL, "URLPrefix", ""); oItem.m_bAllowRemoteDownload = CPLGetXMLBoolValue( psIterURL, "AllowRemoteDownload", ALLOW_REMOTE_DOWNLOAD_DEFAULT); const char* pszResolutionModel = CPLGetXMLValue(psIterURL, "ResolutionMode", "RawContent"); if( EQUAL(pszResolutionModel, "RawContent") ) oItem.m_eResolutionMode = RawContent; else oItem.m_eResolutionMode = FieldsFromXPath; oItem.m_nResolutionDepth = atoi( CPLGetXMLValue( psIterURL, "ResolutionDepth", "1") ); oItem.m_bCacheResults = CPLGetXMLBoolValue( psIterURL, "CacheResults", CACHE_RESULTS_DEFAULT); CPLXMLNode* psIter = psIterURL->psChild; for( ; psIter != NULL; psIter = psIter->psNext ) { if( psIter->eType == CXT_Element && strcmp(psIter->pszValue, "HTTPHeader") == 0 ) { CPLString osName( CPLGetXMLValue(psIter, "Name", "") ); CPLString osValue( CPLGetXMLValue(psIter, "Value", "") ); oItem.m_aosNameValueHTTPHeaders.push_back( std::pair<CPLString, CPLString>(osName, osValue)); } else if( psIter->eType == CXT_Element && strcmp(psIter->pszValue, "Field") == 0 ) { URLSpecificResolution::XPathDerivedField oField; oField.m_osName = CPLGetXMLValue(psIter, "Name", ""); oField.m_osType = CPLGetXMLValue(psIter, "Type", ""); oField.m_osXPath = CPLGetXMLValue(psIter, "XPath", ""); oItem.m_aoFields.push_back( oField ); } } m_aoURLSpecificRules.push_back( oItem ); } } return true; }