Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OTPaths.cpp
Go to the documentation of this file.
1 /************************************************************
2 *
3 * OTPaths.cpp
4 *
5 */
6 
7 /************************************************************
8  -----BEGIN PGP SIGNED MESSAGE-----
9  Hash: SHA1
10 
11  * OPEN TRANSACTIONS
12  *
13  * Financial Cryptography and Digital Cash
14  * Library, Protocol, API, Server, CLI, GUI
15  *
16  * -- Anonymous Numbered Accounts.
17  * -- Untraceable Digital Cash.
18  * -- Triple-Signed Receipts.
19  * -- Cheques, Vouchers, Transfers, Inboxes.
20  * -- Basket Currencies, Markets, Payment Plans.
21  * -- Signed, XML, Ricardian-style Contracts.
22  * -- Scripted smart contracts.
23  *
24  * Copyright (C) 2010-2013 by "Fellow Traveler" (A pseudonym)
25  *
26  * EMAIL:
28  *
29  * BITCOIN: 1NtTPVVjDsUfDWybS4BwvHpG2pdS9RnYyQ
30  *
31  * KEY FINGERPRINT (PGP Key in license file):
32  * 9DD5 90EB 9292 4B48 0484 7910 0308 00ED F951 BB8E
33  *
34  * OFFICIAL PROJECT WIKI(s):
35  * https://github.com/FellowTraveler/Moneychanger
36  * https://github.com/FellowTraveler/Open-Transactions/wiki
37  *
38  * WEBSITE:
39  * http://www.OpenTransactions.org/
40  *
41  * Components and licensing:
42  * -- Moneychanger..A Java client GUI.....LICENSE:.....GPLv3
43  * -- otlib.........A class library.......LICENSE:...LAGPLv3
44  * -- otapi.........A client API..........LICENSE:...LAGPLv3
45  * -- opentxs/ot....Command-line client...LICENSE:...LAGPLv3
46  * -- otserver......Server Application....LICENSE:....AGPLv3
47  * Github.com/FellowTraveler/Open-Transactions/wiki/Components
48  *
49  * All of the above OT components were designed and written by
50  * Fellow Traveler, with the exception of Moneychanger, which
51  * was contracted out to Vicky C ([email protected]).
52  * The open-source community has since actively contributed.
53  *
54  * -----------------------------------------------------
55  *
56  * LICENSE:
57  * This program is free software: you can redistribute it
58  * and/or modify it under the terms of the GNU Affero
59  * General Public License as published by the Free Software
60  * Foundation, either version 3 of the License, or (at your
61  * option) any later version.
62  *
63  * ADDITIONAL PERMISSION under the GNU Affero GPL version 3
64  * section 7: (This paragraph applies only to the LAGPLv3
65  * components listed above.) If you modify this Program, or
66  * any covered work, by linking or combining it with other
67  * code, such other code is not for that reason alone subject
68  * to any of the requirements of the GNU Affero GPL version 3.
69  * (==> This means if you are only using the OT API, then you
70  * don't have to open-source your code--only your changes to
71  * Open-Transactions itself must be open source. Similar to
72  * LGPLv3, except it applies to software-as-a-service, not
73  * just to distributing binaries.)
74  *
75  * Extra WAIVER for OpenSSL, Lucre, and all other libraries
76  * used by Open Transactions: This program is released under
77  * the AGPL with the additional exemption that compiling,
78  * linking, and/or using OpenSSL is allowed. The same is true
79  * for any other open source libraries included in this
80  * project: complete waiver from the AGPL is hereby granted to
81  * compile, link, and/or use them with Open-Transactions,
82  * according to their own terms, as long as the rest of the
83  * Open-Transactions terms remain respected, with regard to
84  * the Open-Transactions code itself.
85  *
86  * Lucre License:
87  * This code is also "dual-license", meaning that Ben Lau-
88  * rie's license must also be included and respected, since
89  * the code for Lucre is also included with Open Transactions.
90  * See Open-Transactions/src/otlib/lucre/LUCRE_LICENSE.txt
91  * The Laurie requirements are light, but if there is any
92  * problem with his license, simply remove the Lucre code.
93  * Although there are no other blind token algorithms in Open
94  * Transactions (yet. credlib is coming), the other functions
95  * will continue to operate.
96  * See Lucre on Github: https://github.com/benlaurie/lucre
97  * -----------------------------------------------------
98  * You should have received a copy of the GNU Affero General
99  * Public License along with this program. If not, see:
100  * http://www.gnu.org/licenses/
101  *
102  * If you would like to use this software outside of the free
103  * software license, please contact FellowTraveler.
104  * (Unfortunately many will run anonymously and untraceably,
105  * so who could really stop them?)
106  *
107  * DISCLAIMER:
108  * This program is distributed in the hope that it will be
109  * useful, but WITHOUT ANY WARRANTY; without even the implied
110  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
111  * PURPOSE. See the GNU Affero General Public License for
112  * more details.
113 
114  -----BEGIN PGP SIGNATURE-----
115  Version: GnuPG v1.4.9 (Darwin)
116 
117  iQIcBAEBAgAGBQJRSsfJAAoJEAMIAO35UbuOQT8P/RJbka8etf7wbxdHQNAY+2cC
118  vDf8J3X8VI+pwMqv6wgTVy17venMZJa4I4ikXD/MRyWV1XbTG0mBXk/7AZk7Rexk
119  KTvL/U1kWiez6+8XXLye+k2JNM6v7eej8xMrqEcO0ZArh/DsLoIn1y8p8qjBI7+m
120  aE7lhstDiD0z8mwRRLKFLN2IH5rAFaZZUvj5ERJaoYUKdn4c+RcQVei2YOl4T0FU
121  LWND3YLoH8naqJXkaOKEN4UfJINCwxhe5Ke9wyfLWLUO7NamRkWD2T7CJ0xocnD1
122  sjAzlVGNgaFDRflfIF4QhBx1Ddl6wwhJfw+d08bjqblSq8aXDkmFA7HeunSFKkdn
123  oIEOEgyj+veuOMRJC5pnBJ9vV+7qRdDKQWaCKotynt4sWJDGQ9kWGWm74SsNaduN
124  TPMyr9kNmGsfR69Q2Zq/FLcLX/j8ESxU+HYUB4vaARw2xEOu2xwDDv6jt0j3Vqsg
125  x7rWv4S/Eh18FDNDkVRChiNoOIilLYLL6c38uMf1pnItBuxP3uhgY6COm59kVaRh
126  nyGTYCDYD2TK+fI9o89F1297uDCwEJ62U0Q7iTDp5QuXCoxkPfv8/kX6lS6T3y9G
127  M9mqIoLbIQ1EDntFv7/t6fUTS2+46uCrdZWbQ5RjYXdrzjij02nDmJAm2BngnZvd
128  kamH0Y/n11lCvo1oQxM+
129  =uSzz
130  -----END PGP SIGNATURE-----
131  **************************************************************/
132 
133 #include "stdafx.hpp"
134 
135 #include "util/OTPaths.hpp"
136 #include "OTLog.hpp"
137 #ifdef _WIN32
139 #endif
140 #include "util/StringUtils.hpp"
141 
142 #include <cerrno>
143 #include <vector>
144 
145 #include <sys/stat.h>
146 
147 #ifdef _WIN32
148 #include <direct.h>
149 #include <shlobj.h>
150 #else
151 #include <libgen.h>
152 #include <unistd.h>
153 #endif
154 
155 #ifdef __APPLE__
156 #include "TargetConditionals.h"
157 #endif
158 
159 #ifdef TARGET_OS_MAC
160 #include <mach-o/dyld.h>
161 #include <limits.h>
162 #endif
163 
164 #ifndef S_ISDIR
165 #define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
166 #endif
167 
168 #ifndef S_ISREG
169 #define S_ISREG(mode) (((mode)&S_IFMT) == S_IFREG)
170 #endif
171 
172 #ifdef _WIN32
173 #define OT_APPDATA_DIR "OpenTransactions"
174 #elif TARGET_OS_IPHONE
175 #define OT_APPDATA_DIR "Documents"
176 #elif ANDROID
177 #define OT_APPDATA_DIR "ot"
178 #else
179 #define OT_APPDATA_DIR ".ot"
180 #endif
181 
182 #ifndef OT_PREFIX_PATH
183 #ifdef _WIN32
184 #define OT_PREFIX_PATH \
185  OTPaths::AppDataFolder() // windows, set to OT AppData Folder.
186 #elif TARGET_OS_IPHONE
187 #define OT_PREFIX_PATH \
188  OTPaths::AppDataFolder() // iphone, set to OT AppData Folder.
189 #elif ANDROID
190 #define OT_PREFIX_PATH \
191  "res/raw" // android, set to res/raw folder for static files in android app
192 // sandbox.
193 #else
194 #define OT_PREFIX_PATH "/usr/local" // default prefix_path unix
195 #endif
196 #endif
197 
198 #define OT_INIT_CONFIG_FILENAME "ot_init.cfg"
199 #define OT_CONFIG_ISRELATIVE "_is_relative"
200 
201 #ifdef _WIN32
202 #define OT_SCRIPTS_DIR "scripts/ot"
203 #elif defined(ANDROID)
204 #define OT_SCRIPTS_DIR ""
205 #else
206 #define OT_SCRIPTS_DIR "lib/opentxs"
207 #endif
208 
209 namespace opentxs
210 {
211 
212 #ifdef ANDROID
213 OTSettings OTPaths::s_settings;
214 #else
215 OTSettings OTPaths::s_settings(GlobalConfigFile()); // NOTE: This is BAD to call
216  // this here. da2ce7 ??
217 #endif
218 
219 OTString OTPaths::s_strAppBinaryFolder("");
220 OTString OTPaths::s_strHomeFolder("");
221 OTString OTPaths::s_strAppDataFolder("");
222 OTString OTPaths::s_strGlobalConfigFile("");
223 OTString OTPaths::s_strPrefixFolder("");
224 OTString OTPaths::s_strScriptsFolder("");
225 
227 {
228 }
229 
231 {
232  return OTPaths::s_strAppBinaryFolder;
233 }
234 
236 {
237  OTPaths::s_strAppBinaryFolder = strLocation;
238 }
239 
241 {
242  return OTPaths::s_strHomeFolder;
243 }
244 
246 {
247  OTPaths::s_strHomeFolder = strLocation;
248 
249 #ifdef ANDROID
250  OTPaths::s_settings.SetConfigFilePath(GlobalConfigFile());
251 #endif
252 }
253 
255 {
256  if (s_strAppDataFolder.Exists())
257  return s_strAppDataFolder; // already got it, just return it.
258 
259  OTString strHomeDataFolder(OTPaths::HomeFolder()),
260  strAppDataFolder(""); // eg. /home/user/ (the folder that the OT
261  // appdata folder will be in.)
262 
263  if (!strHomeDataFolder.Exists() && !GetHomeFromSystem(strHomeDataFolder)) {
264  OT_FAIL;
265  }
266 
267  // now lets change all the '\' into '/'
268  // then check that the path /home/user indeed exists, and is a folder.
269 
270  FixPath(strHomeDataFolder, strHomeDataFolder, true);
271  if (!PathExists(strHomeDataFolder)) OT_FAIL;
272 
273  // ok, we have the HomeData Folder, lets append our OT folder to it.
274 
275  if (!AppendFolder(strAppDataFolder, strHomeDataFolder, OT_APPDATA_DIR))
276  OT_FAIL;
277 
278  bool bFolderCreated;
279  if (!BuildFolderPath(strAppDataFolder, bFolderCreated)) OT_FAIL;
280 
281  s_strAppDataFolder = strAppDataFolder; // all good lets set it.
282 
283  return s_strAppDataFolder;
284 }
285 
287 {
288  if (s_strGlobalConfigFile.Exists())
289  return s_strGlobalConfigFile; // got it, lets return it.
290 
291  OTString strGlobalConfigFile("");
292 
293  if (!AppendFile(strGlobalConfigFile, AppDataFolder(),
295  OT_FAIL;
296 
297  s_strGlobalConfigFile = strGlobalConfigFile;
298 
299  return s_strGlobalConfigFile;
300 }
301 
303 {
304  if (s_strPrefixFolder.Exists())
305  return s_strPrefixFolder; // got it, lets return it.
306 
307  // lets load from the statndard config, or create the entry.
308  if (LoadSetPrefixFolder())
309  return s_strPrefixFolder;
310  else {
311  OT_FAIL;
312  }
313 }
314 
316 {
317  if (s_strScriptsFolder.Exists())
318  return s_strScriptsFolder; // got it, lets return it.
319 
320  // load it from config (if we already have it set in the config).
321  if (LoadSetScriptsFolder())
322  return s_strScriptsFolder;
323  else {
324  OT_FAIL;
325  }
326 }
327 
328 // The LoadSet Functions will update the static values.
329 // static
330 bool OTPaths::LoadSetPrefixFolder // eg. /usr/local/
331  (OTSettings& config, // optional
332  const OTString& strPrefixFolder // optional
333  // const bool& bIsRelative (cannot be relative);
334  )
335 {
336  /*
337  The prefix path is special.
338 
339  This path is tested if it is different to the
340  one that would be automatically selected by this program
341  (aka either compiled into, or from the registry, or the default user data
342  directory).
343 
344  If the set path is different to what would be supplied and the override path
345  value is set.
346  Then we will use that path.
347 
348  Otherwise, we will update the path in the configuration to link against the
349  updated path.
350 
351  Users will need to set the override path flag in the configuration,
352  if they want to manually set the prefix path.
353  */
354 
355  const bool bPreLoaded(config.IsLoaded());
356 
357  if (!bPreLoaded) {
358  config.Reset();
359  if (!config.Load()) {
360  OT_FAIL;
361  }
362  }
363 
364  {
365  // get default path
366  OTString strDefaultPrefixPath(OT_PREFIX_PATH);
367  {
368  if (!strDefaultPrefixPath.Exists()) {
369  otErr << __FUNCTION__ << ": Error: OT_PREFIX_PATH is not set!";
370  OT_FAIL;
371  }
372 
373 #ifdef _WIN32
374  OTString strTemp;
375  if (OTPaths::Win_GetInstallFolderFromRegistry(strTemp)) {
376  strDefaultPrefixPath = strTemp;
377  }
378 #endif
379 
380  if (!ToReal(strDefaultPrefixPath, strDefaultPrefixPath)) {
381  OT_FAIL;
382  }
383  if (!FixPath(strDefaultPrefixPath, strDefaultPrefixPath, true)) {
384  OT_FAIL;
385  }
386  }
387 
388  OTString strLocalPrefixPath = "";
389  bool bPrefixPathOverride = false;
390 
391  {
392  // now check the configuration to see what values we have:
393  OTString strConfigPath = "";
394 
395  bool bIsNew = false;
396  OTString strPrefixPathOverride("prefix_path_override");
397 
398  if (!config.CheckSet_str("paths", "prefix_path",
399  strDefaultPrefixPath, strConfigPath,
400  bIsNew)) {
401  return false;
402  }
403  if (!config.CheckSet_bool(
404  "paths", strPrefixPathOverride, false, bPrefixPathOverride,
405  bIsNew, "; This will force the prefix not to change")) {
406  return false;
407  }
408 
409  // if the config dosn't have a prefix path set. Lets set the
410  // default.
411  // if a prefix path was passed in, we will override with that later.
412  if (!strConfigPath.Exists() || (3 > strConfigPath.GetLength())) {
413  otErr << __FUNCTION__ << ": Error: Bad "
414  << "prefix_path"
415  << " in config, will reset!";
416 
417  strConfigPath = strDefaultPrefixPath; // set
418  bPrefixPathOverride = false;
419 
420  // lets set the default path, and reset override
421  bool bNewOrUpdate = false;
422  if (!config.Set_str("paths", "prefix_path",
423  strDefaultPrefixPath, bNewOrUpdate)) {
424  return false;
425  }
426  if (!config.Set_bool("paths", strPrefixPathOverride, false,
427  bNewOrUpdate)) {
428  return false;
429  }
430  }
431 
432  strLocalPrefixPath = strConfigPath;
433  }
434 
435  {
436  if (!bPrefixPathOverride) {
437  bool bUpdate = false;
438 
439  // default
440  if (!strLocalPrefixPath.Compare(strDefaultPrefixPath)) {
441  strLocalPrefixPath = strDefaultPrefixPath;
442  bUpdate = true;
443  }
444 
445  // passed in
446  if (strPrefixFolder.Exists() &&
447  (3 < strPrefixFolder.GetLength())) {
448  // a prefix folder was passed in... lets use it, and update
449  // the config if the override isn't set
450  OTString strTmp = strPrefixFolder;
451 
452  if (!ToReal(strTmp, strTmp)) {
453  OT_FAIL;
454  }
455 
456  if (!FixPath(strTmp, strTmp, true)) {
457  OT_FAIL;
458  }
459 
460  if (!strLocalPrefixPath.Compare(strTmp)) {
461  strLocalPrefixPath = strTmp;
462  bUpdate = true;
463  }
464  }
465 
466  // we need to update the path in the config
467  if (bUpdate) {
468  bool bNewOrUpdate = false;
469  if (!config.Set_str("paths", "prefix_path",
470  strLocalPrefixPath, bNewOrUpdate)) {
471  return false;
472  }
473  }
474  }
475  }
476 
477  {
478  if (!strLocalPrefixPath.Exists()) {
479  OT_FAIL;
480  }
481 
482  if (!ToReal(strLocalPrefixPath, strLocalPrefixPath)) {
483  OT_FAIL;
484  }
485  if (!FixPath(strLocalPrefixPath, strLocalPrefixPath, true)) {
486  OT_FAIL;
487  }
488  s_strPrefixFolder = strLocalPrefixPath;
489  }
490  }
491 
492  if (!bPreLoaded) {
493  if (!config.Save()) {
494  OT_FAIL;
495  }
496  config.Reset();
497  }
498  return true;
499 }
500 
501 // static
502 bool OTPaths::LoadSetScriptsFolder // ie. PrefixFolder() + [ if (NOT Android)
503  // "lib/opentxs/" ]
504  (OTSettings& config, // optional
505  const OTString& strScriptsFolder, // optional
506  const bool& bIsRelative // optional
507  )
508 {
509  const bool bPreLoaded(config.IsLoaded());
510 
511  if (!bPreLoaded) {
512  config.Reset();
513  if (!config.Load()) {
514  OT_FAIL;
515  }
516  }
517 
518  OTString strRelativeKey = "";
519  strRelativeKey.Format("%s%s", "scripts", OT_CONFIG_ISRELATIVE);
520 
521  // local vairables.
522  bool bConfigIsRelative = false;
523  OTString strConfigFolder = "";
524 
525  // lets first check what we have in the configuration:
526  {
527  bool bKeyIsNew = false;
528 
529  if (!config.CheckSet_bool("paths", strRelativeKey, true,
530  bConfigIsRelative, bKeyIsNew)) {
531  return false;
532  }
533  if (!config.CheckSet_str("paths", "scripts", OT_SCRIPTS_DIR,
534  strConfigFolder, bKeyIsNew)) {
535  return false;
536  }
537  }
538 
539  // lets first test if there was a folder passed in
540 
541  if ((strScriptsFolder.Exists()) && (3 < strScriptsFolder.GetLength())) {
542 
543  // we have a folder passed in, lets now check if we need to update
544  // anything:
545 
546  if (bConfigIsRelative != bIsRelative) {
547 
548  bConfigIsRelative = bIsRelative;
549  bool bNewOrUpdated = false;
550 
551  if (!config.Set_bool("paths", strRelativeKey, bConfigIsRelative,
552  bNewOrUpdated)) {
553  return false;
554  }
555  }
556 
557  if (!strConfigFolder.Compare(strScriptsFolder)) {
558 
559  strConfigFolder = strScriptsFolder; // update folder
560  bool bNewOrUpdated = false;
561 
562  if (!config.Set_str("paths", "scripts", strConfigFolder,
563  bNewOrUpdated)) {
564  return false;
565  }
566  }
567  }
568 
569  if (bConfigIsRelative) {
570  if (!FixPath(strConfigFolder, strConfigFolder, true)) {
571  OT_FAIL;
572  }
573 
574  OTString strPrefixScriptPath = "";
575  AppendFolder(strPrefixScriptPath, PrefixFolder(), strConfigFolder);
576 
577  OTString strAppBinaryScriptPath = "";
578 
579  // if the AppBinaryFolder is set, we will attempt to use this script
580  // path instead.
581  // however if the directory dosn't exist, we will default back to
582  // appending to the prefix.
583 
584  // TODO: Make the prefix path set to AppBinaryFolder. (da2ce7)
585 
586  if (AppBinaryFolder().Exists()) {
587  AppendFolder(strAppBinaryScriptPath, AppBinaryFolder(),
588  strConfigFolder);
589  if (!OTPaths::FolderExists(strAppBinaryScriptPath)) {
590  otOut << __FUNCTION__
591  << ": Warning: Cannot Find: " << strAppBinaryScriptPath
592  << ", using default!";
593  strAppBinaryScriptPath = ""; // don't have anything here.
594  }
595  }
596 
597  s_strScriptsFolder = strAppBinaryScriptPath.Exists()
598  ? strAppBinaryScriptPath
599  : strPrefixScriptPath;
600 
601  if (!s_strScriptsFolder.Exists()) OT_FAIL;
602 
603  }
604  else {
605  if (!ToReal(strConfigFolder, strConfigFolder)) {
606  OT_FAIL;
607  }
608 
609  if (!FixPath(strConfigFolder, strConfigFolder, true)) {
610  OT_FAIL;
611  }
612  s_strScriptsFolder = strConfigFolder; // set
613  }
614 
615  if (!bPreLoaded) {
616  if (!config.Save()) {
617  OT_FAIL;
618  }
619  config.Reset();
620  }
621  return true; // success
622 }
623 
624 // static
625 bool OTPaths::Get(OTSettings& config, const OTString& strSection,
626  const OTString& strKey, OTString& out_strVar,
627  bool& out_bIsRelative, bool& out_bKeyExist)
628 {
629  if (!strSection.Exists()) {
630  otErr << __FUNCTION__ << ": Null: "
631  << "strSection"
632  << " passed in!\n";
633  OT_FAIL;
634  }
635  if (!strKey.Exists()) {
636  otErr << __FUNCTION__ << ": Null: "
637  << "strKey"
638  << " passed in!\n";
639  OT_FAIL;
640  }
641 
642  out_strVar = "";
643  out_bIsRelative = false;
644  out_bKeyExist = false;
645 
646  const bool bPreLoaded(config.IsLoaded());
647 
648  if (!bPreLoaded) {
649  config.Reset();
650  if (!config.Load()) {
651  OT_FAIL;
652  }
653  }
654 
655  bool bBoolExists(false), bIsRelative(false);
656  OTString strRelativeKey(""), strOutFolder("");
657 
658  strRelativeKey.Format("%s%s", strKey.Get(), OT_CONFIG_ISRELATIVE);
659 
660  if (config.Check_bool(strSection, strRelativeKey, bIsRelative,
661  bBoolExists)) {
662  bool bStringExists = false;
663  if (config.Check_str(strSection, strKey, strOutFolder, bStringExists)) {
664  if (bBoolExists && bStringExists) {
665  if (!bIsRelative) // lets fix the path, so it dosn't matter how
666  // people write it in the config.
667  {
668  if (!ToReal(strOutFolder, strOutFolder)) {
669  OT_FAIL;
670  }
671 
672  if (!FixPath(strOutFolder, strOutFolder, true)) {
673  OT_FAIL;
674  }
675  }
676 
677  out_strVar = strOutFolder;
678  out_bIsRelative = bIsRelative;
679  out_bKeyExist = true;
680  }
681  else {
682  out_strVar = "";
683  out_bIsRelative = false;
684  out_bKeyExist = false;
685  }
686 
687  if (!bPreLoaded) {
688  config.Reset();
689  }
690 
691  return true;
692  }
693  }
694  // if we get here, there has been a error!
695  OT_FAIL;
696 }
697 
698 // static
699 bool OTPaths::Set(OTSettings& config, const OTString& strSection,
700  const OTString& strKey, const OTString& strValue,
701  const bool& bIsRelative, bool& out_bIsNewOrUpdated,
702  const OTString& strComment)
703 {
704  if (!strSection.Exists()) {
705  otErr << __FUNCTION__ << ": Null: "
706  << "strSection"
707  << " passed in!\n";
708  OT_FAIL;
709  }
710  if (!strKey.Exists()) {
711  otErr << __FUNCTION__ << ": Null: "
712  << "strKey"
713  << " passed in!\n";
714  OT_FAIL;
715  }
716 
717  out_bIsNewOrUpdated = false;
718 
719  const bool bPreLoaded(config.IsLoaded());
720 
721  if (!bPreLoaded) // we only need to load, if not already loaded.
722  {
723  config.Reset();
724  if (!config.Load()) {
725  OT_FAIL;
726  }
727  }
728 
729  bool bBoolIsNew(false);
730  OTString strRelativeKey("");
731 
732  strRelativeKey.Format("%s%s", strKey.Get(), OT_CONFIG_ISRELATIVE);
733 
734  if (config.Set_bool(strSection, strRelativeKey, bIsRelative, bBoolIsNew,
735  strComment)) {
736  bool bStringIsNew = false;
737  if (config.Set_str(strSection, strKey, strValue, bStringIsNew)) {
738  if (bBoolIsNew && bStringIsNew) // using existing key
739  {
740  out_bIsNewOrUpdated = true;
741  }
742 
743  if (!bPreLoaded) {
744  if (!config.Save()) {
745  OT_FAIL;
746  }
747  config.Reset();
748  }
749 
750  return true;
751  }
752  }
753 
754  // if we get here, there has been a error!
755  OT_FAIL;
756 }
757 
758 // static
759 bool OTPaths::FixPath(const OTString& strPath, OTString& out_strFixedPath,
760  const bool& bIsFolder)
761 {
762  if (!strPath.Exists()) {
763  otErr << __FUNCTION__ << ": Null: "
764  << "strPath"
765  << " passed in!\n";
766  OT_FAIL;
767  }
768 
769  std::string l_strPath(strPath.Get());
770  // first change all back-slashes to forward slashes:
771  std::string l_strPath_noBackslash(
772  OTString::replace_chars(l_strPath, "\\", '/'));
773 
774  // now we make sure we have the correct trailing "/".
775 
776  if ('/' == *l_strPath_noBackslash.rbegin()) {
777  if (bIsFolder) {
778  out_strFixedPath.Set(l_strPath_noBackslash.c_str());
779  return true;
780  }
781  else {
782  out_strFixedPath.Set(
783  l_strPath_noBackslash.substr(0, l_strPath_noBackslash.size() -
784  1).c_str());
785  return true;
786  }
787  }
788  else {
789  if (bIsFolder) {
790  l_strPath_noBackslash += "/";
791  out_strFixedPath.Set(l_strPath_noBackslash.c_str());
792  return true;
793  }
794  else {
795  out_strFixedPath.Set(l_strPath_noBackslash.c_str());
796  return true;
797  }
798  }
799 }
800 
801 // static
802 bool OTPaths::PathExists(const OTString& strPath)
803 {
804  if (!strPath.Exists()) {
805  otErr << __FUNCTION__ << ": Null: "
806  << "strPath"
807  << " passed in!\n";
808  OT_FAIL;
809  }
810 
811  // remove trailing backslash for stat
812  std::string l_strPath(strPath.Get());
813  l_strPath = (OTString::replace_chars(l_strPath, "\\", '/')); // all \ to /
814 
815  // std::string l_strPath_stat = l_strPath;
816  std::string l_strPath_stat("");
817 
818  // remove last / if it exists (for l_strPath_stat)
819  if ('/' == *l_strPath.rbegin())
820  l_strPath_stat = l_strPath.substr(0, l_strPath.size() - 1);
821  else
822  l_strPath_stat = l_strPath;
823 
824  struct stat st;
825  memset(&st, 0, sizeof(st));
826 
827  if (0 ==
828  stat(l_strPath_stat.c_str(), &st)) // good we have at-least on a node
829  {
830  if ('/' != *l_strPath.rbegin()) {
831  int64_t temp_l = 0;
832  return FileExists(strPath, temp_l);
833  }
834  else {
835  return FolderExists(strPath);
836  }
837  }
838  return false;
839 }
840 
841 // static
842 bool OTPaths::FileExists(const OTString& strFilePath, int64_t& nFileLength)
843 {
844  if (!strFilePath.Exists()) {
845  otErr << __FUNCTION__ << ": Null: "
846  << "strFilePath"
847  << " passed in!\n";
848  OT_FAIL;
849  }
850 
851  // remove trailing backslash for stat
852  std::string l_strPath(strFilePath.Get());
853  l_strPath = (OTString::replace_chars(l_strPath, "\\", '/')); // all \ to /
854 
855  if ('/' != *l_strPath.rbegin()) {
856 #ifdef _WIN32
857  std::string l_strPath_stat = l_strPath;
858  struct _stat st_buf;
859  memset(&st_buf, 0, sizeof(st_buf));
860  char filename[4086]; // not sure about this buffer,
861  // on windows paths cannot be longer than 4086,
862  // so it should be fine... needs more research.
863  strcpy_s(filename, l_strPath_stat.c_str());
864  _stat(filename, &st_buf);
865 #else
866  struct stat st_buf;
867  memset(&st_buf, 0, sizeof(st_buf));
868  stat(l_strPath.c_str(), &st_buf);
869 #endif
870 
871  // check for file
872  if (S_ISREG(st_buf.st_mode)) {
873  // good we have a file.
874  size_t lFileLength = st_buf.st_size;
875  nFileLength = static_cast<int64_t>(lFileLength);
876  return true;
877  }
878  }
879  return false;
880 }
881 
882 // static
883 bool OTPaths::FolderExists(const OTString& strFolderPath)
884 {
885  if (!strFolderPath.Exists()) {
886  otErr << __FUNCTION__ << ": Null: "
887  << "strFolderPath"
888  << " passed in!\n";
889  OT_FAIL;
890  }
891 
892  // remove trailing backslash for stat
893  std::string l_strPath(strFolderPath.Get());
894  l_strPath = (OTString::replace_chars(l_strPath, "\\", '/')); // all \ to /
895 
896  if ('/' == *l_strPath.rbegin()) {
897 #ifdef _WIN32
898  std::string l_strPath_stat = l_strPath.substr(0, l_strPath.size() - 1);
899  struct _stat st_buf;
900  memset(&st_buf, 0, sizeof(st_buf));
901  char filename[4086] = ""; // not sure about this buffer,
902  // on windows paths cannot be longer than 4086,
903  // so it should be fine... needs more research.
904  strcpy_s(filename, l_strPath_stat.c_str());
905  _stat(filename, &st_buf);
906 #else
907  struct stat st_buf;
908  memset(&st_buf, 0, sizeof(st_buf));
909  stat(l_strPath.c_str(), &st_buf);
910 #endif
911 
912  if (S_ISDIR(st_buf.st_mode)) {
913  // good we have a directory.
914  return true;
915  }
916  }
917  return false;
918 }
919 
920 // static
921 bool OTPaths::ConfirmCreateFolder(const OTString& strExactPath,
922  bool& out_Exists, bool& out_IsNew)
923 {
924  const bool bExists = (strExactPath.Exists() && !strExactPath.Compare(""));
926  bExists,
927  "OTPaths::ConfirmCreateFolder: Assert failed: no strFolderName\n");
928 
929  std::string l_strExactPath(strExactPath.Get());
930 
931  if ('/' != *l_strExactPath.rbegin()) return false; // not a directory.
932 
933  // Confirm If Directory Exists Already
934  out_Exists = PathExists(strExactPath);
935 
936  if (out_Exists) {
937  out_IsNew = false;
938  return true; // Already Have Folder, lets return true!
939  }
940  else {
941 // It dosn't exist: lets create it.
942 
943 #ifdef _WIN32
944  bool bCreateDirSuccess = (_mkdir(strExactPath.Get()) == 0);
945 #else
946  bool bCreateDirSuccess = (mkdir(strExactPath.Get(), 0700) == 0);
947 #endif
948 
949  if (!bCreateDirSuccess) {
950  otErr << "OTPaths::" << __FUNCTION__ << ": Unable To Confirm "
951  "Created Directory "
952  << strExactPath << ".\n";
953  out_IsNew = false;
954  out_Exists = false;
955  return false;
956  }
957 
958  // At this point if the folder still doesn't exist, nothing we can do.
959  // We
960  // already tried to create the folder, and SUCCEEDED, and then STILL
961  // failed
962  // to find it (if this is still false.)
963  else {
964  bool bCheckDirExist = PathExists(strExactPath);
965 
966  if (!bCheckDirExist) {
967  otErr << "OTPaths::" << __FUNCTION__
968  << ": "
969  "Unable To Confirm Created Directory " << strExactPath
970  << ".\n";
971  out_IsNew = false;
972  out_Exists = false;
973  return false;
974  }
975  else {
976  out_IsNew = true;
977  out_Exists = false;
978  return true; // We have created and checked the Folder
979  }
980  }
981  }
982 }
983 
984 // static
985 bool OTPaths::ToReal(const OTString& strExactPath,
986  OTString& out_strCanonicalPath)
987 {
988  if (!strExactPath.Exists()) {
989  otErr << __FUNCTION__ << ": Null: "
990  << "strExactPath"
991  << " passed in!\n";
992  OT_FAIL;
993  }
994 
995 #ifdef _WIN32
996 #ifdef _UNICODE
997 
998  const char* szPath = strExactPath.Get();
999  size_t newsize = strlen(szPath) + 1;
1000  wchar_t* wzPath = new wchar_t[newsize];
1001 
1002  size_t convertedChars = 0;
1003  mbstowcs_s(&convertedChars, wzPath, newsize, szPath, 4096);
1004 
1005  wchar_t szBuf[4096] = L"";
1006 
1007  if (GetFullPathName(wzPath, 4096, szBuf, nullptr)) {
1008  out_strCanonicalPath.Set(utf8util::UTF8FromUTF16(szBuf));
1009  return true;
1010  }
1011  else {
1012  out_strCanonicalPath.Set("");
1013  return false;
1014  }
1015 
1016 #else
1017  char_t szBuf[4096] = "";
1018  char_t const* szPath = strRealPath.Get();
1019 
1020  if (GetFullPathName(szPath, 4096, szBuf, nullptr)) {
1021  out_strCanonicalPath.Set(szBuf);
1022  return true;
1023  }
1024  else {
1025  out_strCanonicalPath.Set("");
1026  return false;
1027  }
1028 
1029 #endif
1030 #else
1031 
1032  char* actualpath = realpath(strExactPath.Get(), NULL);
1033  if (actualpath == NULL) {
1034 
1035  if (errno == ENOTDIR) {
1036  otWarn << "Input value to RealPath is not a directory: (Realpath: "
1037  "skipping)\n";
1038  out_strCanonicalPath.Set(strExactPath);
1039  return true;
1040  }
1041 
1042  if (errno == ENOENT) {
1043  otWarn << "File doesn't exist: (Realpath: skipping)\n";
1044  out_strCanonicalPath.Set(strExactPath);
1045  return true;
1046  }
1047 
1048  OT_ASSERT_MSG((errno != EACCES), "Error (Realpath: EACCES): Unable to "
1049  "build RealPath: access denied");
1050  OT_ASSERT_MSG(
1051  (errno != EINVAL),
1052  "Error (RealPath: EINVAL): Input value into RealPath was nullptr");
1053  OT_ASSERT_MSG(
1054  (errno != ELOOP),
1055  "Error (RealPath: ELOOP): Resloving links resulted in a loop.");
1056  OT_ASSERT_MSG((errno != ENAMETOOLONG),
1057  "Error (RealPath: ENAMETOOLONG): Name too int64_t.");
1058  OT_ASSERT_MSG((errno != ERANGE), "Error (RealPath: ERANGE): Resulting "
1059  "path is too int64_t for the buffer");
1060  OT_ASSERT_MSG((errno != EIO),
1061  "Error (RealPath: EIO): Unable to access path.");
1062 
1063  OT_ASSERT_MSG(
1064  (false),
1065  "Error (RealPath: OTHER): Something bad Happend with 'realpath'.");
1066  }
1067  out_strCanonicalPath.Set(actualpath);
1068  free(actualpath);
1069  return true;
1070 #endif
1071 }
1072 
1073 bool GetExecutable(OTString& strExecutablePath)
1074 {
1075 #ifdef TARGET_OS_MAC
1076  char bufPath[PATH_MAX + 1] = "";
1077  uint32_t size = sizeof(bufPath);
1078  if (_NSGetExecutablePath(bufPath, &size) == 0)
1079  strExecutablePath.Set(bufPath);
1080  else
1081  return false;
1082 #elif defined __linux__
1083 
1084  char buff[4096] = "";
1085  ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff) - 1);
1086  if (len != -1) { // good
1087  buff[len] = '\0';
1088  strExecutablePath.Set(buff);
1089  }
1090  else { // bad
1091  strExecutablePath.Set("");
1092  return false;
1093  }
1094 
1095 #elif defined _WIN32
1096 
1097 #ifdef _UNICODE
1098  TCHAR bufPath[_MAX_PATH + 1] = L"";
1099 #else
1100  TCHAR bufPath[_MAX_PATH + 1] = "";
1101 #endif
1102 
1103  GetModuleFileName(nullptr, bufPath, sizeof(bufPath) / sizeof(TCHAR));
1104 
1105 #ifdef UNICODE
1106  strExecutablePath.Set(utf8util::UTF8FromUTF16(bufPath));
1107 #else
1108  strExecutablePath.Set(bufPath);
1109 #endif
1110 #else
1111  return false;
1112 #endif
1113  return true;
1114 }
1115 
1116 bool GetCurrentWorking(OTString& strCurrentWorkingPath)
1117 {
1118 
1119 #ifdef _WIN32
1120  // Windows Common
1121  TCHAR* szPath = nullptr;
1122 #ifdef _UNICODE
1123 // Windows Unicode
1124 #define GetCurrentDir _wgetcwd
1125 #else
1126 // Windows No-Unicode
1127 #define GetCurrentDir _getcwd
1128 #endif
1129 #else
1130 // Unix
1131 #define GetCurrentDir getcwd
1132  char* szPath = nullptr;
1133 #endif
1134 
1135  // All
1136  szPath = GetCurrentDir(nullptr, 0);
1137  OT_ASSERT(szPath != nullptr);
1138 
1139  OTString result;
1140 
1141 #ifdef _WIN32
1142 #ifdef _UNICODE
1143  // Windows Unicode
1144  strCurrentWorkingPath.Set(utf8util::UTF8FromUTF16(szPath));
1145 #endif
1146 #else
1147  // Unix
1148  strCurrentWorkingPath.Set(szPath);
1149 #endif
1150  // All
1151  return true;
1152 }
1153 
1154 // static
1155 bool OTPaths::GetHomeFromSystem(OTString& out_strHomeFolder)
1156 {
1157 #ifdef _WIN32
1158 #ifdef _UNICODE
1159  TCHAR szPath[MAX_PATH] = L"";
1160 #else
1161  TCHAR szPath[MAX_PATH] = "";
1162 #endif
1163 
1164  if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
1165  nullptr, 0, szPath))) {
1166 #ifdef UNICODE
1167  out_strHomeFolder.Set(utf8util::UTF8FromUTF16(szPath));
1168 #else
1169  out_strHomeFolder.Set(szPath);
1170 #endif
1171  }
1172  else {
1173  out_strHomeFolder.Set("");
1174  return false;
1175  }
1176 #else
1177  out_strHomeFolder.Set(getenv("HOME"));
1178 #endif
1179  return true;
1180 }
1181 
1182 #ifdef _WIN32
1183 
1184 // static
1185 bool OTPaths::Win_GetInstallFolderFromRegistry(OTString& out_InstallFolderPath)
1186 {
1187  WindowsRegistryTools windowsRegistryTools;
1188 
1189  HKEY hKey = 0;
1190  LONG lRes = RegOpenKeyExW(
1191  HKEY_LOCAL_MACHINE, L"SOFTWARE\\Open-Transactions", 0, KEY_READ, &hKey);
1192  bool bExistsAndSuccess(lRes == ERROR_SUCCESS);
1193  bool bDoesNotExistsSpecifically(lRes == ERROR_FILE_NOT_FOUND);
1194 
1195  std::wstring strValueOfBinDir;
1196  windowsRegistryTools.GetStringRegKey(hKey, L"Path", strValueOfBinDir,
1197  L"bad");
1198 
1199  if (bExistsAndSuccess && !bDoesNotExistsSpecifically) {
1200  std::string strInstallPath(OTString::ws2s(strValueOfBinDir));
1201  out_InstallFolderPath.Set(strInstallPath.c_str());
1202 
1203  return true;
1204  }
1205 
1206  return false;
1207 }
1208 
1209 #endif
1210 
1211 // static
1212 bool OTPaths::AppendFolder(OTString& out_strPath, const OTString& strBasePath,
1213  const OTString& strFolderName)
1214 {
1215  if (!strBasePath.Exists()) {
1216  otErr << __FUNCTION__ << ": Null: "
1217  << "strBasePath"
1218  << " passed in!\n";
1219  OT_FAIL;
1220  }
1221  if (!strFolderName.Exists()) {
1222  otErr << __FUNCTION__ << ": Null: "
1223  << "strFolderName"
1224  << " passed in!\n";
1225  OT_FAIL;
1226  }
1227 
1228  OTString l_strBasePath_fix(""), l_strFolderName_fix("");
1229 
1230  if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false;
1231  if (!FixPath(strFolderName, l_strFolderName_fix, true)) return false;
1232 
1233  std::string l_strBasePath(l_strBasePath_fix.Get()),
1234  l_strFolderName(l_strFolderName_fix.Get());
1235 
1236  l_strBasePath.append(l_strFolderName);
1237 
1238  const OTString l_strPath(l_strBasePath);
1239 
1240  out_strPath = l_strPath;
1241  return true;
1242 }
1243 
1244 // static
1245 bool OTPaths::AppendFile(OTString& out_strPath, const OTString& strBasePath,
1246  const OTString& strFileName)
1247 {
1248  if (!strBasePath.Exists()) {
1249  otErr << __FUNCTION__ << ": Null: "
1250  << "strBasePath"
1251  << " passed in!\n";
1252  OT_FAIL;
1253  }
1254  if (!strFileName.Exists()) {
1255  otErr << __FUNCTION__ << ": Null: "
1256  << "strFileName"
1257  << " passed in!\n";
1258  OT_FAIL;
1259  }
1260 
1261  OTString l_strBasePath_fix(""), l_strFileName_fix("");
1262 
1263  if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false;
1264  if (!FixPath(strFileName, l_strFileName_fix, false)) return false;
1265 
1266  std::string l_strBasePath(l_strBasePath_fix.Get()),
1267  l_strFileName(l_strFileName_fix.Get());
1268 
1269  l_strBasePath.append(l_strFileName);
1270 
1271  const OTString l_strPath(l_strBasePath);
1272 
1273  out_strPath = l_strPath;
1274  return true;
1275 }
1276 
1277 // this function dosn't change the "strRelativePath" so. It will only fix the
1278 // strBasePath.
1279 // static
1280 bool OTPaths::RelativeToCanonical(OTString& out_strCanonicalPath,
1281  const OTString& strBasePath,
1282  const OTString& strRelativePath)
1283 {
1284  if (!strBasePath.Exists()) {
1285  otErr << __FUNCTION__ << ": Null: "
1286  << "strBasePath"
1287  << " passed in!\n";
1288  OT_FAIL;
1289  }
1290  if (!strRelativePath.Exists()) {
1291  otErr << __FUNCTION__ << ": Null: "
1292  << "strRelativePath"
1293  << " passed in!\n";
1294  OT_FAIL;
1295  }
1296 
1297  OTString l_strBasePath_fix("");
1298  if (!FixPath(strBasePath, l_strBasePath_fix, true)) return false;
1299 
1300  if (strRelativePath.Compare(".")) {
1301  out_strCanonicalPath = strBasePath;
1302  return true;
1303  } // if ".", return base path.
1304 
1305  std::string l_strBasePath(l_strBasePath_fix.Get()),
1306  l_strRelativePath(strRelativePath.Get());
1307 
1308  l_strBasePath.append(l_strRelativePath);
1309 
1310  OTString l_strPath(l_strBasePath), l_strCanonicalPath("");
1311 
1312  if (!ToReal(l_strPath, l_strCanonicalPath)) return false;
1313 
1314  out_strCanonicalPath = l_strCanonicalPath;
1315 
1316  return true;
1317 }
1318 
1319 // static
1320 bool OTPaths::BuildFolderPath(const OTString& strFolderPath,
1321  bool& out_bFolderCreated)
1322 {
1323  out_bFolderCreated = false;
1324 
1325  OTString l_strFolderPath_fix(""), l_strFolderPath_real("");
1326 
1327  if (!ToReal(strFolderPath, l_strFolderPath_real))
1328  return false; // path to real
1329 
1330  if (!FixPath(l_strFolderPath_real, l_strFolderPath_fix, true))
1331  return false; // real to fixed real
1332 
1333  std::string l_strFolderPath(l_strFolderPath_fix.Get()); // fixed real path.
1334 
1335  std::vector<std::string> vFolders;
1336 
1337  split_byChar(vFolders, l_strFolderPath, "/", split::no_empties);
1338 
1339  size_t nSize = vFolders.size();
1340 
1341  std::string l_strPathPart("");
1342  bool l_FolderExists(false), l_bBuiltFolder(false);
1343 
1344  const bool bLog(OTLog::IsInitialized());
1345 
1346  for (size_t i = 0; i < nSize; i++) {
1347 #ifndef _WIN32 // aka UNIX
1348  if (0 == i) l_strPathPart += "/"; // add annother / for root.
1349 #endif
1350  l_strPathPart += vFolders[i];
1351  l_strPathPart += "/";
1352 
1353  if (0 == i) continue; // / or x:/ should be skiped.
1354 
1355  OTString strPathPart(l_strPathPart);
1356 
1357  if (!ConfirmCreateFolder(strPathPart, l_FolderExists, l_bBuiltFolder))
1358  return false;
1359  if (bLog && l_bBuiltFolder)
1360  otOut << __FUNCTION__ << ": Made new folder: " << l_strPathPart
1361  << "\n";
1362 
1363  if (!out_bFolderCreated && l_bBuiltFolder) out_bFolderCreated = true;
1364  }
1365  return true;
1366 }
1367 
1368 // static
1369 bool OTPaths::BuildFilePath(const OTString& strFolderPath,
1370  bool& out_bFolderCreated)
1371 {
1372  out_bFolderCreated = false;
1373 
1374  OTString l_strFilePath_fix(""), l_strFilePath_real("");
1375 
1376  if (!ToReal(strFolderPath, l_strFilePath_real))
1377  return false; // path to real
1378 
1379  if (!FixPath(l_strFilePath_real, l_strFilePath_fix, false))
1380  return false; // real to fixed real
1381 
1382  std::string l_strFilePath(l_strFilePath_fix.Get()); // fixed real path.
1383 
1384  std::vector<std::string> vFolders;
1385 
1386  split_byChar(vFolders, l_strFilePath, "/", split::no_empties);
1387 
1388  size_t nSize = vFolders.size();
1389 
1390  std::string l_strPathPart("");
1391  bool l_FolderExists(false), l_bBuiltFolder(false);
1392 
1393  const bool bLog(OTLog::IsInitialized());
1394 
1395  for (size_t i = 0; i < nSize; i++) {
1396 #ifndef _WIN32 // aka UNIX
1397  if (0 == i) l_strPathPart += "/"; // add annother / for root.
1398 #endif
1399 
1400  l_strPathPart += vFolders[i];
1401 
1402  if ((i + 1) == nSize) continue; // file should be skipped
1403 
1404  l_strPathPart += "/"; // is a folder, so should append /
1405 
1406  if (0 == i) continue; // / or x:/ should be skiped.
1407 
1408  OTString strPathPart(l_strPathPart);
1409  if (!ConfirmCreateFolder(strPathPart, l_FolderExists, l_bBuiltFolder))
1410  return false;
1411  if (bLog && l_bBuiltFolder)
1412  otOut << __FUNCTION__ << ": Made new folder: " << l_strPathPart
1413  << "";
1414 
1415  if (!out_bFolderCreated && l_bBuiltFolder) out_bFolderCreated = true;
1416  }
1417  return true;
1418 }
1419 
1420 } // namespace opentxs
static EXPORT bool FileExists(const OTString &strFilePath, int64_t &nFileLength)
Definition: OTPaths.cpp:842
static EXPORT bool LoadSetPrefixFolder(OTSettings &config=s_settings, const OTString &strPrefixFolder="")
Definition: OTPaths.cpp:331
#define GetCurrentDir
EXPORT bool Check_str(const OTString &strSection, const OTString &strKey, OTString &out_strResult, bool &out_bKeyExist) const
Definition: OTSettings.cpp:309
static EXPORT bool Set(OTSettings &config, const OTString &strSection, const OTString &strKey, const OTString &strValue, const bool &bIsRelative, bool &out_bIsNewOrUpdated, const OTString &strComment="")
Definition: OTPaths.cpp:699
EXPORT bool Set_bool(const OTString &strSection, const OTString &strKey, const bool &bValue, bool &out_bNewOrUpdate, const OTString &strComment="")
Definition: OTSettings.cpp:607
static EXPORT void SetAppBinaryFolder(OTString strLocation)
Definition: OTPaths.cpp:235
OTLOG_IMPORT OTLogStream otOut
static EXPORT bool ToReal(const OTString &strExactPath, OTString &out_strCanonicalPath)
Definition: OTPaths.cpp:985
static EXPORT bool BuildFolderPath(const OTString &strFolderPath, bool &out_bFolderCreated)
Definition: OTPaths.cpp:1320
EXPORT uint32_t GetLength() const
Definition: OTString.cpp:1040
static EXPORT const OTString & PrefixFolder()
Definition: OTPaths.cpp:302
#define OT_CONFIG_ISRELATIVE
Definition: OTPaths.cpp:199
static EXPORT bool RelativeToCanonical(OTString &out_strCanonicalPath, const OTString &strBasePath, const OTString &strRelativePath)
Definition: OTPaths.cpp:1280
EXPORT bool Exists() const
Definition: OTString.cpp:1035
static EXPORT const OTString & AppDataFolder()
Definition: OTPaths.cpp:254
EXPORT void Format(const char *fmt,...)
Definition: OTString.cpp:1319
static EXPORT bool AppendFolder(OTString &out_strPath, const OTString &strBasePath, const OTString &strFolderName)
Definition: OTPaths.cpp:1212
bool GetCurrentWorking(OTString &strCurrentWorkingPath)
Definition: OTPaths.cpp:1116
static EXPORT bool FixPath(const OTString &strPath, OTString &out_strFixedPath, const bool &bIsFolder)
Definition: OTPaths.cpp:759
EXPORT bool Compare(const char *compare) const
Definition: OTString.cpp:1102
static EXPORT bool Get(OTSettings &config, const OTString &strSection, const OTString &strKey, OTString &out_strVar, bool &out_bIsRelative, bool &out_bKeyExist)
Definition: OTPaths.cpp:625
EXPORT void Set(const char *data, uint32_t enforcedMaxLength=0)
Definition: OTString.cpp:1055
#define OT_SCRIPTS_DIR
Definition: OTPaths.cpp:206
#define OT_APPDATA_DIR
Definition: OTPaths.cpp:179
static EXPORT bool GetHomeFromSystem(OTString &out_strHomeFolder)
Definition: OTPaths.cpp:1155
#define S_ISREG(mode)
Definition: OTPaths.cpp:169
static EXPORT void SetHomeFolder(OTString strLocation)
Definition: OTPaths.cpp:245
EXPORT ~OTPaths()
Definition: OTPaths.cpp:226
#define OT_ASSERT(x)
Definition: Assert.hpp:150
static EXPORT bool IsInitialized()
Definition: OTLog.cpp:371
EXPORT bool Set_str(const OTString &strSection, const OTString &strKey, const OTString &strValue, bool &out_bNewOrUpdate, const OTString &strComment="")
Definition: OTSettings.cpp:449
#define OT_ASSERT_MSG(x, s)
Definition: Assert.hpp:155
static EXPORT bool BuildFilePath(const OTString &strFolderPath, bool &out_bFolderCreated)
Definition: OTPaths.cpp:1369
static EXPORT bool LoadSetScriptsFolder(OTSettings &config=s_settings, const OTString &strScriptsFolder="", const bool &bIsRelative=true)
Definition: OTPaths.cpp:504
EXPORT bool Reset()
Definition: OTSettings.cpp:297
#define OT_FAIL
Definition: Assert.hpp:139
#define OT_INIT_CONFIG_FILENAME
Definition: OTPaths.cpp:198
EXPORT std::string UTF8FromUTF16(const std::wstring &utf16)
static EXPORT bool ConfirmCreateFolder(const OTString &strExactPath, bool &out_Exists, bool &out_IsNew)
Definition: OTPaths.cpp:921
EXPORT bool Check_bool(const OTString &strSection, const OTString &strKey, bool &out_bResult, bool &out_bKeyExist) const
Definition: OTSettings.cpp:400
OTLOG_IMPORT OTLogStream otWarn
EXPORT const char * Get() const
Definition: OTString.cpp:1045
#define OT_PREFIX_PATH
Definition: OTPaths.cpp:194
OTLOG_IMPORT OTLogStream otErr
static EXPORT const OTString & ScriptsFolder()
Definition: OTPaths.cpp:315
EXPORT bool Exists(std::string strFolder, std::string oneStr="", std::string twoStr="", std::string threeStr="")
Definition: OTStorage.cpp:584
EXPORT const bool & IsLoaded() const
Definition: OTSettings.cpp:292
#define S_ISDIR(mode)
Definition: OTPaths.cpp:165
static EXPORT const OTString & AppBinaryFolder()
Definition: OTPaths.cpp:230
static EXPORT bool AppendFile(OTString &out_strPath, const OTString &strBasePath, const OTString &strFileName)
Definition: OTPaths.cpp:1245
bool GetExecutable(OTString &strExecutablePath)
Definition: OTPaths.cpp:1073
static EXPORT bool FolderExists(const OTString &strFolderPath)
Definition: OTPaths.cpp:883
static EXPORT const OTString & HomeFolder()
Definition: OTPaths.cpp:240
static EXPORT bool PathExists(const OTString &strPath)
Definition: OTPaths.cpp:802
static EXPORT const OTString & GlobalConfigFile()
Definition: OTPaths.cpp:286
static EXPORT std::string replace_chars(const std::string &str, const std::string &charsFrom, const char &charTo)
Definition: OTString.cpp:420