Example #1
0
/*!
  Return true if the SxeProgramInfo object represents a valid binary for SXE registration,
  and otherwise return false.

  The binary is valid if all of the components of absolutePath() above are non-empty, and
  the resulting path is to a file which exists
*/
bool SxeProgramInfo::isValid() const
{
    if ( d->binary == absolutePath() )
        return d->valid;
    if ( fileName.isEmpty() || relPath.isEmpty() )
        return false;
#ifdef SXE_INSTALLER
    if ( installRoot.isEmpty() )
        return false;
#else
    if ( runRoot.isEmpty() )
        return false;
#endif
    d->binary = absolutePath();
    d->valid = false;
    int result = ::stat( QFile::encodeName( d->binary ), &d->sxe_stat );
    qLog(SXE) << "stat'ed binary" << d->binary << " - result:" << result;
    if ( result == 0 )
    {
        d->valid = true;
    }
    else if ( result != -ENOENT )
    {
        qLog(SXE) << "Could not stat" << d->binary << strerror( errno );
    }
    return d->valid;
}
void Plugin::remove()
{
    if (!d->removed) {
        d->removed = !QFile::exists(absolutePath()) || QFile::remove(absolutePath());
        if (d->removed) {
            emit removed();
        }
    }
}
int FileDescriptorTable::rename(const char *oldName, const char *newName)
{
    if(oldName==0 || oldName[0]=='\0') return -EFAULT;
    if(newName==0 || newName[0]=='\0') return -EFAULT;
    string oldPath=absolutePath(oldName);
    string newPath=absolutePath(newName);
    if(oldPath.empty() || newPath.empty()) return -ENAMETOOLONG;
    return FilesystemManager::instance().renameHelper(oldPath,newPath);
}
Example #4
0
void lookForObfs(const QDir& origin, QList< std::shared_ptr<QFile> > obfsCollection)
{
    auto obfs = origin.entryInfoList(QStringList() << "*.obf", QDir::Files);
    for(auto itObf = obfs.begin(); itObf != obfs.end(); ++itObf)
        obfsCollection.push_back(std::shared_ptr<QFile>(new QFile(itObf->absolutePath())));
    
    auto subdirs = origin.entryInfoList(QStringList(), QDir::AllDirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
    for(auto itSubdir = subdirs.begin(); itSubdir != subdirs.end(); ++itSubdir)
        lookForObfs(QDir(itSubdir->absolutePath()), obfsCollection);
}
int FileDescriptorTable::unlink(const char *name)
{
    if(name==0 || name[0]=='\0') return -EFAULT;
    string path=absolutePath(name);
    if(path.empty()) return -ENAMETOOLONG;
    return FilesystemManager::instance().unlinkHelper(path);
}
int FileDescriptorTable::statImpl(const char* name, struct stat* pstat, bool f)
{
    if(name==0 || name[0]=='\0' || pstat==0) return -EFAULT;
    string path=absolutePath(name);
    if(path.empty()) return -ENAMETOOLONG;
    return FilesystemManager::instance().statHelper(path,pstat,f);
}
Example #7
0
void ThemeSelector::refresh()
{
    // Build list of themes
    auto themesDir = Utils::getThemesDir();
    auto themeDirs = themesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
    auto themes = std::unique_ptr<ThemeList>(new ThemeList);
    for (auto it = themeDirs.begin(); it != themeDirs.end(); ++it)
    {
        try
        {
            QDir curThemeDir = themesDir.absolutePath() + "/" + *it;
            themes->emplace_back(std::make_pair(
                curThemeDir, std::move(std::unique_ptr<ThemeManifest>(
                new ThemeManifest(curThemeDir.absolutePath() + "/manifest.xml")))));
        }
        catch (const ThemeManifest::XInvalidManifest &e) 
        {
            msg("[" PLUGIN_NAME "] %s: %s\n", it->toUtf8().data(), e.what());
        }
    }

    // Publish theme list
    m_widgets.lwSkinSelection->clear();
    for (auto it = themes->begin(); it != themes->end(); ++it)
    {
        m_widgets.lwSkinSelection->addItem(it->second->themeName());
    }

    m_widgets.lwSkinSelection->setCurrentIndex(m_widgets.lwSkinSelection->rootIndex());
    m_curThemeList = std::move(themes);
}
Example #8
0
  Try<Bytes> du(std::string path)
  {
    path = absolutePath(path);

    Try<std::string> command = strings::format(
        "%s fs -du -h '%s'", hadoop, path);

    CHECK_SOME(command);

    // We are piping stderr to stdout so that we can see the error (if
    // any) in the logs emitted by `os::shell()` in case of failure.
    //
    // TODO(marco): this was the existing logic, but not sure it is
    // actually needed.
    Try<std::string> out = os::shell(command.get() + " 2>&1");

    if (out.isError()) {
      return Error("HDFS du failed: " + out.error());
    }

    const std::vector<std::string>& s = strings::split(out.get(), " ");
    if (s.size() != 2) {
      return Error("HDFS du returned an unexpected number of results: '" +
                   out.get() + "'");
    }

    Result<size_t> size = numify<size_t>(s[0]);
    if (size.isError()) {
      return Error("HDFS du returned unexpected format: " + size.error());
    } else if (size.isNone()) {
      return Error("HDFS du returned unexpected format");
    }

    return Bytes(size.get());
  }
Example #9
0
		bool File::setPath(const String &filePath)
		{
			_mutex.lock();
			
			if(isOpen())
			{
				if(filePath.isEmpty())
					return false;
					
				FileImpl *impl = new FileImpl;
				if(!impl->open(filePath, _openMode))
				{
					delete _impl;
					return false;
				}
				
				_impl->close();
				delete _impl;
				
				_impl = impl;
			}
			
			_filePath = absolutePath(filePath);
			return true;
		}
Example #10
0
Node* DesktopNode::getNodeByModelPath(const ModelPath &path)
{
    if (path.size() <= 0)
    {
        return 0;
    }

    string root_path = path.front();
    if (root_path != absolutePath())
    {
        return 0;
    }
    Node* node = this;
    for (int i = 1; i < path.size(); i++)
    {
        if (node == 0)
        {
            return 0;
        }
        ContainerNode* container = dynamic_cast<ContainerNode*>(node);
        if (container != 0)
        {
            node = container->node(path[i]).get();
        }
        else if (i < path.size() - 1)
        {
            return 0;
        }
    }
    return node;
}
Example #11
0
bool DesktopNode::updateChildren()
{
    if ((status_filter_ & NODE_NOT_ON_CLOUD) && !checkCloudCacheOrUpdate())
    {
        // pending scaning until cloud info is retrieved
        pending_scan_ = true;
        return true;
    }    

    switch (current_display_mode_)
    {
        case BY_FOLDER:
            updateChildrenByFolder();
            break;
        case BY_SORT:
            updateChildrenBySort();
            break;
        case EXPAND_ALL:
            updateChildrenByExpandingAll();
            break;
        default:
            return false;
    }
    setDirty(false);

    NodeChildenReadyArgs children_ready_args;
    children_ready_args.current_node_path = absolutePath();
    children_ready_args.succeeded = true;
    children_ready_args.children = filterChildren(children_);
    FireEvent(EventChildrenIsReady, children_ready_args);
    return true;
}
QVariant RecordingsModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
    {
        return QVariant();
    }

    auto fileInfo = mData[index.row()];

    switch (role)
    {
    case FilePath:
        return fileInfo.absoluteFilePath();
    case FileName:
        return fileInfo.fileName();
    case FileDir:
        return fileInfo.absolutePath();
    case Modified:
        return fileInfo.lastModified();
    case Section:
        return RecordingsModel::sectionName(fileInfo.lastModified().date());
    default:
        return QVariant();
    }
}
Example #13
0
void ResultsWindow::handleCellClicked(int rowIndex, int columnIndex) {
    // make sure this click was on the file/domain being baked
    if (columnIndex == 0) {
        // use QDesktopServices to show the output directory for this row
        auto directory = _outputDirectories[rowIndex];
        QDesktopServices::openUrl(QUrl::fromLocalFile(directory.absolutePath()));
    }
}
Example #14
0
File: URI.cpp Project: 12307/poco
URI::URI(const Path& path):
	_scheme("file"),
	_port(0)
{
	Path absolutePath(path);
	absolutePath.makeAbsolute();
	_path = absolutePath.toString(Path::PATH_UNIX);
}
coResult coCppTypesGeneratorPlugin::GenerateType(coDynamicString& _relativePath, const coParsedType& _parsedType)
{
	const coType* type = _parsedType.type;
	coASSERT(type);
	coTRY(type->name != "", "Empty type name");

	coLocalAllocator localAllocator(4048);
	coDynamicString absolutePath(localAllocator);

	// Paths
	{
		const coConstString& projectPath = projectGenerator->GetProjectRelativePath();
		coDynamicString tmpPath(localAllocator);
		coJoinPaths(tmpPath, projectPath, co_typesPath);
		coJoinPaths(_relativePath, tmpPath, type->name);
		_relativePath << ".cxx";

		const coConstString& outPath = projectGenerator->GetOutReferenceDir();
		coJoinPaths(absolutePath, outPath, _relativePath);
		coASSERT(coIsPathNormalized(_relativePath));
	}

	coStringOutputStream stream;
	coWriteHeader(stream);
	coWriteInclude(stream, _parsedType.sourcePath);
	coWriteInclude(stream, "lang/reflect/coType.h");
	coWriteInclude(stream, "lang/reflect/coType_f.h");
	coWriteInclude(stream, "lang/result/coResult_f.h");
	coWriteInclude(stream, "lang/reflect/coTypeBuilder.h");
	coWriteInclude(stream, "lang/reflect/coTypeAutoRegistrator.h");
	if (_parsedType.parsedFields.count)
	{
		coWriteInclude(stream, "lang/reflect/coField.h");
		coWriteInclude(stream, "lang/reflect/coField_f.h");
	}
	coWriteInclude(stream, "lang/result/coResult.h");
	coWriteInclude(stream, "container/string/coDynamicString_f.h");
	stream << "\n";
	coTRY(WriteTypeBuilderDeclaration(stream, _parsedType), nullptr);
	coTRY(WriteInitTypeFunc(stream, _parsedType), nullptr);
	coTRY(WriteLinkTypeFunc(stream, _parsedType), nullptr);
	coTRY(WriteGetStaticTypeFunc(stream, _parsedType), nullptr);
	coTRY(stream.GetResult(), "Failed to write to stream: "<<stream << ".");

	{
		coDynamicArray<coByte> output;
		stream.GetOutput(output);
		coFileAccess file;
		coFileAccess::InitConfig c;
		c.mode = coFileAccess::write;
		c.path = absolutePath;
		coTRY(file.Init(c), "Failed to open for writing: " << file << ".");
		coTRY(file.Write(output), "Failed to write in: " << file << ".");
	}

	return true;
}
Example #16
0
void FileSystemDisk::deleteFile(const char* path)
{
	RIO_ASSERT_NOT_NULL(path);

	TempAllocator256 ta;
	DynamicString absolutePath(ta);
	getAbsolutePath(path, absolutePath);

	OsFn::deleteFile(absolutePath.getCStr());
}
Example #17
0
void FileSystemDisk::getFileList(const char* path, Vector<DynamicString>& files)
{
	RIO_ASSERT_NOT_NULL(path);

	TempAllocator256 ta;
	DynamicString absolutePath(ta);
	getAbsolutePath(path, absolutePath);

	OsFn::getFileList(absolutePath.getCStr(), files);
}
Example #18
0
bool FileSystemDisk::getIsDirectory(const char* path)
{
	RIO_ASSERT_NOT_NULL(path);

	TempAllocator256 ta;
	DynamicString absolutePath(ta);
	getAbsolutePath(path, absolutePath);

	return OsFn::getIsDirectory(absolutePath.getCStr());
}
Example #19
0
uint64_t FileSystemDisk::getLastModifiedTime(const char* path)
{
	RIO_ASSERT_NOT_NULL(path);

	TempAllocator256 ta;
	DynamicString absolutePath(ta);
	getAbsolutePath(path, absolutePath);

	return OsFn::getLastModifiedTime(absolutePath.getCStr());
}
Example #20
0
ScriptUnit::ScriptUnit(const QString &filePath, IScriptEngineFactory *factory, QObject *parent)
    : IScriptUnit()
    , m_isLoaded(false)
    , m_filePath(absolutePath(filePath))
    , m_factory(factory)
    , m_script(new QTextDocument(this))
    , m_engine(nullptr)
{
    setParent(parent);
}
Example #21
0
bool KGrSetTheme::readFromDesktopFile(const QString& path)
{
    // Base-class call.
    if (!KgTheme::readFromDesktopFile(path))
        return false;

    // Customised behaviour: interprete "Set" key as "FileName" for SVG file.
    setGraphicsPath (absolutePath (path, customData("Set")));
    return true;
}
int FileDescriptorTable::rmdir(const char *name)
{
    if(name==0 || name[0]=='\0') return -EFAULT;
    string path=absolutePath(name);
    if(path.empty()) return -ENAMETOOLONG;
    ResolvedPath openData=FilesystemManager::instance().resolvePath(path,true);
    if(openData.result<0) return openData.result;
    StringPart sp(path,string::npos,openData.off);
    return openData.fs->rmdir(sp);
}
Example #23
0
void unpackAndroidAssets() {
    const QString DEST_PREFIX = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/";

    QStringList filesToCopy = readAssetLines("cache_assets.txt");
    QString dateStamp = filesToCopy.takeFirst();
    QString dateStampFilename = DEST_PREFIX + dateStamp;
    qDebug() << "Checking date stamp" << dateStamp;
    if (QFileInfo(dateStampFilename).exists()) {
        return;
    }

    auto rootDir = QDir::root();
    for (const auto& fileToCopy : filesToCopy) {
        auto destFileName = DEST_PREFIX + fileToCopy;
        auto destFolder = QFileInfo(destFileName).absoluteDir();
        if (!destFolder.exists()) {
            qDebug() << "Creating folder" << destFolder.absolutePath();
            if (!rootDir.mkpath(destFolder.absolutePath())) {
                throw std::runtime_error("Error creating output path");
            }
        }
        if (QFile::exists(destFileName)) {
            qDebug() << "Removing old file" << destFileName;
            if (!QFile::remove(destFileName)) {
                throw std::runtime_error("Failed to remove existing file");
            }
        }

        qDebug() << "Copying asset " << fileToCopy << "to" << destFileName;
        copyAsset(fileToCopy.toStdString().c_str(), destFileName);
    }

    {
        qDebug() << "Writing date stamp" << dateStamp;
        QFile file(dateStampFilename);
        if (!file.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
            throw std::runtime_error("Can't write date stamp");
        }
        QTextStream(&file) << "touch" << endl;
        file.close();
    }
}
Example #24
0
void Node::setStatus(int status, bool mandatory)
{
    if (status_ != status || mandatory)
    {
        status_ = status;
        NodeStatusUpdated status_update_args;
        status_update_args.current_node_path = absolutePath();
        status_update_args.new_status = status_;
        FireEvent(EventNodeStatusUpdated, status_update_args);
    }
}
Example #25
0
int main(int argc, char *argv[])
{
	char	*result, *argp;
	int 	errflg, absolute, canon, relative, nextArg;

#if _WIN32
    _setmode(1, _O_BINARY);
#endif

	errflg = 0;
    canon = absolute = relative = 0;

    for (nextArg = 1; nextArg < argc; nextArg++) {
        argp = argv[nextArg];
        if (*argp != '-') {
            break;
        }
        if (strcmp(argp, "-a") == 0) {
			absolute++;
        } else if (strcmp(argp, "-c") == 0) {
			canon++;
        } else if (strcmp(argp, "-r") == 0) {
			relative++;
        } else {
            errflg++;
        }
	}

    if (!absolute && !relative && !canon) {
        canon = 1;
    }
	if (errflg || (absolute + relative + canon) > 1) {
        fprintf(stderr, "Usage: getpath [-arc] files...\n");
        exit(2);
	}

	for (; nextArg < argc; ) {
        if (relative) {
            result = canonPath(relativePath(argv[nextArg]));
        } else if (absolute) {
            result = canonPath(absolutePath(argv[nextArg]));
        } else {
            result = canonPath(argv[nextArg]);
        }
        if (++nextArg < argc) {
            printf("%s ", result);
        } else {
            printf("%s", result);
        }
	}
    printf("\n");

	return 0;
}
bool ImageItem::setName(const QString &name)
{
  if (m_type == Image) {
    MetaDataManager::self()->setImageName(m_id, name);
    return true;
  }

  if (m_type == Gallery)
    return MetaDataManager::self()->setGalleryName(m_id, name, absolutePath());

  return false;
}
Example #27
0
File* FileSystemDisk::open(const char* path, FileOpenMode::Enum mode)
{
	RIO_ASSERT_NOT_NULL(path);

	TempAllocator256 ta;
	DynamicString absolutePath(ta);
	getAbsolutePath(path, absolutePath);

	FileDisk* file = RIO_NEW(*allocator, FileDisk)();
	file->open(absolutePath.getCStr(), mode);
	return file;
}
Example #28
0
char *Lv2PathMapper::mapAbsolutePath(const char *abstractPath)
{
    // get script folder and append incoming relative path
    fs::path absolutePath(ScriptHost::instance().getCurrentFolder());
    absolutePath /= abstractPath;
    absolutePath = canonical(absolutePath);
    // copy to malloc-allocated char*
    const char *pathString = absolutePath.c_str();
    char *ret = (char *)malloc(strlen(pathString) + 1);
    strcpy(ret, pathString);
    return ret;
}
Example #29
0
int main (int argc, char **argv)
{
    KLocalizedString::setApplicationDomain("kronometer");

    QApplication app {argc, argv};

    KCrash::initialize();

    auto aboutData = KAboutData {
        QStringLiteral("kronometer"),   // componentName
        i18nc("KAboutData display name", "Kronometer"),
        QStringLiteral(KRONOMETER_VERSION_STRING),
        i18n("Kronometer is a simple stopwatch application"), // shortDescription
        KAboutLicense::GPL_V2,    // licenseType
        i18n("Copyright (C) 2014-2016 Elvis Angelaccio"),    // copyrightStatement
        {},  // otherText
        QStringLiteral("http://aelog.org/kronometer")   // homePageAddress
    };

    aboutData.addAuthor(
        i18n("Elvis Angelaccio"),
        i18n("Maintainer"),
        QStringLiteral("*****@*****.**"),
        QStringLiteral("http://aelog.org")
    );

    aboutData.addCredit(
        i18n("Ken Vermette"),
        i18n("Kronometer icon"),
        QStringLiteral("*****@*****.**")
    );

    KAboutData::setApplicationData(aboutData);

    app.setApplicationName(aboutData.componentName());
    app.setApplicationDisplayName(aboutData.displayName());
    app.setOrganizationDomain(aboutData.organizationDomain());
    app.setApplicationVersion(aboutData.version());
    app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kronometer")));

    // Make sure that the local data directory is available.
    auto appdata = QFileInfo {QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)};
    if (not appdata.exists()) {
        auto dir = QDir {appdata.absolutePath()};
        dir.mkdir(appdata.fileName());
    }

    auto window = new MainWindow {};
    window->show();

    return app.exec();
}
Example #30
0
void KmxController::UpdateMotionParams(){
  char fileName[256];
  absolutePath(settings_file_, fileName);

  MappedFile mmFile;
  if(mmapNamedFile(mmFile, fileName)){
    log_info("Failed to map file: %s", fileName);
    return;
  }
  SetMotionParams(mmFile.addr, mmFile.filesize);

  unmapFile(mmFile);
}