Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dadigang
Ventoy
Commits
471432fc
Commit
471432fc
authored
Sep 22, 2021
by
longpanda
Browse files
Optimization for VentoyGUI
parent
a78e1960
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
183 additions
and
11 deletions
+183
-11
INSTALL/ventoy_pack.sh
INSTALL/ventoy_pack.sh
+4
-3
LinuxGUI/Ventoy2Disk/QT/main.cpp
LinuxGUI/Ventoy2Disk/QT/main.cpp
+26
-0
LinuxGUI/Ventoy2Disk/main_gtk.c
LinuxGUI/Ventoy2Disk/main_gtk.c
+61
-0
LinuxGUI/Ventoy2Disk/ventoy_gui.c
LinuxGUI/Ventoy2Disk/ventoy_gui.c
+92
-8
No files found.
INSTALL/ventoy_pack.sh
View file @
471432fc
...
...
@@ -107,7 +107,7 @@ cp $OPT Ventoy2Disk.sh $tmpdir/
cp
$OPT
VentoyWeb.sh
$tmpdir
/
cp
$OPT
VentoyGUI
*
$tmpdir
/
#cp $OPT Ventoy.desktop $tmpdir/
cp
$OPT
README
$tmpdir
/
cp
$OPT
plugin
$tmpdir
/
cp
$OPT
CreatePersistentImg.sh
$tmpdir
/
...
...
@@ -115,7 +115,7 @@ cp $OPT ExtendPersistentImg.sh $tmpdir/
dos2unix
-q
$tmpdir
/Ventoy2Disk.sh
dos2unix
-q
$tmpdir
/VentoyWeb.sh
#dos2unix -q $tmpdir/Ventoy.desktop
dos2unix
-q
$tmpdir
/CreatePersistentImg.sh
dos2unix
-q
$tmpdir
/ExtendPersistentImg.sh
...
...
@@ -156,7 +156,7 @@ chmod +x $tmpdir/VentoyGUI*
cp
$OPT
$LANG_DIR
/languages.json
$tmpdir
/tool/
#chmod +x $tmpdir/Ventoy.desktop
chmod
+x
$tmpdir
/CreatePersistentImg.sh
chmod
+x
$tmpdir
/ExtendPersistentImg.sh
...
...
@@ -169,6 +169,7 @@ cp $OPT Ventoy2Disk*.exe $tmpdir/
cp
$OPT
$LANG_DIR
/languages.json
$tmpdir
/ventoy/
rm
-rf
$tmpdir
/tool
rm
-f
$tmpdir
/
*
.sh
rm
-f
$tmpdir
/VentoyGUI.
*
rm
-rf
$tmpdir
/WebUI
rm
-f
$tmpdir
/README
...
...
LinuxGUI/Ventoy2Disk/QT/main.cpp
View file @
471432fc
...
...
@@ -4,6 +4,7 @@
#include <QMessageBox>
#include <QFileInfo>
#include <QStyle>
#include <QDir>
#include <QDesktopWidget>
#include <QPixmap>
#include <unistd.h>
...
...
@@ -23,6 +24,7 @@ char g_ini_file[4096];
int
main
(
int
argc
,
char
*
argv
[])
{
int
ret
;
long
long
size
;
QApplication
a
(
argc
,
argv
);
Ventoy2DiskWindow
w
;
...
...
@@ -34,6 +36,21 @@ int main(int argc, char *argv[])
}
#endif
if
(
!
QFileInfo
::
exists
(
"./boot/boot.img"
))
{
QString
curdir
=
a
.
applicationDirPath
();
int
index
=
curdir
.
indexOf
(
"/tool/"
);
if
(
index
>=
0
)
{
QDir
::
setCurrent
(
curdir
.
left
(
index
));
}
else
{
QDir
::
setCurrent
(
curdir
);
}
}
if
(
!
QFileInfo
::
exists
(
"./boot/boot.img"
))
{
QMessageBox
::
critical
(
NULL
,
"Error"
,
"Please run under the correct directory."
);
...
...
@@ -56,9 +73,18 @@ int main(int argc, char *argv[])
}
}
QFileInfo
Info
(
g_log_file
);
size
=
(
long
long
)
Info
.
size
();
if
(
size
>=
4
*
SIZE_1MB
)
{
QFile
::
remove
(
g_log_file
);
}
vlog
(
"===================================================
\n
"
);
vlog
(
"===== Ventoy2Disk %s powered by QT %s =====
\n
"
,
ventoy_get_local_version
(),
qVersion
());
vlog
(
"===================================================
\n
"
);
vlog
(
"log file is <%s> lastsize:%lld
\n
"
,
g_log_file
,
(
long
long
)
size
);
vlog
(
"ini file is <%s>
\n
"
,
g_ini_file
);
ventoy_disk_init
();
ventoy_http_init
();
...
...
LinuxGUI/Ventoy2Disk/main_gtk.c
View file @
471432fc
...
...
@@ -9,6 +9,7 @@
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/limits.h>
#include <ventoy_define.h>
#include <ventoy_util.h>
...
...
@@ -56,6 +57,49 @@ int early_msgbox(GtkMessageType type, GtkButtonsType buttons, const char *str)
return
ret
;
}
static
int
adjust_cur_dir
(
char
*
argv0
)
{
int
ret
=
2
;
char
c
;
char
*
pos
=
NULL
;
char
*
end
=
NULL
;
if
(
argv0
[
0
]
==
'.'
)
{
return
1
;
}
for
(
pos
=
argv0
;
pos
&&
*
pos
;
pos
++
)
{
if
(
*
pos
==
'/'
)
{
end
=
pos
;
}
}
if
(
end
)
{
c
=
*
end
;
*
end
=
0
;
pos
=
strstr
(
argv0
,
"/tool/"
);
if
(
pos
)
{
*
pos
=
0
;
}
ret
=
chdir
(
argv0
);
*
end
=
c
;
if
(
pos
)
{
*
pos
=
'/'
;
}
}
return
ret
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
...
...
@@ -64,6 +108,7 @@ int main(int argc, char *argv[])
GtkWidget
*
pWidget
=
NULL
;
GtkBuilder
*
pBuilder
=
NULL
;
GError
*
error
=
NULL
;
struct
stat
logstat
;
gtk_init
(
&
argc
,
&
argv
);
...
...
@@ -74,6 +119,11 @@ int main(int argc, char *argv[])
return
EACCES
;
}
if
(
access
(
"./boot/boot.img"
,
F_OK
)
==
-
1
)
{
adjust_cur_dir
(
argv
[
0
]);
}
if
(
access
(
"./boot/boot.img"
,
F_OK
)
==
-
1
)
{
early_msgbox
(
GTK_MESSAGE_ERROR
,
GTK_BUTTONS_CLOSE
,
"Please run under the correct directory."
);
...
...
@@ -94,11 +144,22 @@ int main(int argc, char *argv[])
}
}
memset
(
&
logstat
,
0
,
sizeof
(
logstat
));
if
(
0
==
stat
(
g_log_file
,
&
logstat
))
{
if
(
logstat
.
st_size
>=
4
*
SIZE_1MB
)
{
remove
(
g_log_file
);
}
}
ventoy_log_init
();
vlog
(
"================================================
\n
"
);
vlog
(
"===== Ventoy2Disk %s powered by GTK%d.x =====
\n
"
,
ventoy_get_local_version
(),
GTK_MAJOR_VERSION
);
vlog
(
"================================================
\n
"
);
vlog
(
"log file is <%s> lastsize:%lld
\n
"
,
g_log_file
,
(
long
long
)
logstat
.
st_size
);
vlog
(
"ini file is <%s>
\n
"
,
g_ini_file
);
ventoy_disk_init
();
...
...
LinuxGUI/Ventoy2Disk/ventoy_gui.c
View file @
471432fc
...
...
@@ -33,7 +33,10 @@
#define LD_CACHE_FILE "/etc/ld.so.cache"
#define INT2STR_YN(a) ((a) == 0 ? "NO" : "YES")
static
int
g_xdg_log
=
0
;
static
int
g_xdg_ini
=
0
;
static
char
g_log_file
[
PATH_MAX
];
static
char
g_ini_file
[
PATH_MAX
];
static
char
*
g_log_buf
=
NULL
;
extern
char
**
environ
;
...
...
@@ -499,6 +502,7 @@ static int restart_main(int argc, char **argv, char *guiexe)
if
(
envs
)
{
vlog
(
"recover success, argc=%d evecve <%s>
\n
"
,
j
,
guiexe
);
dump_args
(
"EXECVE"
,
newargv
);
execve
(
guiexe
,
newargv
,
envs
);
}
else
...
...
@@ -584,12 +588,36 @@ static int restart_by_pkexec(int argc, char **argv, const char *curpath, const c
newargv
[
j
++
]
=
pkexec
;
newargv
[
j
++
]
=
path
;
for
(
i
=
1
;
i
<
argc
&&
j
<
MAX_PARAS
-
2
;
i
++
)
for
(
i
=
1
;
i
<
argc
&&
j
<
MAX_PARAS
;
i
++
)
{
if
(
strcmp
(
argv
[
i
],
"--xdg"
)
==
0
)
{
continue
;
}
newargv
[
j
++
]
=
argv
[
i
];
}
newargv
[
j
++
]
=
create_environ_param
(
VTOY_ENV_STR
,
environ
);
newargv
[
j
++
]
=
exepara
;
if
(
j
<
MAX_PARAS
)
{
newargv
[
j
++
]
=
create_environ_param
(
VTOY_ENV_STR
,
environ
);
}
if
(
j
<
MAX_PARAS
)
{
newargv
[
j
++
]
=
exepara
;
}
if
(
g_xdg_log
&&
j
+
1
<
MAX_PARAS
)
{
newargv
[
j
++
]
=
"-l"
;
newargv
[
j
++
]
=
g_log_file
;
}
if
(
g_xdg_ini
&&
j
+
1
<
MAX_PARAS
)
{
newargv
[
j
++
]
=
"-i"
;
newargv
[
j
++
]
=
g_ini_file
;
}
dump_args
(
"PKEXEC"
,
newargv
);
execv
(
pkexec
,
newargv
);
...
...
@@ -962,8 +990,9 @@ static int distro_check_gui_env(char *type, int len, int *pver)
return
pstNode
?
1
:
0
;
}
static
int
detect_gui_exe_path
(
const
char
*
curpath
,
char
*
pathbuf
,
int
buflen
)
static
int
detect_gui_exe_path
(
int
argc
,
char
**
argv
,
const
char
*
curpath
,
char
*
pathbuf
,
int
buflen
)
{
int
i
;
int
ret
;
int
ver
;
int
libflag
=
0
;
...
...
@@ -971,8 +1000,46 @@ static int detect_gui_exe_path(const char *curpath, char *pathbuf, int buflen)
char
line
[
256
];
mode_t
mode
;
struct
stat
filestat
;
if
(
access
(
"./ventoy_gui_type"
,
F_OK
)
!=
-
1
)
for
(
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
argv
[
i
]
&&
strcmp
(
argv
[
i
],
"--gtk2"
)
==
0
)
{
guitype
=
"gtk"
;
ver
=
2
;
}
else
if
(
argv
[
i
]
&&
strcmp
(
argv
[
i
],
"--gtk3"
)
==
0
)
{
guitype
=
"gtk"
;
ver
=
3
;
}
else
if
(
argv
[
i
]
&&
strcmp
(
argv
[
i
],
"--gtk4"
)
==
0
)
{
guitype
=
"gtk"
;
ver
=
4
;
}
else
if
(
argv
[
i
]
&&
strcmp
(
argv
[
i
],
"--qt4"
)
==
0
)
{
guitype
=
"qt"
;
ver
=
4
;
}
else
if
(
argv
[
i
]
&&
strcmp
(
argv
[
i
],
"--qt5"
)
==
0
)
{
guitype
=
"qt"
;
ver
=
5
;
}
else
if
(
argv
[
i
]
&&
strcmp
(
argv
[
i
],
"--qt6"
)
==
0
)
{
guitype
=
"qt"
;
ver
=
6
;
}
}
if
(
guitype
)
{
vlog
(
"Get GUI type from param <%s%d>.
\n
"
,
guitype
,
ver
);
}
else
if
(
access
(
"./ventoy_gui_type"
,
F_OK
)
!=
-
1
)
{
vlog
(
"Get GUI type from ventoy_gui_type file.
\n
"
);
...
...
@@ -1113,6 +1180,7 @@ int real_main(int argc, char **argv)
vlog
(
"=============== VentoyGui %s ===============
\n
"
,
VTOY_GUI_ARCH
);
vlog
(
"=========================================================
\n
"
);
vlog
(
"=========================================================
\n
"
);
vlog
(
"log file is <%s>
\n
"
,
g_log_file
);
euid
=
geteuid
();
getcwd
(
curpath
,
sizeof
(
curpath
));
...
...
@@ -1145,7 +1213,7 @@ int real_main(int argc, char **argv)
return
1
;
}
if
(
detect_gui_exe_path
(
curpath
,
path
,
sizeof
(
path
)))
if
(
detect_gui_exe_path
(
argc
,
argv
,
curpath
,
path
,
sizeof
(
path
)))
{
return
1
;
}
...
...
@@ -1154,7 +1222,6 @@ int real_main(int argc, char **argv)
{
vlog
(
"We have root privileges, just exec %s
\n
"
,
path
);
argv
[
0
]
=
path
;
argv
[
1
]
=
NULL
;
execv
(
argv
[
0
],
argv
);
}
else
...
...
@@ -1176,6 +1243,7 @@ int main(int argc, char **argv)
{
int
i
;
int
ret
;
const
char
*
env
=
NULL
;
snprintf
(
g_log_file
,
sizeof
(
g_log_file
),
"log.txt"
);
for
(
i
=
0
;
i
<
argc
;
i
++
)
...
...
@@ -1185,6 +1253,22 @@ int main(int argc, char **argv)
snprintf
(
g_log_file
,
sizeof
(
g_log_file
),
"%s"
,
argv
[
i
+
1
]);
break
;
}
else
if
(
argv
[
i
]
&&
strcmp
(
argv
[
i
],
"--xdg"
)
==
0
)
{
env
=
getenv
(
"XDG_CACHE_HOME"
);
if
(
env
)
{
g_xdg_log
=
1
;
snprintf
(
g_log_file
,
sizeof
(
g_log_file
),
"%s/ventoy.log"
,
env
);
}
env
=
getenv
(
"XDG_CONFIG_HOME"
);
if
(
env
)
{
g_xdg_ini
=
1
;
snprintf
(
g_ini_file
,
sizeof
(
g_ini_file
),
"%s/Ventoy2Disk.ini"
,
env
);
}
}
}
g_log_buf
=
malloc
(
MAX_LOG_BUF
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment