Пример #1
0
void StBrowserPlugin::streamAsFile(NPStream*   theStream,
                                   const char* theFileName) {
    if(theFileName == NULL) {
        ///ST_DEBUG_LOG("streamAsFile ERROR");
        return;
    }

    const StString anUrl((theStream->url != NULL) ? theStream->url : "");
    const bool isPreview = !myPreviewUrl.isEmpty()
                           && (anUrl.isEndsWith(myPreviewUrl) || anUrl.isEndsWith(myPreviewUrlUtf8));
    StString aFileName = StString(theFileName);
    StString aFolder, aDummy;
    StFileNode::getFolderAndFile(aFileName, aFolder, aDummy);
    if(aFileName.isStartsWith(StProcess::getTempFolder())) {
        // Some browsers (Safari) returns file copies in temporary folder
        // and imidiatly remove it after function execution.
        // sView load image async, so we need to copy file until it will be read.
        StString aFileNameNew = aFileName + ".sView.tmp";
        if(StFileNode::moveFile(aFileName, aFileNameNew)) {
            aFileName = aFileNameNew;
            myTmpFiles.add(aFileName);
        }
    }

    StMutexAuto aLock(myMutex);
    if(isPreview) {
        myPreviewPath = aFileName;
    } else {
        myFullPath    = aFileName;
    }
}
Пример #2
0
StString StProcess::getAbsolutePath(const StString& thePath) {
    StString aPath;
    if(thePath.isStartsWith(ST_FILE_PROTOCOL)) {
        const StString aData = thePath.subString(ST_FILE_PROTOCOL.getLength(), thePath.getLength());
        aPath.fromUrl(aData);
    } else {
        aPath = thePath;
    }

    if(StFileNode::isAbsolutePath(aPath)) {
        return aPath;
    }
    return StProcess::getWorkingFolder() + aPath; // make absolute path
}
Пример #3
0
void StAndroidGlue::setOpenPath(const jstring  theOpenPath,
                                const jstring  theMimeType,
                                const jboolean theIsLaunchedFromHistory) {
    JNIEnv* aJniEnv = myActivity->env;
    StString anOpenPath = stStringFromJava(aJniEnv, theOpenPath);
    StString aMimeType  = stStringFromJava(aJniEnv, theMimeType);

    const StString ST_FILE_PROTOCOL("file://");
    if(anOpenPath.isStartsWith(ST_FILE_PROTOCOL)) {
        const size_t   aCutFrom = ST_FILE_PROTOCOL.getLength();
        const StString aPath    = anOpenPath.subString(aCutFrom, (size_t )-1);
        anOpenPath.fromUrl(aPath);
    }

    StMutexAuto aLock(myFetchLock);
    if(myCreatePath.isEmpty()) {
        myCreatePath = anOpenPath;
    }

    // ignore outdated intent from history list - use C++ recent list instead
    if(!theIsLaunchedFromHistory) {
        myDndPath = anOpenPath;
    }
}
Пример #4
0
StHandle<StOpenInfo> StApplication::parseProcessArguments() {
    StHandle<StOpenInfo> anInfo = new StOpenInfo();

    StArrayList<StString> anArguments = StProcess::getArguments();
    StArgumentsMap anOpenFileArgs;
    size_t aFilesCount = 0;
    bool isFilesSection = false;
    const StString ARGUMENT_FILES_SECTION     = '-';
    const StString ARGUMENT_ANY               = "--";
    const StString ARGUMENT_HELP              = "help";
    const StString ARGUMENT_FILE              = "file";
    const StString ARGUMENT_LEFT_VIEW         = "left";
    const StString ARGUMENT_RIGHT_VIEW        = "right";
    // parse extra parameters
    for(size_t aParamIter = 1; aParamIter < anArguments.size(); ++aParamIter) {
        StString aParam = anArguments[aParamIter];
        ///ST_DEBUG_LOG("aParam= '" + aParam + "'");
        if(isFilesSection) {
            // file name
            StString aFilePath = StProcess::getAbsolutePath(aParam);
            anOpenFileArgs.add(StArgument(ARGUMENT_FILE + aFilesCount++, aFilePath));
            if(!anInfo->hasPath()) {
                // first file determines MIME type (needed to autoselect Drawer plugin)
                anInfo->setPath(aFilePath);
            }
        } else if(aParam == ARGUMENT_FILES_SECTION) {
            isFilesSection = true;
        } else if(aParam.isStartsWith(ARGUMENT_ANY)) {
            // argument
            StArgument anArg; anArg.parseString(aParam.subString(2, aParam.getLength())); // cut suffix --

            if(anArg.getKey().isEqualsIgnoreCase(ARGUMENT_HELP)) {
                return NULL;
            } else if(anArg.getKey().isEqualsIgnoreCase(ARGUMENT_LEFT_VIEW)) {
                // left view
                anArg.setValue(StProcess::getAbsolutePath(anArg.getValue()));
                anOpenFileArgs.add(anArg);
                anInfo->setPath(anArg.getValue()); // left file always determines MIME type
            } else if(anArg.getKey().isEqualsIgnoreCase(ARGUMENT_RIGHT_VIEW)) {
                // right view
                anArg.setValue(StProcess::getAbsolutePath(anArg.getValue()));
                anOpenFileArgs.add(anArg);
                if(!anInfo->hasPath()) {
                    anInfo->setPath(anArg.getValue());
                }
            } else {
                // pass argument unchanged
                anOpenFileArgs.add(anArg);
            }
        } else {
            // file name
            StString aFilePath = StProcess::getAbsolutePath(aParam);
            anOpenFileArgs.add(StArgument(ARGUMENT_FILE + aFilesCount++, aFilePath));
            if(!anInfo->hasPath()) {
                // first file determines MIME type (needed to autoselect Drawer plugin)
                anInfo->setPath(aFilePath);
            }
        }
    }

    anInfo->setArgumentsMap(anOpenFileArgs);
    return anInfo;
}