-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
181 lines (149 loc) · 4.98 KB
/
main.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Author: Copyright (C) Andrzej Surowiec 2012
*
*
* This file is part of GPF Crypto Stick.
*
* GPF Crypto Stick is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* GPF Crypto Stick is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPF Crypto Stick. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QApplication>
#include <QSharedMemory>
#include <QDebug>
#include "mainwindow.h"
#include "device.h"
#include "stick20hid.h"
/*******************************************************************************
External declarations
*******************************************************************************/
/*******************************************************************************
Local defines
*******************************************************************************/
/*******************************************************************************
HelpInfos
Changes
Date Author Info
09.07.14 RB Function created
Reviews
Date Reviewer Info
*******************************************************************************/
void HelpInfos (void)
{
printf ("Crypto Stick GUI\n");
printf ("\n");
printf ("-h, --help This help\n");
printf ("-a, --admin Enable extra functions in the GUI for administrators.\n");
printf ("-d, --debug Enable debug options\n");
printf ("--debugAll Enable extensive debug options\n");
printf ("--lock-hardware Enable menu entry for hardware lock\n");
/* Disable password matrix
printf ("--PWM Enable PIN entry via matrix\n");
*/
printf ("--cmd .... Start a command line command\n");
printf ("\n");
}
/*******************************************************************************
main
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int main(int argc, char *argv[])
{
int i;
//int DebugWindowActive;
//int SpecialConfigActive;
char *p;
StartUpParameter_tst StartupInfo_st;
QApplication a(argc, argv);
// Check for multiple instances
// GUID from http://www.guidgenerator.com/online-guid-generator.aspx
QSharedMemory shared("6b50960df-f5f3-4562-bbdc-84c3bc004ef4");
if( !shared.create( 512, QSharedMemory::ReadWrite) )
{
// An instance is already running. Quit the current instance
QMessageBox msgBox;
msgBox.setText( QObject::tr("Can't start more than one instance of the application.") );
msgBox.setIcon( QMessageBox::Critical );
msgBox.exec();
exit(0);
}
else {
qDebug() << "Application started successfully.";
}
StartupInfo_st.ExtendedConfigActive = FALSE;
StartupInfo_st.FlagDebug = DEBUG_STATUS_NO_DEBUGGING;
StartupInfo_st.PasswordMatrix = FALSE;
StartupInfo_st.LockHardware = FALSE;
StartupInfo_st.Cmd = FALSE;
HID_Stick20Init ();
// Check for commandline parameter
// if (2 == argc)
for (i=2;i<=argc;i++)
{
p = argv[i-1];
if ((0 == strcmp (p,"--help")) || (0 == strcmp (p,"-h")))
{
HelpInfos ();
exit (0);
}
if ((0 == strcmp (p,"--debug")) || (0 == strcmp (p,"-d")))
{
StartupInfo_st.FlagDebug = DEBUG_STATUS_LOCAL_DEBUG;
}
if (0 == strcmp (p,"--debugAll"))
{
StartupInfo_st.FlagDebug = DEBUG_STATUS_DEBUG_ALL;
}
if ((0 == strcmp (p,"--admin")) || (0 == strcmp (p,"-a")))
{
StartupInfo_st.ExtendedConfigActive = TRUE;
}
/* Disable password matrix
if (0 == strcmp (p,"--PWM"))
{
StartupInfo_st.PasswordMatrix = TRUE;
}
*/
if (0 == strcmp (p,"--lock-hardware"))
{
StartupInfo_st.LockHardware = TRUE;
}
if (0 == strcmp (p,"--cmd"))
{
StartupInfo_st.Cmd = TRUE;
i++;
if (i > argc)
{
fprintf (stderr,"ERROR: Can't get command\n");
fflush(stderr);
exit (1);
}
else
{
p = argv[i-1];
StartupInfo_st.CmdLine = p;
}
}
}
MainWindow w(&StartupInfo_st);
//w.show();
/*
QTime midnight(0, 0, 0);
qsrand(midnight.secsTo(QTime::currentTime()));
*/
QDateTime local(QDateTime::currentDateTime());
qsrand (local.currentMSecsSinceEpoch() % 2000000000);
a.setQuitOnLastWindowClosed(false);
return a.exec();
}