mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
Add wWinMain to FLTK p3dcert, and use wstring entirely [untested]
This commit is contained in:
parent
645ee9d05f
commit
40f70c388f
@ -92,6 +92,30 @@ no_cert_text[] =
|
|||||||
|
|
||||||
"Click Cancel to avoid running this application.";
|
"Click Cancel to avoid running this application.";
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
int WINAPI
|
||||||
|
wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
|
||||||
|
OpenSSL_add_all_algorithms();
|
||||||
|
|
||||||
|
LPWSTR *argv;
|
||||||
|
int argc;
|
||||||
|
argv = CommandLineToArgvW(pCmdLine, &argc);
|
||||||
|
if (argv == NULL || argc != 2) {
|
||||||
|
cerr << "usage: p3dcert cert_filename cert_dir\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
wstring cert_filename (argv[0]);
|
||||||
|
wstring cert_dir (argv[1]);
|
||||||
|
|
||||||
|
AuthDialog *dialog = new AuthDialog(cert_filename, cert_dir);
|
||||||
|
dialog->show();
|
||||||
|
|
||||||
|
return Fl::run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // _WIN32
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
OpenSSL_add_all_algorithms();
|
OpenSSL_add_all_algorithms();
|
||||||
|
|
||||||
@ -108,14 +132,20 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
return Fl::run();
|
return Fl::run();
|
||||||
}
|
}
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: AuthDialog::Constructor
|
// Function: AuthDialog::Constructor
|
||||||
// Access: Public
|
// Access: Public
|
||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef _WIN32
|
||||||
|
AuthDialog::
|
||||||
|
AuthDialog(const wstring &cert_filename, const wstring &cert_dir) :
|
||||||
|
#else
|
||||||
AuthDialog::
|
AuthDialog::
|
||||||
AuthDialog(const string &cert_filename, const string &cert_dir) :
|
AuthDialog(const string &cert_filename, const string &cert_dir) :
|
||||||
|
#endif
|
||||||
Fl_Window(435, 242, "New Panda3D Application"),
|
Fl_Window(435, 242, "New Panda3D Application"),
|
||||||
_cert_dir(cert_dir)
|
_cert_dir(cert_dir)
|
||||||
{
|
{
|
||||||
@ -208,41 +238,43 @@ approve_cert() {
|
|||||||
// Look for an unused filename.
|
// Look for an unused filename.
|
||||||
int i = 1;
|
int i = 1;
|
||||||
size_t buf_length = _cert_dir.length() + 100;
|
size_t buf_length = _cert_dir.length() + 100;
|
||||||
char *buf = new char[buf_length];
|
|
||||||
|
// Sure, there's a slight race condition right now: another process
|
||||||
|
// might attempt to create the same filename. So what.
|
||||||
|
FILE *fp = NULL;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
wstring buf_w;
|
wchar_t *buf = new wchar_t[buf_length];
|
||||||
#endif // _WIN32
|
|
||||||
|
while (true) {
|
||||||
|
swprintf(buf, L"%s/p%d.crt", _cert_dir.c_str(), i);
|
||||||
|
assert(wcslen(buf) < buf_length);
|
||||||
|
|
||||||
|
// Check if it already exists. If not, take it.
|
||||||
|
if (GetFileAttributesW(buf) == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
fp = _wfopen(buf, L"w");
|
||||||
|
|
||||||
|
#else // _WIN32
|
||||||
|
char *buf = new char[buf_length];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
sprintf(buf, "%s/p%d.crt", _cert_dir.c_str(), i);
|
sprintf(buf, "%s/p%d.crt", _cert_dir.c_str(), i);
|
||||||
assert(strlen(buf) < buf_length);
|
assert(strlen(buf) < buf_length);
|
||||||
|
|
||||||
// Check if it already exists. If not, take it.
|
// Check if it already exists. If not, take it.
|
||||||
#ifdef _WIN32
|
|
||||||
DWORD results = 0;
|
|
||||||
if (string_to_wstring(buf_w, buf)) {
|
|
||||||
results = GetFileAttributesW(buf_w.c_str());
|
|
||||||
}
|
|
||||||
if (results == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
if (stat(buf, &statbuf) != 0) {
|
if (stat(buf, &statbuf) != 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sure, there's a slight race condition right now: another process
|
|
||||||
// might attempt to create the same filename. So what.
|
|
||||||
FILE *fp = NULL;
|
|
||||||
#ifdef _WIN32
|
|
||||||
fp = _wfopen(buf_w.c_str(), L"w");
|
|
||||||
#else // _WIN32
|
|
||||||
fp = fopen(buf, "w");
|
fp = fopen(buf, "w");
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
PEM_write_X509(fp, _cert);
|
PEM_write_X509(fp, _cert);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
@ -257,14 +289,17 @@ approve_cert() {
|
|||||||
// Description: Reads the list of certificates in the pem filename
|
// Description: Reads the list of certificates in the pem filename
|
||||||
// passed on the command line into _cert and _stack.
|
// passed on the command line into _cert and _stack.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
#ifdef _WIN32
|
||||||
|
void AuthDialog::
|
||||||
|
read_cert_file(const wstring &cert_filename) {
|
||||||
|
#else
|
||||||
void AuthDialog::
|
void AuthDialog::
|
||||||
read_cert_file(const string &cert_filename) {
|
read_cert_file(const string &cert_filename) {
|
||||||
|
#endif
|
||||||
|
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
wstring cert_filename_w;
|
fp = _wfopen(cert_filename.c_str(), L"r");
|
||||||
if (string_to_wstring(cert_filename_w, cert_filename)) {
|
|
||||||
fp = _wfopen(cert_filename_w.c_str(), L"r");
|
|
||||||
}
|
|
||||||
#else // _WIN32
|
#else // _WIN32
|
||||||
fp = fopen(cert_filename.c_str(), "r");
|
fp = fopen(cert_filename.c_str(), "r");
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
@ -53,7 +53,11 @@ class ViewCertDialog;
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
class AuthDialog : public Fl_Window {
|
class AuthDialog : public Fl_Window {
|
||||||
public:
|
public:
|
||||||
|
#ifdef _WIN32
|
||||||
|
AuthDialog(const wstring &cert_filename, const wstring &cert_dir);
|
||||||
|
#else
|
||||||
AuthDialog(const string &cert_filename, const string &cert_dir);
|
AuthDialog(const string &cert_filename, const string &cert_dir);
|
||||||
|
#endif
|
||||||
virtual ~AuthDialog();
|
virtual ~AuthDialog();
|
||||||
|
|
||||||
static void run_clicked(Fl_Widget *w, void *data);
|
static void run_clicked(Fl_Widget *w, void *data);
|
||||||
@ -63,7 +67,11 @@ public:
|
|||||||
void approve_cert();
|
void approve_cert();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef _WIN32
|
||||||
|
void read_cert_file(const wstring &cert_filename);
|
||||||
|
#else
|
||||||
void read_cert_file(const string &cert_filename);
|
void read_cert_file(const string &cert_filename);
|
||||||
|
#endif
|
||||||
void get_friendly_name();
|
void get_friendly_name();
|
||||||
void verify_cert();
|
void verify_cert();
|
||||||
int load_certificates_from_der_ram(X509_STORE *store,
|
int load_certificates_from_der_ram(X509_STORE *store,
|
||||||
@ -76,7 +84,11 @@ public:
|
|||||||
ViewCertDialog *_view_cert_dialog;
|
ViewCertDialog *_view_cert_dialog;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef _WIN32
|
||||||
|
wstring _cert_dir;
|
||||||
|
#else
|
||||||
string _cert_dir;
|
string _cert_dir;
|
||||||
|
#endif
|
||||||
X509 *_cert;
|
X509 *_cert;
|
||||||
STACK_OF(X509) *_stack;
|
STACK_OF(X509) *_stack;
|
||||||
|
|
||||||
|
@ -4455,7 +4455,7 @@ if (RTDIST or RUNTIME):
|
|||||||
TargetAdd('p3dcert.exe', input='plugin_mkdir_complete.obj')
|
TargetAdd('p3dcert.exe', input='plugin_mkdir_complete.obj')
|
||||||
TargetAdd('p3dcert.exe', input='plugin_wstring_encode.obj')
|
TargetAdd('p3dcert.exe', input='plugin_wstring_encode.obj')
|
||||||
TargetAdd('p3dcert.exe', input='plugin_p3dCert.obj')
|
TargetAdd('p3dcert.exe', input='plugin_p3dCert.obj')
|
||||||
OPTS=['OPENSSL', 'FLTK', 'WINCOMCTL', 'WINSOCK', 'WINGDI', 'WINUSER', 'ADVAPI', 'WINOLE', 'WINSHELL']
|
OPTS=['OPENSSL', 'FLTK', 'WINCOMCTL', 'WINSOCK', 'WINGDI', 'WINUSER', 'ADVAPI', 'WINOLE', 'WINSHELL', 'SUBSYSTEM:WINDOWS']
|
||||||
if GetTarget() == 'darwin':
|
if GetTarget() == 'darwin':
|
||||||
OPTS += ['OPT:2']
|
OPTS += ['OPT:2']
|
||||||
TargetAdd('p3dcert.exe', opts=OPTS)
|
TargetAdd('p3dcert.exe', opts=OPTS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user