Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-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 : #include "cloudconfiguration.h"
23 :
24 : #include <QRandomGenerator>
25 :
26 : #include "settings.h"
27 :
28 : using namespace muse;
29 : using namespace muse::cloud;
30 : using namespace muse::network;
31 :
32 : static const std::string module_name("cloud");
33 : static const Settings::Key CLIENT_ID_KEY(module_name, "cloud/clientId");
34 :
35 0 : static QByteArray generateClientId()
36 : {
37 0 : QByteArray qtGeneratedId(QSysInfo::machineUniqueId());
38 0 : if (!qtGeneratedId.isEmpty()) {
39 0 : return qtGeneratedId;
40 : }
41 :
42 0 : QRandomGenerator* generator = QRandomGenerator::global();
43 :
44 0 : long long randId = generator->generate();
45 0 : constexpr size_t randBytes = sizeof(decltype(generator->generate()));
46 :
47 0 : for (size_t bytes = randBytes; bytes < sizeof(randId); bytes += randBytes) {
48 0 : randId <<= 8 * randBytes;
49 0 : randId += generator->generate();
50 : }
51 :
52 0 : return QString::number(randId, 16).toLatin1();
53 0 : }
54 :
55 0 : CloudConfiguration::CloudConfiguration(const modularity::ContextPtr& iocCtx)
56 0 : : Contextable(iocCtx)
57 : {
58 0 : }
59 :
60 0 : void CloudConfiguration::init()
61 : {
62 0 : if (settings()->value(CLIENT_ID_KEY).isNull()) {
63 0 : settings()->setSharedValue(CLIENT_ID_KEY, Val(generateClientId().toStdString()));
64 : }
65 0 : }
66 :
67 0 : std::string CloudConfiguration::clientId() const
68 : {
69 0 : return settings()->value(CLIENT_ID_KEY).toString();
70 : }
71 :
72 0 : QByteArray CloudConfiguration::uploadingLicense() const
73 : {
74 0 : return "all-rights-reserved";
75 : }
76 :
77 0 : io::path_t CloudConfiguration::tokensFilePath(const std::string& cloudName) const
78 : {
79 0 : return globalConfiguration()->userAppDataPath() + "/" + cloudName + "_cred.dat";
80 : }
81 :
82 0 : RequestHeaders CloudConfiguration::headers() const
83 : {
84 0 : static const std::string CLOUD_USER_AGENT = "cloud";
85 0 : return networkConfiguration()->defaultHeaders(CLOUD_USER_AGENT);
86 : }
|