1 /*
2  * DesktopRVersion.hpp
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 #ifndef DESKTOPRVERSION_HPP
16 #define DESKTOPRVERSION_HPP
17 
18 #include <iostream>
19 #include <fstream>
20 
21 #include <QtCore>
22 #include <QWidget>
23 
24 #include "desktop-config.h"
25 
26 namespace rstudio {
27 namespace desktop {
28 
29 enum Architecture
30 {
31    ArchNone = 1,
32    ArchX86 = 2,
33    ArchX64 = 4,
34    ArchUnknown = 0x100
35 };
36 typedef int Architectures;
37 
38 enum ValidateResult
39 {
40    ValidateSuccess = 1,
41    ValidateNotFound = 2,
42    ValidateBadArchitecture = 4,
43    ValidateVersionTooOld = 8
44 };
45 
46 class RVersion
47 {
48 public:
49    RVersion(QString binDir=QString());
50 
51    QString binDir() const;
52    QString homeDir() const;
53    QString description() const;
54    bool isEmpty() const;
55    bool isValid() const;
56    ValidateResult validate() const;
57    quint32 version() const;
58    Architecture architecture() const;
59    int compareTo(const RVersion& other) const;
60    bool operator<(const RVersion& other) const;
61    bool operator==(const RVersion& other) const;
62 
63 private:
64    void stat();
65 
66    QString binDir_;
67    QString homeDir_;
68    bool loaded_;
69    quint32 version_;
70    Architecture arch_;
71 };
72 
73 QString binDirToHomeDir(QString binDir);
74 
75 // Detect versions that might be implied by a user-specified dir.
76 // The versions that are returned might not be valid.
77 QList<RVersion> detectVersionsInDir(QString dir);
78 
79 // Enumerates all valid versions of R that are detected on the system.
80 // The versions parameter can be used to explicitly provide one or more
81 // R versions that may not be detected.
82 QList<RVersion> allRVersions(QList<RVersion> versions=QList<RVersion>());
83 
84 RVersion autoDetect(Architecture architecture, bool preferredOnly=false);
85 RVersion autoDetect();
86 
87 RVersion detectRVersion(bool forceUi,
88                         QWidget* parent = nullptr);
89 
90 } // namespace desktop
91 } // namespace rstudio
92 
93 #endif // DESKTOPRVERSION_HPP
94