]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - LinuxGUI/Ventoy2Disk/main_webui.c
Add /F option for VentoyPlugson.exe to use the system default browser.
[Ventoy.git] / LinuxGUI / Ventoy2Disk / main_webui.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <string.h>
5 #include <errno.h>
6 #include <ctype.h>
7 #include <unistd.h>
8 #include <fcntl.h>
9 #include <sys/wait.h>
10 #include <sys/types.h>
11 #include <linux/limits.h>
12 #include <ventoy_define.h>
13 #include <ventoy_util.h>
14 #include <ventoy_json.h>
15 #include <ventoy_disk.h>
16 #include <ventoy_http.h>
17
18 char g_log_file[PATH_MAX];
19 char g_ini_file[PATH_MAX];
20
21 int ventoy_log_init(void);
22 void ventoy_log_exit(void);
23
24 void ventoy_signal_stop(int sig)
25 {
26 vlog("ventoy server exit due to signal ...\n");
27 printf("ventoy server exit ...\n");
28
29 ventoy_http_stop();
30 ventoy_http_exit();
31 ventoy_disk_exit();
32 ventoy_log_exit();
33 exit(0);
34 }
35
36 int main(int argc, char **argv)
37 {
38 int i;
39 int rc;
40 const char *ip = "127.0.0.1";
41 const char *port = "24680";
42
43 if (argc != 3)
44 {
45 printf("Invalid argc %d\n", argc);
46 return 1;
47 }
48
49 if (isdigit(argv[1][0]))
50 {
51 ip = argv[1];
52 }
53
54 if (isdigit(argv[2][0]))
55 {
56 port = argv[2];
57 }
58
59 snprintf(g_log_file, sizeof(g_log_file), "log.txt");
60 snprintf(g_ini_file, sizeof(g_ini_file), "./Ventoy2Disk.ini");
61 for (i = 0; i < argc; i++)
62 {
63 if (argv[i] && argv[i + 1] && strcmp(argv[i], "-l") == 0)
64 {
65 snprintf(g_log_file, sizeof(g_log_file), "%s", argv[i + 1]);
66 }
67 else if (argv[i] && argv[i + 1] && strcmp(argv[i], "-i") == 0)
68 {
69 snprintf(g_ini_file, sizeof(g_ini_file), "%s", argv[i + 1]);
70 }
71 }
72
73 ventoy_log_init();
74
75 vlog("===============================================\n");
76 vlog("===== Ventoy2Disk %s %s:%s =====\n", ventoy_get_local_version(), ip, port);
77 vlog("===============================================\n");
78
79 ventoy_disk_init();
80
81 ventoy_http_init();
82
83 rc = ventoy_http_start(ip, port);
84 if (rc)
85 {
86 printf("Ventoy failed to start http server, check log.txt for detail\n");
87 }
88 else
89 {
90 signal(SIGINT, ventoy_signal_stop);
91 signal(SIGTSTP, ventoy_signal_stop);
92 signal(SIGQUIT, ventoy_signal_stop);
93 while (1)
94 {
95 sleep(100);
96 }
97 }
98
99 return 0;
100 }
101