3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
4 * Copyright (C) 2010 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <sys/ioctl.h>
37 #define IMAGE_FILE "inst.img"
39 void zinstall_draw_step1 ()
41 zgui_puts (10, 40, "First step is focused on hard-drive ID,\nthat mean, you must select\n correct disk for installation.\n\n", 0);
43 zgui_input (10, 80, &zinst
.drive
, 31, 0);
46 void zinstall_draw_step2 ()
48 zgui_puts (10, 40, "Are you sure you want overwrite\nall data on selected drive ?", 0);
50 zgui_puts (20, 80, zinst
.drive
, 0);
55 zinst
.fd
= open (IMAGE_FILE
, O_RDONLY
);
58 printf ("ERROR -> image file '%s' not found\n", IMAGE_FILE
);
61 printf ("zinst.fd: %d\n", zinst
.fd
);
63 zinst
.flen
= 2048*1024; /* 2MB image */
65 printf ("Image size: %dkB\n", zinst
.flen
/1024);
67 unsigned l
= strlen (zinst
.drive
);
68 memcpy (zinst
.rq
.dev
, zinst
.drive
, l
);
69 zinst
.rq
.dev
[l
] = '\0';
76 void zinstall_close ()
81 int zinstall_draw_step3 ()
83 unsigned char percent
= zinst
.s
/41+1;
86 sprintf (str
, "Installing: %d %c", zinst
.s
/41+1, '%');
87 zgui_puts (10, 40, str
, 0);
89 xrectfill (zinst
.appcl
->x
+50, zinst
.appcl
->y
+75, zinst
.appcl
->x
+50+percent
*2, zinst
.appcl
->y
+87, 0xffa000);
90 xrectfill (zinst
.appcl
->x
+50+percent
*2, zinst
.appcl
->y
+75, zinst
.appcl
->x
+250, zinst
.appcl
->y
+87, 0x0000ff);
92 if (zinst
.s
>= zinst
.flen
/512)
95 zinst
.rq
.sector
= zinst
.s
++;
97 memset (zinst
.rq
.data
, 0, 512);
99 int l
= read (zinst
.fd
, zinst
.rq
.data
, 512);
102 printf ("ERROR -> read () == 0; image data are probably corrupted\n");
106 int r
= ioctl (IOATAWRITE
, &zinst
.rq
, sizeof (struct ioatarq_t
));
109 printf ("WARNING -> ioctl (IOATAWRITE) == -1; repeating\n");
111 r
= ioctl (IOATAWRITE
, &zinst
.rq
, sizeof (struct ioatarq_t
));
113 printf ("ERROR -> ioctl (IOATAWRITE) == -1; installation failed !\n");
121 void zinstall_draw_step4 ()
123 zgui_puts (10, 40, "Installation was finished\nCongratulation !", 0);
126 void zinstall_draw ()
128 zgui_puts (10, 10, "ZeX/OS Installer\n-=-=-=-=-=-=-=-=-", 0);
130 unsigned btn_next
= zgui_button (150, 145, "Next");
132 if (!btn_next
&& zinst
.step
< 4) {
135 if (zinst
.step
== 3) {
136 int r
= zinstall_open ();
140 } else if (zinst
.step
== 4)
144 switch (zinst
.step
) {
146 zgui_puts (10, 40, "Welcome !\nYou are attempting to install ZeX/OS\nonto your hard-drive, please be sure\nabout your backup because of data loss.\n\nWarning: This version is in the alpha-stage,\nit is possible that some error may occur.\n\nPress button \"Next\" for continue\nin installation process", 0);
149 return zinstall_draw_step1 ();
151 return zinstall_draw_step2 ();
154 int r
= zinstall_draw_step3 ();
161 return zinstall_draw_step4 ();
163 zgui_puts (10, 40, "Installation failed !\nprobably installer files are missing", 0);
168 int main (int argc
, char **argv
)
173 memcpy (zinst
.drive
, "/dev/hda", 8);
174 zinst
.drive
[8] = '\0';
176 if (zgui_init () == -1)
179 zinst
.appcl
= zgui_window ();
182 unsigned state
= zgui_event ();
184 if (state
& APPCL_STATE_REDRAW
)
187 if (state
& APPCL_STATE_EXIT
)