Mercurial > hg > vamp-plugin-pack
comparison get-version.cpp @ 67:38cd115c91d4
Integrate version checker into installer program & build, + win32 signing bits
author | Chris Cannam |
---|---|
date | Thu, 13 Feb 2020 10:56:15 +0000 |
parents | 85768d48e6ce |
children |
comparison
equal
deleted
inserted
replaced
66:85768d48e6ce | 67:38cd115c91d4 |
---|---|
30 #include <vamp-hostsdk/PluginHostAdapter.h> | 30 #include <vamp-hostsdk/PluginHostAdapter.h> |
31 | 31 |
32 // Undocumented internal API | 32 // Undocumented internal API |
33 #include <vamp-hostsdk/../src/vamp-hostsdk/Files.h> | 33 #include <vamp-hostsdk/../src/vamp-hostsdk/Files.h> |
34 | 34 |
35 #ifdef _WIN32 | |
36 #include <windows.h> | |
37 #include <process.h> | |
38 #include <io.h> | |
39 #else | |
40 #include <unistd.h> | |
41 #endif | |
42 | |
43 #include <fcntl.h> | |
44 | |
35 #include <iostream> | 45 #include <iostream> |
36 #include <string> | 46 #include <string> |
37 | 47 |
38 using namespace std; | 48 using namespace std; |
39 | 49 |
57 << "in the latter case." << endl; | 67 << "in the latter case." << endl; |
58 cerr << endl; | 68 cerr << endl; |
59 exit(2); | 69 exit(2); |
60 } | 70 } |
61 | 71 |
72 // We write our output to stdout, but want to ensure that the plugin | |
73 // doesn't write anything itself. To do this we open a null file | |
74 // descriptor and dup2() it into place of stdout in the gaps between | |
75 // our own output activity. | |
76 | |
77 static int normalFd = -1; | |
78 static int suspendedFd = -1; | |
79 | |
80 static void initFds() | |
81 { | |
82 #ifdef _WIN32 | |
83 normalFd = _dup(1); | |
84 suspendedFd = _open("NUL", _O_WRONLY); | |
85 #else | |
86 normalFd = dup(1); | |
87 suspendedFd = open("/dev/null", O_WRONLY); | |
88 #endif | |
89 | |
90 if (normalFd < 0 || suspendedFd < 0) { | |
91 throw std::runtime_error | |
92 ("Failed to initialise fds for stdio suspend/resume"); | |
93 } | |
94 } | |
95 | |
96 static void suspendOutput() | |
97 { | |
98 #ifdef _WIN32 | |
99 _dup2(suspendedFd, 1); | |
100 #else | |
101 dup2(suspendedFd, 1); | |
102 #endif | |
103 } | |
104 | |
105 static void resumeOutput() | |
106 { | |
107 fflush(stdout); | |
108 #ifdef _WIN32 | |
109 _dup2(normalFd, 1); | |
110 #else | |
111 dup2(normalFd, 1); | |
112 #endif | |
113 } | |
114 | |
62 int main(int argc, char **argv) | 115 int main(int argc, char **argv) |
63 { | 116 { |
64 char *scooter = argv[0]; | 117 char *scooter = argv[0]; |
65 char *name = 0; | 118 char *name = 0; |
66 while (scooter && *scooter) { | 119 while (scooter && *scooter) { |
70 if (!name || !*name) name = argv[0]; | 123 if (!name || !*name) name = argv[0]; |
71 | 124 |
72 if (argc != 2) usage(name); | 125 if (argc != 2) usage(name); |
73 if (string(argv[1]) == string("-?")) usage(name); | 126 if (string(argv[1]) == string("-?")) usage(name); |
74 | 127 |
128 initFds(); | |
129 suspendOutput(); | |
130 | |
75 string libraryPath(argv[1]); | 131 string libraryPath(argv[1]); |
76 | 132 |
77 void *handle = Files::loadLibrary(libraryPath); | 133 void *handle = Files::loadLibrary(libraryPath); |
78 if (!handle) { | 134 if (!handle) { |
79 cerr << "Unable to load library " << libraryPath << endl; | 135 cerr << "Unable to load library " << libraryPath << endl; |
93 | 149 |
94 int index = 0; | 150 int index = 0; |
95 const VampPluginDescriptor *descriptor = 0; | 151 const VampPluginDescriptor *descriptor = 0; |
96 | 152 |
97 while ((descriptor = fn(VAMP_API_VERSION, index))) { | 153 while ((descriptor = fn(VAMP_API_VERSION, index))) { |
154 resumeOutput(); | |
98 cout << descriptor->identifier << ":" | 155 cout << descriptor->identifier << ":" |
99 << descriptor->pluginVersion << endl; | 156 << descriptor->pluginVersion << endl; |
157 suspendOutput(); | |
100 ++index; | 158 ++index; |
101 } | 159 } |
102 | 160 |
103 Files::unloadLibrary(handle); | 161 Files::unloadLibrary(handle); |
104 | 162 |