OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
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
29
using namespace
std;
30
using namespace
std::filesystem;
31
32
namespace
owl
{
33
34
namespace
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
56
auto
GetRoamingAppDataFolderPath_() -> path
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{};
62
const
auto
r = SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_VERIFY,
nullptr
, &pszPath);
63
const
auto
pathGuard = unique_ptr<WCHAR,
decltype
(&CoTaskMemFree)>{pszPath, &CoTaskMemFree};
64
if
(r != S_OK)
throw
TXOwl
{
_T
(
"SHGetKnownFolderPath failed"
)};
65
CHECK
(pszPath);
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
//
77
auto
GetDiagIniFullFileName_
(LPCSTR filename) ->
tstring
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))
85
create_directory(d);
86
return
to_tstring
(d / f);
87
}
88
89
_OWLFUNC
(
bool
)
90
GetDiagEnabled
(LPCSTR filename, LPCSTR diagGroup,
bool
defEnabled)
91
{
92
_USES_CONVERSION
;
93
TProfile
p(DiagnosticsSection,
GetDiagIniFullFileName_
(filename));
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
)
103
GetDiagLevel
(LPCSTR filename, LPCSTR diagGroup,
int
defLevel)
104
{
105
_USES_CONVERSION
;
106
TProfile
p(DiagnosticsSection,
GetDiagIniFullFileName_
(filename));
107
TGroupSettings s(p,
_A2W
(diagGroup), 0, defLevel);
108
return
s.Level;
109
}
110
111
}
// OWL namespace
112
CHECK
#define CHECK(condition)
Definition
checks.h:239
owl::TProfile
An instance of TProfile encapsulates a setting within a system file, often referred to as a profile o...
Definition
profile.h:44
owl::TProfile::GetInt
int GetInt(LPCTSTR key, int defaultInt=0)
Looks up and returns the integer value associated with the given string, key.
Definition
profile.cpp:86
owl::TXOwl
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition
except.h:38
_T
#define _T(x)
Definition
cygwin.h:51
pch.h
_A2W
#define _A2W(lpw)
Definition
memory.h:220
_USES_CONVERSION
#define _USES_CONVERSION
Definition
memory.h:217
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::GetDiagEnabled
bool GetDiagEnabled(LPCSTR filename, LPCSTR diagGroup, bool defEnabled)
Retrieves a diagnostic group's enabled flag from a private ini-file.
Definition
diaginit.cpp:90
owl::tchar
char tchar
Definition
defs.h:77
owl::tistringstream
std::istringstream tistringstream
Definition
strmdefs.h:37
owl::tstring
std::string tstring
Definition
defs.h:79
owl::GetDiagLevel
int GetDiagLevel(LPCSTR filename, LPCSTR diagGroup, int defLevel)
Retrieves a diagnostic group's level setting from a private ini-file.
Definition
diaginit.cpp:103
owl::GetDiagIniFullFileName_
auto GetDiagIniFullFileName_(LPCSTR filename) -> tstring
Definition
diaginit.cpp:77
owl::to_tstring
auto to_tstring(const T &v) -> tstring
Definition
defs.h:82
defs.h
General definitions used by all ObjectWindows programs.
_OWLFUNC
#define _OWLFUNC(p)
Definition
defs.h:341
profile.h
Definition of TProfile class.
shellitm.h
Definitions of Win95 Shell Clases: TShellItem, TShellItemIterator, TPidl, TShellMalloc.
source
owlcore
diaginit.cpp
Generated by
1.18.0