File: tqslpaths.h

package info (click to toggle)
trustedqsl 2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 29,116 kB
  • ctags: 3,577
  • sloc: cpp: 24,858; xml: 5,344; ansic: 626; sh: 88; python: 18; makefile: 11
file content (91 lines) | stat: -rw-r--r-- 3,143 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/***************************************************************************
                          tqslpaths.h  -  description
                             -------------------
    begin                : Mon Dec 9 2002
    copyright            : (C) 2002 by ARRL
    author               : Jon Bloom
    email                : jbloom@arrl.org
    revision             : $Id: tqslpaths.h,v 1.7 2013/03/01 13:09:28 k1mu Exp $
 ***************************************************************************/

#ifndef __tqslpaths_h
#define __tqslpaths_h

#ifdef HAVE_CONFIG_H
#include "sysconfig.h"
#endif

#ifdef __APPLE__
#include <CoreFoundation/CFBundle.h>
#endif

#include <wx/filefn.h>
#if defined(__WIN32__)
	#include <windows.h>
#endif

class DocPaths : public wxPathList {
 public:
	explicit DocPaths(wxString subdir) : wxPathList() {
#ifdef _WIN32
		Add(wxGetHomeDir() + wxT("\\help\\") + subdir);
#else
		Add(wxGetHomeDir() + wxT("/help/") + subdir);
#endif
#if defined(_WIN32)
		HKEY hkey;
		if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\TrustedQSL",
			0, KEY_READ, &hkey) == ERROR_SUCCESS) {
			DWORD dtype;
			char path[256];
			DWORD bsize = sizeof path;
			if (RegQueryValueEx(hkey, "HelpDir", 0, &dtype, (LPBYTE)path, &bsize)
				== ERROR_SUCCESS) {
				Add(wxString(path) + "\\");
				Add(wxString(path) + "\\" + subdir);
			}
		}
		Add(wxT("help\\") + subdir);
#elif defined(__APPLE__)
		CFBundleRef tqslBundle = CFBundleGetMainBundle();
		CFURLRef bundleURL = CFBundleCopyBundleURL(tqslBundle);
		CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(tqslBundle);
		if (bundleURL && resourcesURL) {
			CFStringRef bundleString = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
			CFStringRef resString = CFURLCopyFileSystemPath(resourcesURL, kCFURLPOSIXPathStyle);
			CFRelease(bundleURL);
			CFRelease(resourcesURL);

			CFIndex lenB = CFStringGetMaximumSizeForEncoding(CFStringGetLength(bundleString), kCFStringEncodingUTF8);
			CFIndex lenR = CFStringGetMaximumSizeForEncoding(CFStringGetLength(resString), kCFStringEncodingUTF8);

			char *npath = reinterpret_cast<char *>(malloc(lenB  + lenR + 10));
			if (npath) {
				CFStringGetCString(bundleString, npath, lenB + 1, kCFStringEncodingASCII);
				CFRelease(bundleString);

                		// if last char is not a /, append one
                		if ((strlen(npath) > 0) && (npath[strlen(npath)-1] != '/')) {
                        		strncat(npath, "/", 2);
                		}

				CFStringGetCString(resString, npath + strlen(npath), lenR + 1, kCFStringEncodingUTF8);

                		if ((strlen(npath) > 0) && (npath[strlen(npath)-1] != '/')) {
                        		strncat(npath, "/", 2);
                		}
                		Add(wxString::FromUTF8(npath));
                		Add(wxString::FromUTF8(npath) + wxT("Help/"));
				Add(wxT("/Applications/") + subdir + wxT(".app/Contents/Resources/"));
				Add(wxT("/Applications/") + subdir + wxT(".app/Contents/Resources/Help/"));
				free(npath);
			}
		}
#else
		Add(wxT(CONFDIR) wxT("help/"));
		Add(wxT(CONFDIR) wxT("help/") + subdir);
		Add(subdir);
#endif
	}
};
#endif		// tqslpaths_h