OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
diaginit.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of diagnostic initialization functions. Settings are stored
7/// in a profile (name is provided) in a section named "Diagnostics". Profile
8/// format in an ascii .ini file looks like:
9/// \code
10/// [Diagnostics]
11/// Enabled = <enabled>
12/// <groupname1> = <enabled> <level>
13/// <groupname2> = <enabled> <level>
14/// ...
15/// <groupnameN> = <enabled> <level>
16/// \endcode
17/// where:
18/// \code
19/// <enabled> = 0|1
20/// <level> = 0..255
21/// \endcode
22//----------------------------------------------------------------------------
23#include <owl/pch.h>
24#include <owl/defs.h>
25#include <owl/profile.h>
26#include <owl/shellitm.h>
27#include <filesystem>
28
29using namespace std;
30using namespace std::filesystem;
31
32namespace owl {
33
34namespace
35{
36
37 const tchar DiagnosticsSection[] = _T("Diagnostics");
38
39 struct TGroupSettings
40 {
41 int Enabled;
42 int Level;
43
44 // Parses the settings for the given group in the given profile.
45 // The format of the setting is "<int Enabled> <int Level>", e.g. "1 3".
46 // If no setting is found, or parsing fails, the given defaults are used.
47 //
48 TGroupSettings(TProfile& p, const tstring& group, int defEnabled, int defLevel = 0)
49 : Enabled(defEnabled), Level(defLevel)
50 {
51 tistringstream is(p.GetString(group));
52 is >> Enabled >> Level;
53 }
54 };
55
57 {
58 // NOTE: pszPath should be freed by CoTaskMemFree, whether SHGetKnownFolderPath succeeds or not.
59 // See: https://learn.microsoft.com/en-gb/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath
60 //
61 auto pszPath = PWSTR{};
63 const auto pathGuard = unique_ptr<WCHAR, decltype(&CoTaskMemFree)>{pszPath, &CoTaskMemFree};
64 if (r != S_OK) throw TXOwl{_T("SHGetKnownFolderPath failed")};
66 return pszPath;
67 };
68
69} // namespace
70
71//
72// Returns the full path for the given file.
73// If the given file has no parent path, the parent path is assumed to be "%appdata%\OWLNext".
74// This is a private function. However, it is defined in the `owl` namespace, since it is reused
75// internally by TTraceWindow in "tracewnd.cpp".
76//
78{
79 const auto f = path{filename};
80 if (f.has_parent_path())
81 return to_tstring(f);
82
83 const auto d = GetRoamingAppDataFolderPath_() / _T("OWLNext");
84 if (!exists(d))
86 return to_tstring(d / f);
87}
88
89_OWLFUNC(bool)
91{
94
95 bool globallyEnabled = p.GetInt(_T("Enabled"), 1) != 0;
96 if (!globallyEnabled) return false;
97
98 TGroupSettings s(p, _A2W(diagGroup), defEnabled ? 1 : 0);
99 return s.Enabled != 0;
100}
101
102_OWLFUNC(int)
110
111} // OWL namespace
112
#define CHECK(condition)
Definition checks.h:239
An instance of TProfile encapsulates a setting within a system file, often referred to as a profile o...
Definition profile.h:44
int GetInt(LPCTSTR key, int defaultInt=0)
Looks up and returns the integer value associated with the given string, key.
Definition profile.cpp:86
#define _T(x)
Definition cygwin.h:51
#define _A2W(lpw)
Definition memory.h:220
#define _USES_CONVERSION
Definition memory.h:217
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
bool GetDiagEnabled(LPCSTR filename, LPCSTR diagGroup, bool defEnabled)
Retrieves a diagnostic group's enabled flag from a private ini-file.
Definition diaginit.cpp:90
char tchar
Definition defs.h:77
std::istringstream tistringstream
Definition strmdefs.h:37
std::string tstring
Definition defs.h:79
int GetDiagLevel(LPCSTR filename, LPCSTR diagGroup, int defLevel)
Retrieves a diagnostic group's level setting from a private ini-file.
Definition diaginit.cpp:103
auto GetDiagIniFullFileName_(LPCSTR filename) -> tstring
Definition diaginit.cpp:77
auto to_tstring(const T &v) -> tstring
Definition defs.h:82
General definitions used by all ObjectWindows programs.
#define _OWLFUNC(p)
Definition defs.h:341
Definition of TProfile class.
Definitions of Win95 Shell Clases: TShellItem, TShellItemIterator, TPidl, TShellMalloc.