TrueReality  v0.1.1912
trVersion/Main.cpp
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
22 #include <iostream>
23 
24 #include <trVersion/Utils.h>
25 
27 #include <trUtil/DefaultSettings.h>
28 #include <trUtil/VersionUtil.h>
29 #include <trUtil/PathUtils.h>
30 #include <trUtil/Exception.h>
31 #include <trUtil/Logging/Log.h>
32 
33 const static trUtil::RefStr TR_CURRENT_VERSION("True Reality Engine Current version: ");
34 const static trUtil::RefStr TR_NEW_VERSION("\nTrue Reality Engine New Version : ");
35 const static trUtil::RefStr TR_VERSION("True Reality v");
36 
37 //Forward declaration
40 void SetVersion(trUtil::VersionUtil &ver, int maj, int min, std::string yymm, int build);
41 
45 int main(int argc, char** argv)
46 {
47 
48 
49  std::string logFileName;
50  std::string logLevel;
51  bool updateVer = false;
52  bool incVer = false;
53  int majVer = -1;
54  int minVer = -1;
55  std::string yymmVer = "";
56  int buildVer = -1;
57 
58  //Parse command line arguments
59  ParseCmdLineArgs(argc, argv, logFileName, logLevel, updateVer, incVer, majVer, minVer, yymmVer, buildVer);
60 
61  //Creates the default folders in the User Data folder.
63 
64  //Setup our Logging options
65  trUtil::DefaultSettings::SetupLoggingOptions(logFileName, logLevel);
66 
67  try
68  {
70  if (updateVer)
71  {
72  UpdateVersion(ver);
73  }
74  else if (incVer)
75  {
76  IncremenetVersion(ver);
77  }
78  else if (majVer != -1 && minVer != -1 && yymmVer != "" && buildVer != -1)
79  {
80  SetVersion(ver, majVer, minVer, yymmVer, buildVer);
81  }
82  else if (majVer != -1 || minVer != -1 || yymmVer != "" || buildVer != -1)
83  {
85  std::cerr << TR_CURRENT_VERSION << ver.GetVersionString() << std::endl;
86  if (majVer != -1)
87  {
88  ver.SetMajorVersion(majVer);
89  }
90 
91  if (minVer != -1)
92  {
93  ver.SetMinorVersion(minVer);
94  }
95 
96  if (yymmVer != "")
97  {
98  ver.SetYYMMVersion(yymmVer);
99  }
100 
101  if (buildVer != -1)
102  {
103  ver.SetBuildVersion(buildVer);
104  }
105 
106  ver.SaveVersionFile();
107 
108  std::cerr << TR_NEW_VERSION << ver.GetVersionString() << std::endl;
110  }
111  else
112  {
114  std::cerr << TR_VERSION << ver.GetVersionString() << std::endl;
116  }
117 
118  }
119  catch (const trUtil::Exception& ex)
120  {
121  LOG_E(EXE_NAME + " caught an unhandled exception:\n" + ex.ToString());
123  return -1;
124  }
125  return 0;
126 }
127 
134 {
136  std::cerr << TR_CURRENT_VERSION << ver.GetVersionString() << std::endl;
137 
138  ver.IncrementVersion();
139  ver.SaveVersionFile();
140 
141  std::cerr << TR_NEW_VERSION << ver.GetVersionString() << std::endl;
143 }
144 
148 void SetVersion(trUtil::VersionUtil &ver, int maj, int min, std::string yymm, int build)
149 {
151  std::cerr << TR_CURRENT_VERSION << ver.GetVersionString() << std::endl;
152 
153  ver.SetVersion(maj, min, yymm, build);
154  ver.SaveVersionFile();
155 
156  std::cerr << TR_NEW_VERSION << ver.GetVersionString() << std::endl;
158 }
159 
164 {
166  std::cerr << TR_CURRENT_VERSION << ver.GetVersionString() << std::endl;
168 
169  ver.UpdateVersion();
170  ver.SaveVersionFile();
171 
173  std::cerr << TR_NEW_VERSION << ver.GetVersionString() << std::endl;
175 }
void ParseCmdLineArgs(int &argc, char **argv, std::string &logFileName, std::string &logLevel, bool &updateVer, bool &incVer, int &majVer, int &minVer, std::string &yymmVer, int &buildVer)
Definition: Utils.cpp:37
std::string ToString() const
Converts this exception to a string.
Definition: Exception.cpp:52
void SetBuildVersion(int build)
Sets the Build part of the version string.
static const std::string EXE_NAME
Definition: Utils.h:26
void SetMinorVersion(int min)
Sets the Minor part of the version string.
This is the exception class used throughout the engine.
Definition: Exception.h:48
void IncrementVersion()
Increments the version number of the build by one and sets the YYMM to current date.
void UpdateVersion()
Updates the version file to the most recent HG/Git Revision and YTMM.
void SetVersion(int maj, int min, std::string yymm, int build)
Sets the version numbers.
Definition: VersionUtil.cpp:92
A string wrapper that will make sure that all of the strings with the same value will point to the sa...
Definition: RefStr.h:50
void SaveVersionFile()
Saves the version file currently in RAM to default location.
Definition: VersionUtil.cpp:86
static const trUtil::RefStr TR_NEW_VERSION("\rue Reality Engine New Version : ")
TR_UTIL_EXPORT void CreateUserDataPathTree()
Creates all the folders in the Data (TR_USER_DATA) folder, that includes Maps, GUI, Shaders, StaticMeshes, etc etc.
Definition: PathUtils.cpp:147
void LogException(trUtil::Logging::LogLevel level=trUtil::Logging::LogLevel::LOG_ERROR) const
Logs the exception to the default logger.
Definition: Exception.cpp:60
void SetMajorVersion(int maj)
Sets the Major part of the version string.
int main(int argc, char **argv)
Software&#39;s main function.
void TR_UTIL_EXPORT TextColor(TXT_COLOR TextColor)
Changes Text color in the console window....
Definition: TextColor.cpp:34
A utility to read and control the engines version numbers.
Definition: VersionUtil.h:45
#define LOG_E(msg)
Log an ERROR message.
Definition: Log.h:165
void SetYYMMVersion(std::string yymm)
Sets the Year/Month part of the version string.
void SetVersion(trUtil::VersionUtil &ver, int maj, int min, std::string yymm, int build)
Sets all the version numbers.
BRIGHT_YELLOW
Definition: TextColor.h:41
std::string GetVersionString()
Returns the full version string.
void UpdateVersion(trUtil::VersionUtil &ver)
Updates the version from the current .hg revision and YYMM.
DEFAULT
Definition: TextColor.h:41
LOG_ERROR
Definition: LogLevel.h:64
void IncremenetVersion(trUtil::VersionUtil &ver)
Increments the version in the version file.
void TR_UTIL_EXPORT SetupLoggingOptions(const std::string &logFileName, const std::string &logLevel)
Sets up all the default logging options for the software.
static const trUtil::RefStr TR_CURRENT_VERSION("True Reality Engine Current version: ")
static const trUtil::RefStr TR_VERSION("True Reality v")