Open Source Snapmatic picture and Savegame viewer/editor for GTA V https://gta5view.syping.de/

SavegameCopy.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*****************************************************************************
  2. * gta5view Grand Theft Auto V Profile Viewer
  3. * Copyright (C) 2016-2017 Syping
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *****************************************************************************/
  18. #include "SidebarGenerator.h"
  19. #include "SavegameWidget.h"
  20. #include "StandardPaths.h"
  21. #include "SavegameCopy.h"
  22. #include "config.h"
  23. #include <QStringBuilder>
  24. #include <QMessageBox>
  25. #include <QFileDialog>
  26. #include <QSettings>
  27. SavegameCopy::SavegameCopy()
  28. {
  29. }
  30. void SavegameCopy::copySavegame(QWidget *parent, QString sgdPath)
  31. {
  32. QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR);
  33. settings.beginGroup("FileDialogs");
  34. bool dontUseNativeDialog = settings.value("DontUseNativeDialog", false).toBool();
  35. settings.beginGroup("SavegameCopy");
  36. fileDialogPreSave: //Work?
  37. QFileInfo sgdFileInfo(sgdPath);
  38. QFileDialog fileDialog(parent);
  39. fileDialog.setFileMode(QFileDialog::AnyFile);
  40. fileDialog.setViewMode(QFileDialog::Detail);
  41. fileDialog.setAcceptMode(QFileDialog::AcceptSave);
  42. fileDialog.setOption(QFileDialog::DontUseNativeDialog, dontUseNativeDialog);
  43. fileDialog.setOption(QFileDialog::DontConfirmOverwrite, true);
  44. fileDialog.setDefaultSuffix("");
  45. fileDialog.setWindowFlags(fileDialog.windowFlags()^Qt::WindowContextHelpButtonHint);
  46. fileDialog.setWindowTitle(SavegameWidget::tr(("Export Savegame...")));
  47. fileDialog.setLabelText(QFileDialog::Accept, SavegameWidget::tr("Export"));
  48. QStringList filters;
  49. filters << SavegameWidget::tr("Savegame files (SGTA*)");
  50. filters << SavegameWidget::tr("All files (**)");
  51. fileDialog.setNameFilters(filters);
  52. QList<QUrl> sidebarUrls = SidebarGenerator::generateSidebarUrls(fileDialog.sidebarUrls());
  53. fileDialog.setSidebarUrls(sidebarUrls);
  54. fileDialog.setDirectory(settings.value("Directory", StandardPaths::picturesLocation()).toString());
  55. fileDialog.restoreGeometry(settings.value(parent->objectName() % "+Geometry", "").toByteArray());
  56. fileDialog.selectFile(sgdFileInfo.fileName());
  57. if (fileDialog.exec())
  58. {
  59. QStringList selectedFiles = fileDialog.selectedFiles();
  60. if (selectedFiles.length() == 1)
  61. {
  62. QString selectedFile = selectedFiles.at(0);
  63. if (QFile::exists(selectedFile))
  64. {
  65. if (QMessageBox::Yes == QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Overwrite %1 with current Savegame?").arg("\""+selectedFile+"\""), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes))
  66. {
  67. if (!QFile::remove(selectedFile))
  68. {
  69. QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to overwrite %1 with current Savegame").arg("\""+selectedFile+"\""));
  70. goto fileDialogPreSave; //Work?
  71. }
  72. }
  73. else
  74. {
  75. goto fileDialogPreSave; //Work?
  76. }
  77. }
  78. bool isCopied = QFile::copy(sgdPath, selectedFile);
  79. if (!isCopied)
  80. {
  81. QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("Failed to export current Savegame"));
  82. goto fileDialogPreSave; //Work?
  83. }
  84. }
  85. else
  86. {
  87. QMessageBox::warning(parent, SavegameWidget::tr("Export Savegame"), SavegameWidget::tr("No valid file is selected"));
  88. goto fileDialogPreSave; //Work?
  89. }
  90. }
  91. settings.setValue(parent->objectName() % "+Geometry", fileDialog.saveGeometry());
  92. settings.setValue("Directory", fileDialog.directory().absolutePath());
  93. settings.endGroup();
  94. settings.endGroup();
  95. }