OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 <owl/filename.h>
28#include <sstream>
29
30using namespace owl;
31using namespace std;
32
33namespace owl {
34
35namespace
36{
37
38 const tchar DiagnosticsSection[] = _T("Diagnostics");
39
40 struct TGroupSettings
41 {
42 int Enabled;
43 int Level;
44
45 // Parses the settings for the given group in the given profile.
46 // The format of the setting is "<int Enabled> <int Level>", e.g. "1 3".
47 // If no setting is found, or parsing fails, the given defaults are used.
48 //
49 TGroupSettings(TProfile& p, const tstring& group, int defEnabled, int defLevel = 0)
50 : Enabled(defEnabled), Level(defLevel)
51 {
53 is >> Enabled >> Level;
54 }
55 };
56
58 {
61 CHECKX(SUCCEEDED(r), _T("SHGetSpecialFolderLocation failed")); InUse(r);
62 tchar buf[_MAX_PATH];
63 const bool ok = TShell::SHGetPathFromIDList(pidl, &buf[0]);
64 CHECKX(ok, _T("SHGetPathFromIDList failed")); InUse(ok);
65 const TFileName f(buf, true);
67 return f;
68 };
69
70} // namespace
71
72//
73// Returns the full path for the given file.
74// If the given file has no path, it is assumed to be located in "%appdata%\OWLNext".
75// This is a private function. However, it is defined in the `owl` namespace, since it is reused
76// internally by TTraceWindow in "tracewnd.cpp".
77//
79{
84 return f.Canonical();
85
86 TFileName d = GetRoamingAppDataFolderPath_().AddSubDir(_T("OWLNext"));
87 if (!d.Exists())
88 d.CreateDir();
89 return d.MergeParts(TFileName::File | TFileName::Ext, f).Canonical();
90}
91
92_OWLFUNC(bool)
94{
97
98 bool globallyEnabled = p.GetInt(_T("Enabled"), 1) != 0;
99 if (!globallyEnabled) return false;
100
101 TGroupSettings s(p, _A2W(diagGroup), defEnabled ? 1 : 0);
102 return s.Enabled != 0;
103}
104
105_OWLFUNC(int)
113
114} // OWL namespace
115
#define CHECKX(condition, message)
Definition checks.h:245
The TFileName class constructs filenames.
Definition filename.h:37
@ Device
Logical device or sharename.
Definition filename.h:127
@ Path
Directory path to the file.
Definition filename.h:128
@ Ext
Extension.
Definition filename.h:130
@ File
Filename part without the extension.
Definition filename.h:129
@ Server
Server name.
Definition filename.h:126
const tstring & Canonical(bool forceUNC=false) const
Return normal fully qualified path string.
Definition filename.cpp:520
bool HasParts(uint p) const
Returns true if any of the parts specified by p are used.
Definition filename.cpp:810
An instance of TProfile encapsulates a setting within a system file, often referred to as a profile o...
Definition profile.h:44
bool GetString(LPCTSTR key, TCHAR *buff, unsigned buffSize, LPCTSTR defaultString=0)
Looks up and returns the string value associated with the given key string.
Definition profile.cpp:100
int GetInt(LPCTSTR key, int defaultInt=0)
Looks up and returns the integer value associated with the given string, key.
Definition profile.cpp:86
static BOOL SHGetPathFromIDList(LPCITEMIDLIST, TCHAR *)
Invokes 'SHGetPathFromIDList' indirectly.
Definition shellitm.cpp:196
static HRESULT SHGetSpecialFolderLocation(HWND, int, LPITEMIDLIST *)
Invokes 'SHGetSpecialFolderLocation' indirectly.
Definition shellitm.cpp:206
#define _MAX_PATH
Definition cygwin.h:97
#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
tstring GetDiagIniFullFileName_(LPCSTR filename_)
Definition diaginit.cpp:78
bool GetDiagEnabled(LPCSTR filename, LPCSTR diagGroup, bool defEnabled)
Retrieves a diagnostic group's enabled flag from a private ini-file.
Definition diaginit.cpp:93
void InUse(const T &arg)
Handy utility to avoid compiler warnings about unused parameters.
Definition defs.h:299
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:106
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.