' Gambas class file PRIVATE sStdErr AS String ' store all standard error messages PRIVATE hProcess AS Process ' handler for external process PRIVATE iCountMsg AS Integer = 1 ' counter used for progress bar PRIVATE sReturn AS String ' store return value of rpm command PRIVATE bTrivial AS Boolean = TRUE ' TRUE: trivial opertion, FALSE: not trivial operation PRIVATE sScript AS String = "/usr/lib/rpminstall/apt.sh" ' path of helper shell script PUBLIC SUB Form_Open() DIM sList AS String DIM sRes AS String DIM i AS Integer ME.Center() ' adjust button size according to it's font size tbtDetail.Width = tbtDetail.Font.Width(tbtDetail.Text) + 36 btnPrgClose.Width = btnPrgClose.Font.Width(btnPrgClose.Text) + 36 hbxPBottom.Height = btnPrgClose.Font.Height(btnPrgClose.Text) + 18 ' concatenate all file names into one string IF FMain.lvwMain.Count > 0 THEN WITH FMain.lvwMain .MoveFirst FOR i = 1 TO .Count ' should quote file paths sList = sList & "\\\"" & Quote.Shell(.Item.Text) & "\\\" " .MoveNext NEXT END WITH ENDIF ' setup command string IF FMain.bSrcOnly = FALSE THEN ' binary package installation with apt-get command (root via gksu) IF FMain.bAssumeYes = FALSE THEN sList = "gksu -D " & ("\"RPM installer\"") & " '" & sScript & " --trivial-only " & sList & "'" ELSE sList = "gksu -D " & ("\"RPM installer\"") & " '" & sScript & " --assume-yes " & sList & "'" ENDIF ELSE ' source package installation with rpm command (non root) sList = "rpm -Uv " & sList & " 1>&2 ;echo RETURN_VALUE_OF_CHILD:$? 1>&2" ENDIF ' then execute it hProcess = SHELL sList FOR READ WRITE AS "Command" END PUBLIC SUB Command_Read() '' gksu redirect all messages from its child to standard error. '' So there is nothing to do for starnard output '' ' DIM sLine AS String ' ' ' get all standard output ' READ #LAST, sLine, -512 ' sStdOut = sStdOut & DConv$(sLine) ' PRINT "STDOUT: ", sLine END PUBLIC SUB Command_Error(sStr AS String) sStr = DConv$(sStr) sStr = Replace$(sStr, "\r", "") ' erase unnecessary \r ' get all standard err output but discard annoying messages. IF sStr LIKE "*-WARNING*" THEN RETURN IF sStr LIKE "*%\\]" THEN RETURN IF sStr LIKE ("Reading Package Lists*") THEN RETURN IF sStr LIKE ("Building Dependency Tree*") THEN RETURN IF sStr LIKE "E:*" THEN RETURN IF sStr LIKE "\n" THEN RETURN ' find specific string and judge this is a trivial operation or not. IF sStr LIKE "*Trivial Only specified but this is not a trivial operation.*" THEN bTrivial = FALSE RETURN ENDIF IF sStr LIKE "RETURN_VALUE_OF_CHILD*" THEN sReturn = Left$(Split(sStr, ":")[1]) ' extract return value from child process ELSE sStdErr = sStdErr & sStr IF sStr LIKE "*100\\%*" THEN ' count ###[100%] string to show accurate progress pgbProgress.Value = iCountMsg / (FMain.lvwMain.Count + 3) iCountMsg += 1 ' for debug ' PRINT iCountMsg ENDIF END IF ' for debug ' PRINT "STDERR: ", sStr END PUBLIC SUB Command_Kill() DIM iRet AS Integer ' hold return value ME.Mouse = Mouse.Default IF sReturn = 0 THEN ' if command exit successfully, show message and close all form. tlbProgress.Text = ("Installation is completed") pgbProgress.Value = 1 btnPrgClose.Enabled = TRUE btnPrgClose.SetFocus() tbtDetail.Enabled = TRUE ELSE ' if command exit with error, show error message and back to main form. IF bTrivial = FALSE THEN ' ask user to run apt-get install with --assume-yes or not iRet = Message.Question(("Following message is shown during installation\n\nDo you want to continue the installation?") & sStdErr, ("&No"), ("&Yes")) ELSE IF Len(sStdErr) > 0 THEN Message.Error(("Following error occured\n\nFailed to install rpm packages.") & sStdErr, ("&Close")) iRet = FALSE ELSE Message.Error(("Authentification error occured\n\nFailed to install rpm packages.\n\n") & sStdErr, ("&Close")) iRet = FALSE ENDIF ME.Close(iRet) pgbProgress.Value = 0 iCountMsg = 1 sStdErr = "" ENDIF END PUBLIC SUB btnPrgClose_Click() ME.Close(TRUE) END PUBLIC SUB tbtDetail_Click() IF tbtDetail.Value = TRUE THEN ' expand form and show standard output messages txaDetail.Text = sStdErr txaDetail.Visible = TRUE tbtDetail.Picture = Stock["small/rewind"] ELSE ' shrink form txaDetail.Visible = FALSE tbtDetail.Picture = Stock["small/forward"] ENDIF END