• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ossia / score / 35899133125

23 Sep 2026 05:57PM UTC coverage: 41.488% (+1.2%) from 40.337%
35899133125

push

github

jcelerier
3rdparty: follow the merged libossia

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWVTQ1pm3X2Uz7goFgULtC

123236 of 297041 relevant lines covered (41.49%)

113626.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.92
/src/lib/core/document/DocumentBackups.cpp
1
// This is an open source non-commercial project. Dear PVS-Studio, please check
2
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3
#include "DocumentBackups.hpp"
4

5
#include <score/tools/QMapHelper.hpp>
6
#include <score/widgets/MessageBox.hpp>
7

8
#include <core/application/OpenDocumentsFile.hpp>
9

10
#include <ossia/detail/algorithms.hpp>
11

12
#include <QApplication>
13
#include <QDateTime>
14
#include <QFile>
15
#include <QIcon>
16
#include <QMap>
17
#include <QMessageBox>
18
#include <QObject>
19
#include <QSettings>
20
#include <QString>
21
#include <QVariant>
22

23
bool score::DocumentBackups::canRestoreDocuments()
×
24
{
25
  // Try to reload if there was a crash
26
  if(OpenDocumentsFile::exists())
×
27
  {
28
    if(score::question(
×
29
           qApp->activeWindow(), QObject::tr("Reload?"),
×
30
           QObject::tr("It seems that score previously crashed. Do you "
×
31
                       "wish to reload your work?"))
32
       == QMessageBox::Yes)
×
33
    {
34
      return true;
×
35
    }
36
    else
37
    {
38
      DocumentBackups::clear();
×
39
      return false;
×
40
    }
41
  }
42

43
  return false;
×
44
}
×
45

46
static void loadRestorableDocumentData(
×
47
    const QString& data_filename, const QString& save_filename,
48
    const QString& command_filename, std::vector<score::RestorableDocument>& arr)
49
{
50
  QFile data_file{data_filename};
×
51
  QFile command_file{command_filename};
×
52
  if(data_file.exists() && command_file.exists())
×
53
  {
54
    data_file.open(QFile::ReadOnly);
×
55
    command_file.open(QFile::ReadOnly);
×
56

57
    auto it = ossia::find_if(arr, [&](score::RestorableDocument& elt) {
×
58
      return elt.filePath == save_filename;
×
59
    });
60
    if(it == arr.end())
×
61
    {
62
      arr.push_back(
×
63
          {save_filename, data_filename, command_filename, data_file.readAll(),
×
64
           command_file.readAll()});
×
65
    }
×
66
    else
67
    {
68
      // Compare dates
69
      auto old_time
70
          = QFile{it->commandsPath}.fileTime(QFileDevice::FileModificationTime);
×
71
      auto new_time = command_file.fileTime(QFileDevice::FileModificationTime);
×
72

73
      if(old_time < new_time)
×
74
      {
75
        it->docPath = data_filename;
×
76
        it->commandsPath = command_filename;
×
77
        it->doc = data_file.readAll();
×
78
        it->commandsPath = command_file.readAll();
×
79
      }
×
80
    }
×
81
  }
×
82
}
×
83

84
std::vector<score::RestorableDocument> score::DocumentBackups::restorableDocuments()
×
85
{
86
  std::vector<score::RestorableDocument> arr;
×
87

88
#if defined(__EMSCRIPTEN__)
89
  QSettings s;
90
  const auto existing = s.value("score-backup/docs").toMap();
91
  for(auto it = existing.cbegin(); it != existing.cend(); ++it)
92
  {
93
    const auto entry = it.value().toStringList();
94
    if(entry.size() != 2)
95
      continue;
96

97
    const auto doc = s.value(it.key()).toByteArray();
98
    const auto commands = s.value(entry[1]).toByteArray();
99
    if(doc.isEmpty())
100
      continue;
101

102
    arr.push_back({entry[0], it.key(), entry[1], doc, commands});
103
  }
104
#else
105
  QSettings s{score::OpenDocumentsFile::path(), QSettings::IniFormat};
×
106

107
  auto docs = s.value("score/docs");
×
108
  const auto existing_files = docs.toMap();
×
109

110
  for(const auto& file1 : QMap_keys(existing_files))
×
111
  {
112
    if(file1.isEmpty())
×
113
      continue;
×
114

115
    auto res = existing_files[file1].value<QPair<QString, QString>>();
×
116
    loadRestorableDocumentData(file1, res.first, res.second, arr);
×
117
  }
×
118
#endif
119
  return arr;
×
120
}
×
121

122
SCORE_LIB_BASE_EXPORT void score::DocumentBackups::clear()
62 ✔
123
{
124
#if defined(__EMSCRIPTEN__)
125
  QSettings s;
126
  const auto existing = s.value("score-backup/docs").toMap();
127
  for(auto it = existing.cbegin(); it != existing.cend(); ++it)
128
  {
129
    s.remove(it.key());
130
    if(const auto entry = it.value().toStringList(); entry.size() == 2)
131
      s.remove(entry[1]);
132
  }
133
  s.remove("score-backup/docs");
134
#else
135
  if(OpenDocumentsFile::exists())
62 ✔
136
  {
137
    // Remove all the tmp files
138
    {
139
      QSettings s{score::OpenDocumentsFile::path(), QSettings::IniFormat};
×
140

141
      const auto existing_files = s.value("score/docs").toMap();
×
142

143
      for(auto it = existing_files.cbegin(); it != existing_files.cend(); ++it)
×
144
      {
145
        QFile{it.key()}.remove();
×
146
        auto files = it.value().value<QPair<QString, QString>>();
×
147
        QFile{files.second}.remove();
×
148
      }
×
149
    }
×
150

151
    // Remove the file containing the map
152
    QFile{OpenDocumentsFile::path()}.remove();
×
153
  }
×
154
#endif
155
}
62 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc