1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "configutil.h" |
6 | #include "project/jsprojectgenerator.h" |
7 | |
8 | #include "services/option/optionmanager.h" |
9 | |
10 | namespace config { |
11 | |
12 | class ConfigUtilPrivate |
13 | { |
14 | friend class ConfigUtil; |
15 | ConfigureParam configureParam; |
16 | }; |
17 | |
18 | ConfigUtil::ConfigUtil(QObject *parent) |
19 | : QObject(parent) |
20 | , d(new ConfigUtilPrivate()) |
21 | { |
22 | |
23 | } |
24 | |
25 | ConfigUtil::~ConfigUtil() |
26 | { |
27 | if (d) { |
28 | delete d; |
29 | } |
30 | } |
31 | |
32 | ConfigUtil *ConfigUtil::instance() |
33 | { |
34 | static ConfigUtil ins; |
35 | return &ins; |
36 | } |
37 | |
38 | ConfigureParam *ConfigUtil::getConfigureParamPointer() |
39 | { |
40 | return &d->configureParam; |
41 | } |
42 | |
43 | bool ConfigUtil::getProjectInfo(const ConfigureParam *param, dpfservice::ProjectInfo &info) |
44 | { |
45 | QString sourceFolder = QFileInfo(param->projectPath).path(); |
46 | info.setLanguage(param->language); |
47 | info.setKitName(JSProjectGenerator::toolKitName()); |
48 | info.setWorkspaceFolder(sourceFolder); |
49 | |
50 | return true; |
51 | } |
52 | |
53 | QString ConfigUtil::getConfigPath(const QString &projectPath) |
54 | { |
55 | return CustomPaths::projectCachePath(projectPath) + QDir::separator() + "project.properties"; |
56 | } |
57 | |
58 | void ConfigUtil::readConfig(const QString &filePath, ConfigureParam ¶m) |
59 | { |
60 | param.clear(); |
61 | |
62 | QFile file(filePath); |
63 | if (file.open(QIODevice::ReadOnly)) { |
64 | QDataStream stream(&file); |
65 | stream >> param; |
66 | file.close(); |
67 | } |
68 | } |
69 | |
70 | void ConfigUtil::saveConfig(const QString &filePath, const ConfigureParam ¶m) |
71 | { |
72 | QFile file(filePath); |
73 | if (file.open(QIODevice::ReadWrite)) { |
74 | QDataStream stream(&file); |
75 | stream << param; |
76 | file.close(); |
77 | } |
78 | } |
79 | |
80 | void ConfigUtil::updateProjectInfo(dpfservice::ProjectInfo &info, const ConfigureParam *param) |
81 | { |
82 | if (!param) |
83 | return; |
84 | |
85 | info.setLanguage(param->language); |
86 | info.setKitName(JSProjectGenerator::toolKitName()); |
87 | info.setWorkspaceFolder(param->projectPath); |
88 | } |
89 | |
90 | } //namespace config |
91 |