; ------------------------------------------------------------------------- ; creates a fli4l-floppy __FLI4LVER__ ; ; Creation: lanspezi 2005-04-04 ; $Id$ ; ------------------------------------------------------------------------- #include-once Func mkfloppy () msg_lang_read ("mkfloppy") Global $_bool_usercancel Global $_bool_abort Global $progressbar Global $_floppytotalspace Global $_floppyclustersize Dim $_msg_error $_msg_error = "" $_bool_usercancel = "false" $_bool_abort = "false" $progressbar = GUICtrlCreateProgress (70,430,520,20) GUICtrlSetData ($progressbar,0) $icon = GUICtrlCreateIcon ("windows\scripts\ico_floppy.ico",-1, 20,422,32,32) $message = @CRLF & $MSG_LINE & @CRLF & $MSG_05_start & " " fli4lbuild_msg ($message ,1) Dim $_floppy_dual If $boot_type = "dual1440" OR _ $boot_type = "dual1680" OR _ $boot_type = "dualfd" OR _ $boot_type = "fdx2" then mk_floppy_dual () else mk_floppy_single () EndIf If $_bool_abort = "false" AND $_bool_usercancel = "false" Then GUICtrlSetData ($progressbar,100) If $verbose = "true" then $msg = @CRLF & $MSG_05_finish1 Else $msg = $MSG_finished EndIf $msg = $msg & @CRLF & $MSG_LINE & @CRLF & $MSG_05_finish2 & @CRLF fli4lbuild_msg ($msg,1) EndIf If $_bool_abort = "true" then $msg = @CRLF & $MSG_05_error & @CRLF fli4lbuild_errmsg ($msg,0) fli4lbuild_msg ($msg,1) EndIf If $_bool_usercancel = "true" then $msg = $MSG_05_cancel & @CRLF fli4lbuild_errmsg ($msg,0) fli4lbuild_msg ($MSG_cancel & @CRLF, 1) EndIf sleep (2000) GUICtrlDelete ($progressbar) GUICtrlDelete ($icon) EndFunc Func mk_floppy_single () Dim $floppyfiles[5][3] $floppyfiles[0][0] = "\syslinux.cfg" $floppyfiles[0][1] = "\SYSLINUX.CFG" $floppyfiles[0][2] = $MSG_05_copysyslinux $floppyfiles[1][0] = "\kernel" $floppyfiles[1][1] = "\KERNEL" $floppyfiles[1][2] = $MSG_05_copykernel $floppyfiles[2][0] = "\rootfs.img" $floppyfiles[2][1] = "\ROOTFS.IMG" $floppyfiles[2][2] = $MSG_05_copyrootfstgz $floppyfiles[3][0] = "\rc.cfg" $floppyfiles[3][1] = "\RC.CFG" $floppyfiles[3][2] = $MSG_05_copyrccfg $floppyfiles[4][0] = "\opt.img" $floppyfiles[4][1] = "\OPT.IMG" $floppyfiles[4][2] = $MSG_05_copyopttarbz2 $msg = $MSG_05_insertfloppy & @CRLF & @CRLF & $MSG_05_startcopy $res1 = MsgBox (1 + 64,$MSG_msgbox_info, $msg) If $res1 = 1 then $val = delete_floppyfiles ("") If $val = 0 then $val1 = syslinux () If $val1 = 0 Then fli4lbuild_msg (@CRLF & $MSG_05_calculatespace & " " ,0) $_filesize=FileGetSize($drive & "\LDLINUX.SYS") $_filespace = (Int($_filesize/$_floppyclustersize) + _ (Mod($_filesize,$_floppyclustersize)<>0)) * $_floppyclustersize For $_n = 0 to 4 $_filesize=FileGetSize($glob_dir_tmpbuild & $floppyfiles[$_n][0]) $_filespace = $_filespace + (Int($_filesize/$_floppyclustersize) + _ (Mod($_filesize,$_floppyclustersize)<>0)) * $_floppyclustersize Next If $_filespace <= $_floppytotalspace then fli4lbuild_msg ($MSG_finished, 0) For $_n = 0 to 4 fli4lbuild_msg (@CRLF & $floppyfiles[$_n][2] & " " ,0) $res2 = write_file_to_floppy ($glob_dir_tmpbuild & $floppyfiles[$_n][0], $drive & _ $floppyfiles[$_n][1]) If $res2 = -1 then $_bool_abort = "true" ExitLoop EndIf GUICtrlSetData ($progressbar,($_n + 1) * 20 - 10) fli4lbuild_msg ($MSG_finished,0) Next Else $_bool_abort = "true" fli4lbuild_msg ($MSG_cancel & @CRLF,1) $msg = $MSG_05_floppynospace & @CRLF & $MSG_05_requiredspace1 & " " & $_filespace & " " & $MSG_05_requiredspace2 $msg=$msg & @CRLF & $MSG_05_requiredspace3 & " " & $_floppytotalspace & " " & $MSG_05_requiredspace2 fli4lbuild_errmsg ($msg, 1) fli4lbuild_msg ($msg, 1) EndIf Else ; syslinux error $_bool_abort = "true" EndIf Else $_bool_usercancel = "true" EndIf Else $_bool_usercancel = "true" EndIf EndFunc Func mk_floppy_dual () Dim $floppy1files[5][3] $floppy1files[0][0] = "\syslinux.cfg" $floppy1files[0][1] = "\SYSLINUX.CFG" $floppy1files[0][2] = $MSG_05_copysyslinux $floppy1files[1][0] = "\kernel" $floppy1files[1][1] = "\KERNEL" $floppy1files[1][2] = $MSG_05_copykernel $floppy1files[2][0] = "\rootfs.img" $floppy1files[2][1] = "\ROOTFS.IMG" $floppy1files[2][2] = $MSG_05_copyrootfstgz $floppy1files[3][0] = "\rc.cfg" $floppy1files[3][1] = "\RC.CFG" $floppy1files[3][2] = $MSG_05_copyrccfg $floppy1files[4][0] = "\opt_tbz2.1" $floppy1files[4][1] = "\OPT.IMG" $floppy1files[4][2] = $MSG_05_copyopttarbz2 Dim $floppy2files[1][3] $floppy2files[0][0] = "\opt_tbz2.2" $floppy2files[0][1] = "\OPT.IMG" $floppy2files[0][2] = $MSG_05_copyopttarbz2 $msg = $MSG_05_insertfloppy & @CRLF & $MSG_05_bootdisk & @CRLF & @CRLF & $MSG_05_startcopy $res1 = MsgBox (1 + 64,$MSG_msgbox_info, $msg) If $res1 = 1 then $val = delete_floppyfiles ("BOOT") If $val = 0 then fli4lbuild_msg (@CRLF,0) fli4lbuild_msg ($MSG_05_bootdisk2 & " ... ",1) $val1 = syslinux () If $val1 = 0 Then fli4lbuild_msg (@CRLF & $MSG_05_calculatespace & " " ,0) $_filesize=FileGetSize($drive & "\LDLINUX.SYS") $_filespace = (Int($_filesize/$_floppyclustersize) + _ (Mod($_filesize,$_floppyclustersize)<>0)) * $_floppyclustersize For $_n = 0 to 3 $_filesize=FileGetSize($glob_dir_tmpbuild & $floppy1files[$_n][0]) $_filespace = $_filespace + (Int($_filesize/$_floppyclustersize) + _ (Mod($_filesize,$_floppyclustersize)<>0)) * $_floppyclustersize Next If $_filespace > $_floppytotalspace Then $_bool_abort = "true" fli4lbuild_msg ($MSG_cancel & @CRLF,1) $msg = $MSG_05_bootflnospace & @CRLF & $MSG_05_requiredspace1 & " " & $_filespace & " " & $MSG_05_requiredspace2 $msg=$msg & @CRLF & $MSG_05_requiredspace3 & " " & $_floppytotalspace & " " & $MSG_05_requiredspace2 fli4lbuild_errmsg ($msg, 1) fli4lbuild_msg ($msg, 1) Else $_filesize=FileGetSize($glob_dir_tmpbuild & "\opt.img") $_filespace = $_filespace + (Int($_filesize/$_floppyclustersize) + _ (Mod($_filesize,$_floppyclustersize)<>0)) * $_floppyclustersize $preserve = 0 ; default read_var_from_base ("PRESERVE=", $preserve) $preserve = (Int($preserve/$_floppyclustersize) + _ (Mod($preserve,$_floppyclustersize)<>0)) * $_floppyclustersize If $preserve > $_floppytotalspace Then $preserve = $_floppytotalspace EndIf $_filespace = $_filespace + $preserve If $_filespace <= $_floppytotalspace * 2 then ; assume both floppies formatted identical fli4lbuild_msg ($MSG_finished, 0) For $_n = 0 to 3 fli4lbuild_msg (@CRLF & $floppy1files[$_n][2] & " ",0) $res2 = write_file_to_floppy ($glob_dir_tmpbuild & $floppy1files[$_n][0], $drive & _ $floppy1files[$_n][1]) If $res2 = -1 then $_bool_abort = "true" fli4lbuild_msg ($MSG_cancel,0) ExitLoop EndIf GUICtrlSetData ($progressbar,($_n + 1) * 15) fli4lbuild_msg ($MSG_finished,0) Next Else $_bool_abort = "true" fli4lbuild_msg ($MSG_cancel & @CRLF,1) $msg = $MSG_05_floppynospace & @CRLF & $MSG_05_requiredspace1 & " " & $_filespace & " " & $MSG_05_requiredspace2 $msg=$msg & @CRLF & $MSG_05_requiredspace3 & " " & 2 * $_floppytotalspace & " " & $MSG_05_requiredspace2 fli4lbuild_errmsg ($msg, 1) fli4lbuild_msg ($msg, 1) EndIf EndIf Else ; syslinux error $_bool_abort = "true" EndIf Else $_bool_usercancel = "true" EndIf If $_bool_abort = "false" AND $_bool_usercancel = "false" Then GUICtrlSetData ($progressbar,70) $run_call = StringFormat ('windows\\diskfill.exe "%s\\opt.img" %s "%s%s" "%s%s" %s', _ $glob_dir_tmpbuild, $drive, $glob_dir_tmpbuild, $floppy1files[4][0], $glob_dir_tmpbuild, $floppy2files[0][0], $preserve) $val = RunWait ($run_call, @WorkingDir, @SW_HIDE) If $val = 0 then $res2 = 0 If FileExists ($glob_dir_tmpbuild & $floppy1files[4][0]) then fli4lbuild_msg (@CRLF & $floppy1files[4][2] & " ",0) $res2 = write_file_to_floppy ($glob_dir_tmpbuild & $floppy1files[4][0], $drive & _ $floppy1files[4][1]) If $res2 = -1 then fli4lbuild_msg ($MSG_cancel,0) Else fli4lbuild_msg ($MSG_finished,0) GUICtrlSetData ($progressbar,80) EndIf EndIf If $res2 = -1 then $_bool_abort = "true" Else ; second-disk $res1 = MsgBox (1 + 64,$MSG_msgbox_info, $MSG_05_secfloppy1 & @CRLF & _ $MSG_05_secfloppy2 & @CRLF & $MSG_05_secfloppy3) If $res1 = 1 then $val = delete_floppyfiles ("OPT") If $val = 0 then fli4lbuild_msg (@CRLF,0) fli4lbuild_msg ($MSG_05_optdisk & " ... ",1) fli4lbuild_msg (@CRLF & $floppy2files[0][2] & " ",0) $_filesize=FileGetSize ($glob_dir_tmpbuild & $floppy2files[0][0]) $_filespace=$_filesize If $_filespace <= $_floppytotalspace Then $res2 = write_file_to_floppy ($glob_dir_tmpbuild & $floppy2files[0][0], $drive & _ $floppy2files[0][1]) If $res2 = -1 then $_bool_abort = "true" fli4lbuild_msg ($MSG_cancel,0) Else fli4lbuild_msg ($MSG_finished,0) EndIf Else $_bool_abort = "true" fli4lbuild_msg ($MSG_cancel & @CRLF,1) $msg = $MSG_05_floppynospace & @CRLF & $MSG_05_requiredspace1 & " " & $_filespace & " " & $MSG_05_requiredspace2 $msg=$msg & @CRLF & $MSG_05_requiredspace3 & " " & $_floppytotalspace & " " & $MSG_05_requiredspace2 fli4lbuild_errmsg ($msg, 1) fli4lbuild_msg ($msg, 1) EndIf Else $_bool_abort = "true" EndIf Else fli4lbuild_msg (@CRLF & $MSG_05_optdisk & " ... ",0) $_bool_usercancel = "true" EndIf EndIf Else #cs error on diskfill (not in this context) 1 = wrong parameters (not in this context) 2 = parameter 2 is not a drive letter (floppy already used) 3 = failed to get drive info (already checked) 4 = input-file too big for splitting (not in this context) 5 = can't open input-file (not in this context) 6 = can't open writefile #1 (not in this context) 7 = can't open writefile #2 (use available) 8 = preserve larger than available #ce $_bool_abort = "true" EndIf FileDelete ($glob_dir_tmpbuild & $floppy1files[4][0]) FileDelete ($glob_dir_tmpbuild & $floppy2files[0][0]) EndIf Else $_bool_usercancel = "true" EndIf EndFunc Func syslinux () fli4lbuild_msg (@CRLF & $MSG_05_writesystem & " " ,0) If @OSType = "WIN32_WINDOWS" Then $val = RunWait ("windows\syslinux.com " & $suffix & " " & $drive, @WorkingDir, @SW_HIDE) Else $val = RunWait ("windows\syslinux.exe " & $suffix & " " & $drive, @WorkingDir, @SW_HIDE) EndIf fli4lbuild_msg ($MSG_finished,0) Return $val #cs Error on syslinux: 1 = error status 0 = good status #ce EndFunc Func write_file_to_floppy ($_src, $_dest) Dim $res1 Dim $res2 $res2 = -1 Do $res1 = FileCopy ($_src, $_dest ,1) If $res1 <> 1 then $msg_error = $MSG_05_floppynowrite1 & $_dest & "'" & @CRLF & $MSG_05_floppynowrite2 ; GUICtrlSetData($log_output, $msg_error, 1) $res2=MsgBox (5+48, $MSG_msgbox_error, $msg_error) EndIf Until $res1 = 1 or $res2 = 2 If $res2 = 2 then fli4l_log_error ($msg_error) fli4lbuild_msg ($MSG_cancel,0) Return -1 Else Return 0 EndIf EndFunc Func delete_floppyfiles ($floppynr) Dim $res1 Dim $res2 Dim $res3 Dim $res4 Do $res1 = DriveStatus ($drive & "\") While $res1 <> "READY" ; MsgBox(0, "Debug", $res1) If $res1 = "UNKNOWN" AND @OSType <> "WIN32_WINDOWS" Then ; floppy is not formatted $res2 = MsgBox (3+32+256, $MSG_msgbox_info, $MSG_05_floppynotformatted1 & @CRLF & $MSG_05_floppynotformatted2) If $res2 = 2 Then Return -1 If $res2 = 6 Then ;format floppy fli4lbuild_msg (@CRLF & $MSG_05_formatfloppy & " ", 0) RunWait(@ComSpec & " /c " & "format " & $drive & ' /BACKUP /V:""') fli4lbuild_msg ($MSG_finished, 0) EndIf Else If @OSType = "WIN32_WINDOWS" Then $msg = $MSG_05_nofloppyW9x Else $msg = $MSG_05_nofloppy EndIf $res2 = MsgBox (5 + 16, $MSG_msgbox_info, $msg) If $res2 = 2 Then Return -1 EndIf $res1 = DriveStatus ($drive & "\") WEnd $_floppytotalspace = (DriveSpaceTotal( $drive & "\" )* 1048576) $_floppyclustersize=DriveSizeCluster( $drive ) $currentdir = @WorkingDir $search = FileFindFirstFile($drive & "\*.*") If $search <> -1 Then $msg = $MSG_05_filesonfloppy & @CRLF & @CRLF & "(" & StringUpper($drive) & "\)" If $floppynr = "OPT" _ AND DriveGetLabel($drive) = "_FLI4L_BOOT" _ AND FileGetSize($glob_dir_tmpbuild & "\rc.cfg") = FileGetSize($drive & "\RC.CFG") Then $msg = $msg & @CRLF & @CRLF & $MSG_05_floppyseemsboot EndIf $res1 = MsgBox (4+32+256, $MSG_msgbox_info, $msg) If $res1 = 6 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If StringInStr(FileGetAttrib ($drive & "\" & $file),"D") <> 0 Then FileSetAttrib ($drive & "\" & $file, "-HRS", 1) DirRemove ($drive & "\" & $file, 1) Else FileSetAttrib ($drive & "\" & $file, "-HRS") FileDelete ($drive & "\" & $file) EndIf Wend $res3 = 6 Else $res3 = MsgBox (4+32+256, $MSG_msgbox_info, $MSG_05_usefloppy) If $res3 = 7 Then $res3 = MsgBox (1+32, $MSG_msgbox_info, $MSG_05_exchangefloppy) If $res3 = 2 Then Return -1 EndIf EndIf EndIf FileClose($search) FileChangeDir ($currentdir) If $res3 = 1 Then $_canwrite = 0 Else $_canwrite = DriveSetLabel($drive, "_FLI4L_" & $floppynr) If $_canwrite = 0 Then $msg_error = $MSG_05_error $res4 = MsgBox (5+48, $MSG_msgbox_error, $msg_error) If $res4 = 2 Then Return -1 EndIf EndIf Until $_canwrite <> 0 Return 0 EndFunc