Changeset 78701 in vbox for trunk/src/VBox
- Timestamp:
- May 23, 2019 5:02:30 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 130779
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/net/UIDownloaderAdditions.cpp
r78668 r78701 59 59 const QString strSource = strSourcePath + strSourceName; 60 60 const QString strPathSHA256SumsFile = QString("https://www.virtualbox.org/download/hashes/%1/SHA256SUMS").arg(strVersion); 61 const QString strTarget = QDir(vboxGlobal().homeFolder()).absoluteFilePath( strSourceName);61 const QString strTarget = QDir(vboxGlobal().homeFolder()).absoluteFilePath(QString("%1.tmp").arg(strSourceName)); 62 62 63 63 /* Set source/target: */ … … 144 144 } 145 145 146 /* Serialize that buffer into the file: */ 146 /* Make sure temporary file exists. If we have 147 * reached this place, it's already written and verified. */ 148 const QString strTempFilename = target(); 149 if (!QFile::exists(strTempFilename)) 150 { 151 /* But still we are providing a failsafe. 152 * Since we can try to write it again. */ 153 QFile file(strTempFilename); 154 if (!file.open(QIODevice::WriteOnly)) 155 AssertFailedReturnVoid(); 156 file.write(m_receivedData); 157 } 158 159 /* Rename temporary file to target one. This can require a number 160 * of tries to let user choose the place to save file to. */ 161 QString strNetTarget = target(); 162 strNetTarget.remove(QRegExp("\\.tmp$")); 163 setTarget(strNetTarget); 147 164 while (true) 148 165 { 149 /* Make sure t he file already exists. If we reached150 * this place, it's already written and checked. */151 QFile file(target());152 bool fSuccess = false;153 /* Check step. Try to open file for reading first.*/154 if (file.open(QIODevice::ReadOnly))155 fSuccess = true;156 /* Failsafe step. Try to open file for writing otherwise.*/157 if (!fSuccess && file.open(QIODevice::WriteOnly))158 {159 /* Write buffer into the file: */160 file.write(m_receivedData); 161 file.close();162 fSuccess = true;163 } 164 /* If the file already exists or was just written: */165 if (f Success)166 { 167 /* Warn the user about additions-image loaded and saved, propose to mount it: */166 /* Make sure target file doesn't exist: */ 167 bool fTargetFileExists = QFile::exists(target()); 168 if (fTargetFileExists) 169 { 170 /* We should ask user about file rewriting (or exit otherwise): */ 171 if (!msgCenter().confirmOverridingFile(QDir::toNativeSeparators(target()))) 172 break; 173 /* And remove file if rewriting confirmed: */ 174 if (QFile::remove(target())) 175 fTargetFileExists = false; 176 } 177 178 /* Try to rename temporary file to target one (would fail if target file still exists): */ 179 const bool fFileRenamed = !fTargetFileExists && QFile::rename(strTempFilename, target()); 180 181 /* If file renamed: */ 182 if (fFileRenamed) 183 { 184 /* Warn the user about additions-image downloaded and saved, propose to mount it (and/or exit in any case): */ 168 185 if (msgCenter().proposeMountGuestAdditions(source().toString(), QDir::toNativeSeparators(target()))) 169 186 emit sigDownloadFinished(target()); 170 187 break; 171 188 } 172 173 /* Warn the user about additions-image was downloaded but was NOT saved: */174 msgCenter().cannotSaveGuestAdditions(source().toString(), QDir::toNativeSeparators(target()));175 176 /* Ask the user for another location for the additions-image file: */177 QString strTarget = QIFileDialog::getExistingDirectory(QFileInfo(target()).absolutePath(),178 windowManager().networkManagerOrMainWindowShown(),179 tr("Select folder to save Guest Additions image to"), true);180 181 /* Check if user had really set a new target: */182 if (!strTarget.isNull())183 setTarget(QDir(strTarget).absoluteFilePath(QFileInfo(target()).fileName()));184 189 else 185 break; 186 } 187 } 188 190 { 191 /* Warn the user about additions-image was downloaded but was NOT saved: */ 192 msgCenter().cannotSaveGuestAdditions(source().toString(), QDir::toNativeSeparators(target())); 193 /* Ask the user for another location for the additions-image file: */ 194 const QString strTarget = QIFileDialog::getExistingDirectory(QFileInfo(target()).absolutePath(), 195 windowManager().networkManagerOrMainWindowShown(), 196 tr("Select folder to save Guest Additions image to"), true); 197 198 /* Check if user had really set a new target (and exit in opposite case): */ 199 if (!strTarget.isNull()) 200 setTarget(QDir(strTarget).absoluteFilePath(QFileInfo(target()).fileName())); 201 else 202 break; 203 } 204 } 205 }
Note:
See TracChangeset
for help on using the changeset viewer.