]> git.cworth.org Git - apitrace/blob - cli/cli_resources.cpp
d3dretrace: Dump textures of all shader stages.
[apitrace] / cli / cli_resources.cpp
1 /*********************************************************************
2  *
3  * Copyright 2011 Intel Corporation
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without
9  * restriction, including without limitation the rights to use, copy,
10  * modify, merge, publish, distribute, sublicense, and/or sell copies
11  * of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  *
26  *********************************************************************/
27
28
29 #include <iostream>
30
31 #include "os_string.hpp"
32
33 #include "cli_resources.hpp"
34
35
36 static bool
37 tryPath(const os::String &path, bool verbose)
38 {
39     bool exists = path.exists();
40     if (verbose) {
41         std::cerr << "info: " << (exists ? "found" : "did not find") << " " << path.str() << "\n";
42     }
43     return exists;
44 }
45
46 os::String
47 findProgram(const char *programFilename, bool verbose)
48 {
49     os::String programPath;
50
51     os::String processDir = os::getProcessName();
52     processDir.trimFilename();
53
54     programPath = processDir;
55     programPath.join(programFilename);
56     if (tryPath(programPath, verbose)) {
57         return programPath;
58     }
59
60 #ifndef _WIN32
61     // Try absolute install directory
62     programPath = APITRACE_PROGRAMS_INSTALL_DIR;
63     programPath.join(programFilename);
64     if (tryPath(programPath, verbose)) {
65         return programPath;
66     }
67 #endif
68
69     return "";
70 }
71
72 os::String
73 findWrapper(const char *wrapperFilename, bool verbose)
74 {
75     os::String wrapperPath;
76
77     os::String processDir = os::getProcessName();
78     processDir.trimFilename();
79
80     // Try relative build directory
81     // XXX: Just make build and install directory layout match
82     wrapperPath = processDir;
83 #if defined(APITRACE_CONFIGURATION_SUBDIR)
84     // Go from `Debug\apitrace.exe` to `wrappers\Debug\foo.dll` on MSVC builds.
85     wrapperPath.join("..");
86     wrapperPath.join("wrappers");
87     wrapperPath.join(APITRACE_CONFIGURATION_SUBDIR);
88 #else
89     wrapperPath.join("wrappers");
90 #endif
91     wrapperPath.join(wrapperFilename);
92     if (tryPath(wrapperPath, verbose)) {
93         return wrapperPath;
94     }
95
96     // Try relative install directory
97     wrapperPath = processDir;
98 #if defined(_WIN32)
99     wrapperPath.join("..\\lib\\wrappers");
100 #elif defined(__APPLE__)
101     wrapperPath.join("../lib/wrappers");
102 #else
103     wrapperPath.join("../lib/apitrace/wrappers");
104 #endif
105     wrapperPath.join(wrapperFilename);
106     if (tryPath(wrapperPath, verbose)) {
107         return wrapperPath;
108     }
109
110 #ifndef _WIN32
111     // Try absolute install directory
112     wrapperPath = APITRACE_WRAPPERS_INSTALL_DIR;
113     wrapperPath.join(wrapperFilename);
114     if (tryPath(wrapperPath, verbose)) {
115         return wrapperPath;
116     }
117 #endif
118
119     return "";
120 }
121
122 os::String
123 findScript(const char *scriptFilename, bool verbose)
124 {
125     os::String scriptPath;
126
127     os::String processDir = os::getProcessName();
128     processDir.trimFilename();
129
130     // Try relative build directory
131     // XXX: Just make build and install directory layout match
132 #if defined(APITRACE_SOURCE_DIR)
133     scriptPath = APITRACE_SOURCE_DIR;
134     scriptPath.join("scripts");
135     scriptPath.join(scriptFilename);
136     if (tryPath(scriptPath, verbose)) {
137         return scriptPath;
138     }
139 #endif
140
141     // Try relative install directory
142     scriptPath = processDir;
143 #if defined(_WIN32)
144     scriptPath.join("..\\lib\\scripts");
145 #elif defined(__APPLE__)
146     scriptPath.join("../lib/scripts");
147 #else
148     scriptPath.join("../lib/apitrace/scripts");
149 #endif
150     scriptPath.join(scriptFilename);
151     if (tryPath(scriptPath, verbose)) {
152         return scriptPath;
153     }
154
155 #ifndef _WIN32
156     // Try absolute install directory
157     scriptPath = APITRACE_SCRIPTS_INSTALL_DIR;
158     scriptPath.join(scriptFilename);
159     if (tryPath(scriptPath, verbose)) {
160         return scriptPath;
161     }
162 #endif
163
164     std::cerr << "error: cannot find " << scriptFilename << " script\n";
165
166     return "";
167 }