コード例 #1
0
ファイル: AssetUpload.cpp プロジェクト: AlphaStaxLLC/hifi
void AssetUpload::start() {
    if (QThread::currentThread() != thread()) {
        QMetaObject::invokeMethod(this, "start");
        return;
    }
    
    if (_data.isEmpty() && !_filename.isEmpty()) {
        // try to open the file at the given filename
        QFile file { _filename };
        
        if (file.open(QIODevice::ReadOnly)) {            
            _data = file.readAll();
        } else {
            // we couldn't open the file - set the error result
            _error = FileOpenError;
            
            // emit that we are done
            emit finished(this, QString());

            return;
        }
    }
    
    // ask the AssetClient to upload the asset and emit the proper signals from the passed callback
    auto assetClient = DependencyManager::get<AssetClient>();
   
    if (!_filename.isEmpty()) {
        qCDebug(asset_client) << "Attempting to upload" << _filename << "to asset-server.";
    }
    
    assetClient->uploadAsset(_data, [this](bool responseReceived, AssetServerError error, const QString& hash){
        if (!responseReceived) {
            _error = NetworkError;
        } else {
            switch (error) {
                case AssetServerError::NoError:
                    _error = NoError;
                    break;
                case AssetServerError::AssetTooLarge:
                    _error = TooLarge;
                    break;
                case AssetServerError::PermissionDenied:
                    _error = PermissionDenied;
                    break;
                case AssetServerError::FileOperationFailed:
                    _error = ServerFileError;
                    break;
                default:
                    _error = FileOpenError;
                    break;
            }
        }
        
        if (_error == NoError && hash == hashData(_data).toHex()) {
            saveToCache(getATPUrl(hash), _data);
        }
        
        emit finished(this, hash);
    });
}
コード例 #2
0
ファイル: AssetUtils.cpp プロジェクト: howard-stearns/hifi
// Extract the valid AssetHash portion from atp: URLs like "[atp:]HASH[.fbx][?query]"
// (or an invalid AssetHash if not found)
AssetHash extractAssetHash(const QString& input) {
    if (isValidHash(input)) {
        return input;
    }
    QString path = getATPUrl(input).path();
    QString baseName = QFileInfo(path).baseName();
    if (isValidHash(baseName)) {
        return baseName;
    }
    return AssetHash();
}
コード例 #3
0
ファイル: ATPAssetMigrator.cpp プロジェクト: Giugiogia/hifi
void ATPAssetMigrator::assetUploadFinished(AssetUpload *upload, const QString& hash) {
    if (upload->getError() == AssetUpload::NoError) {

        const auto& modelURL = _originalURLs[upload];
        
        // successfully uploaded asset - make any required replacements found in the pending replacements
        auto values = _pendingReplacements.values(modelURL);
        
        
        QString atpURL = getATPUrl(hash, upload->getExtension()).toString();
        
        for (auto value : values) {
            // replace the modelURL in this QJsonValueRef with the hash
            QJsonObject valueObject = value.toObject();
            valueObject[MODEL_URL_KEY] = atpURL;
            value = valueObject;
        }
        
        // add this URL to our list of uploaded assets
        _uploadedAssets.insert(modelURL, atpURL);
        
        // pull the replaced models from _pendingReplacements
        _pendingReplacements.remove(modelURL);
        
        // are we out of pending replacements? if so it is time to save the entity-server file
        if (_doneReading && _pendingReplacements.empty()) {
            saveEntityServerFile();
            
            // reset after the attempted save, success or fail
            reset();
        }
    } else {
        AssetUploadDialogFactory::showErrorDialog(upload, _dialogParent);
    }
    
    upload->deleteLater();
}