Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #ifndef MU_ENGRAVING_ENGRAVINGERRORS_H
24 : #define MU_ENGRAVING_ENGRAVINGERRORS_H
25 :
26 : #include "io/path.h"
27 : #include "types/ret.h"
28 :
29 : #include "translation.h"
30 :
31 : namespace mu::engraving {
32 : enum class Err {
33 : Undefined = -1,
34 : NoError = 0,
35 : UnknownError = 2000,
36 :
37 : // file
38 : FileUnknownError = 2001,
39 : FileNotFound = 2002,
40 : FileOpenError = 2003,
41 : FileBadFormat = 2004,
42 : FileUnknownType = 2005,
43 : FileTooOld = 2006,
44 : FileTooNew = 2007,
45 : FileOld300Format = 2008,
46 : FileCorrupted = 2009,
47 : FileCriticallyCorrupted = 2010,
48 :
49 : UserAbort = 2011,
50 : IgnoreError = 2012
51 : };
52 :
53 0 : inline muse::Ret make_ret(Err err, const muse::String& text)
54 : {
55 0 : return muse::Ret(static_cast<int>(err), text.toStdString());
56 : }
57 :
58 7 : inline muse::Ret make_ret(Err err, const muse::io::path_t& filePath = {})
59 : {
60 7 : muse::String text;
61 :
62 7 : switch (err) {
63 0 : case Err::NoError:
64 0 : return muse::make_ok();
65 0 : case Err::FileUnknownError:
66 0 : text = muse::mtrc("engraving", "Unknown error");
67 0 : break;
68 1 : case Err::FileNotFound:
69 1 : text = muse::mtrc("engraving", "File “%1” not found").arg(filePath.toString());
70 1 : break;
71 0 : case Err::FileOpenError:
72 0 : text = muse::mtrc("engraving", "File open error");
73 0 : break;
74 0 : case Err::FileBadFormat:
75 0 : text = muse::mtrc("engraving", "Bad format");
76 0 : break;
77 0 : case Err::FileUnknownType:
78 0 : text = muse::mtrc("engraving", "Unknown filetype");
79 0 : break;
80 2 : case Err::FileTooOld:
81 2 : text = muse::mtrc("engraving", "This file was last saved in a version older than 2.0.0. "
82 : "You can convert this score by opening and then "
83 : "saving in MuseScore version 2.x. "
84 : "Visit the <a href=\"%1\">MuseScore download page</a> to obtain such a 2.x version.")
85 2 : .arg(u"https://musescore.org/download#older-versions");
86 2 : break;
87 2 : case Err::FileTooNew:
88 2 : text = muse::mtrc("engraving", "This file was saved using a newer version of MuseScore Studio. "
89 : "Please visit <a href=\"%1\">MuseScore.org</a> to obtain the latest version.")
90 2 : .arg(u"https://musescore.org");
91 2 : break;
92 0 : case Err::FileOld300Format:
93 0 : text = muse::mtrc("engraving", "This file was last saved in a development version of 3.0.");
94 0 : break;
95 1 : case Err::FileCorrupted:
96 1 : text = muse::mtrc("engraving", "File “%1” is corrupted.").arg(filePath.toString());
97 1 : break;
98 1 : case Err::FileCriticallyCorrupted:
99 1 : text = muse::mtrc("engraving", "File “%1” is critically corrupted and cannot be processed.").arg(filePath.toString());
100 1 : break;
101 0 : case Err::Undefined:
102 : case Err::UnknownError:
103 : case Err::IgnoreError:
104 : case Err::UserAbort:
105 0 : break;
106 : }
107 :
108 7 : return muse::Ret(static_cast<int>(err), text.toStdString());
109 7 : }
110 : }
111 :
112 : #endif // MU_ENGRAVING_ENGRAVINGERRORS_H
|