kvk1989 2 Posted February 8, 2022 hi , i have a issue with my project progress bar not working with actual file size thanks !! here is my codes unit Emmcdl; interface uses Winapi.Windows, System.Classes, System.SysUtils, Vcl.Controls, Vcl.Graphics, Vcl.StdCtrls, Dos, forms, fungsi,FileCtrl; const emmc = 'emmcdl.exe'; type TEmmcdl_info = record serial: string; msmid: string; hash: string; sblid: string; end; function EmmcDlInfo(port: string): Boolean; function EmmcDlGPT(port, storage, firehose: string): Boolean; function EmmcDlRead(port, storage, firehose, partname, filename: string): Boolean; function EmmcDlWrite(port, storage, firehose, partname, filename: string): Boolean; function EmmcDlErase(port, storage, firehose, partname: string): Boolean; function EmmcDlEraseAdress(port, storage, firehose, startadress, sizeadress: string): Boolean; function EmmcDlRawXMl(port, storage, firehose, xml: string): Boolean; function EmmcDlPathXMl(port, storage, firehose, xml: string): Boolean; function EmmcDlReboot(port: string): Boolean; var getemmcdl: string; info: TEmmcdl_info; ListGPT: Tstringlist; maxprogress: Int64; implementation uses SetupApi, USBPort, XMLparser, main; function EmmcDlInfo(port: string): Boolean; var found: Boolean; begin result := false; found := false; ProcessRunning := True; stopprogress := false; Screen.Cursor := 11; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -info', '', procedure(const Line: PAnsiChar) var str, str1: string; begin str := string(Line).Trim; if (pos('SerialNumber:', str) > 0) then begin str1 := copy(str, pos('SerialNumber:', str) + 13, 10); info.serial := str1; end; if (pos('MSM_HW_ID:', str) > 0) then begin str1 := copy(str, pos('MSM_HW_ID:', str) + 10, 10); info.msmid := str1; end; if (pos('OEM_PK_HASH:', str) > 0) then begin str1 := copy(str, pos('OEM_PK_HASH:', str) + 12, 67); info.hash := str1; end; if (pos('SBL SW Version:', str) > 0) then begin str1 := copy(str, pos('SBL SW Version:', str) + 15, 10); info.sblid := str1; end; if (pos('invalid', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; end); finally if found then result := True else result := false; Screen.Cursor := 0; ProcessRunning := false; stopprogress := True; end; end; procedure adlg(Text: string; clrr: TColor; newline: Boolean); begin Application.ProcessMessages; Form7.rch.SelAttributes.Color := clrr; if newline then begin Form7.rch.SelText := ansistring(#13#10) + Text; end else begin Form7.rch.SelText := Text; end; Application.ProcessMessages; end; function TakenTime(Start, EndT: DWORD): string; var dt: TDateTime; begin dt := (EndT - Start) / (1000.0 * 86400); Result := FormatDateTime('hh:mm:ss', dt); end; function EmmcDlGPT(port, storage, firehose: string): Boolean; var found: Boolean; dev: string; begin result := false; found := false; Screen.Cursor := 11; ProcessRunning := True; stopprogress := false; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -f "' + firehose + '" -MemoryName ' + storage + ' ', '-gpt', procedure(const Line: PAnsiChar) var str: string; begin str := string(Line).Trim; dev := str; log(str + #13, 0, 1); if (pos('invalid', lowercase(str)) > 0) or (pos('error ', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) or (pos('the device is not ready', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; found := True; end); finally if found then begin result := True; dev := copy(dev, pos('', dev), pos('', dev)); ListGPT.Add(dev); end else result := false; Screen.Cursor := 0; ProcessRunning := false; stopprogress := True; end; end; function EmmcDlRead(port, storage, firehose, partname, filename: string): Boolean; var found: Boolean; dev: string; begin result := false; found := false; Screen.Cursor := 11; ProcessRunning := True; stopprogress := false; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -MemoryName ' + storage + ' -f "' + firehose + '" -d ', partname + ' -o "' + filename + '"', procedure(const Line: PAnsiChar) var str, str1: string; begin str := string(Line).Trim; dev := str; if (AnsiPos('remaining', str) <> 0) then begin str1 := copy(str, pos('remaining', str) + 9, 10); Form7.stat.Panels[3].Text := str1; //Form7.pb1.Position := Trunc(((maxprogress - StrToInt64(str1)) / // ) * 100); end; if (pos('invalid', lowercase(str)) > 0) or (pos('error ', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) or (pos('the device is not ready', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; end); finally if found then result := True else result := false; Screen.Cursor := 0; ProcessRunning := false; stopprogress := True; end; end; function EmmcDlWrite(port, storage, firehose, partname, filename: string): Boolean; var found: Boolean; begin result := false; found := false; Screen.Cursor := 11; ProcessRunning := True; stopprogress := false; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -MemoryName ' + storage + ' -f "' + firehose + '" -b ', partname + ' "' + filename + '"', procedure(const Line: PAnsiChar) var str, str1: string; begin str := string(Line).Trim; if (AnsiPos('remaining', str) <> 0) then begin str1 := copy(str, pos('remaining', str) + 9, 10); Form7.stat.Panels[3].Text := str1; Form7.pb1.Position := Trunc(((maxprogress - StrToInt64(str1)) / maxprogress) * 100); end; if (pos('invalid', lowercase(str)) > 0) or (pos('error ', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) or (pos('the device is not ready', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; end); finally if found then result := True else result := false; ProcessRunning := false; stopprogress := True; Screen.Cursor := 0; end; end; function EmmcDlErase(port, storage, firehose, partname: string): Boolean; var found: Boolean; begin result := false; found := false; Screen.Cursor := 11; ProcessRunning := True; stopprogress := false; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -MemoryName ' + storage + ' -f "' + firehose + '" -e ', partname, procedure(const Line: PAnsiChar) var str, str1: string; begin str := string(Line).Trim; if (AnsiPos('remaining', str) <> 0) then begin str1 := copy(str, pos('remaining', str) + 9, 10); Form7.stat.Panels[3].Text := str1; Form7.pb1.Position := Trunc(((maxprogress - StrToInt64(str1)) / maxprogress) * 100); end; if (pos('invalid', lowercase(str)) > 0) or (pos('error ', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) or (pos('the device is not ready', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; end); finally if found then result := True else result := false; ProcessRunning := false; stopprogress := True; Screen.Cursor := 0; end; end; function EmmcDlEraseAdress(port, storage, firehose, startadress, sizeadress: string): Boolean; var found: Boolean; begin result := false; found := false; Screen.Cursor := 11; ProcessRunning := True; stopprogress := false; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -MemoryName ' + storage + ' -f "' + firehose + '" -e ', startadress + ' ' + sizeadress, procedure(const Line: PAnsiChar) var str, str1: string; begin str := string(Line).Trim; if (AnsiPos('remaining', str) <> 0) then begin str1 := copy(str, pos('remaining', str) + 9, 10); Form7.stat.Panels[3].Text := str1; Form7.pb1.Position := Trunc(((maxprogress - StrToInt64(str1)) / maxprogress) * 100); end; if (pos('invalid', lowercase(str)) > 0) or (pos('error ', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) or (pos('the device is not ready', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; end); finally if found then result := True else result := false; ProcessRunning := false; stopprogress := True; Screen.Cursor := 0; end; end; function EmmcDlRawXMl(port, storage, firehose, xml: string): Boolean; var found: Boolean; l1, l2, l3, l4, l5: string; begin result := false; found := false; Screen.Cursor := 11; ProcessRunning := True; stopprogress := false; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -MemoryName ' + storage + ' -f "' + firehose + '" -x ', '"' + xml + '"', procedure(const Line: PAnsiChar) var str, str1: string; i: integer; begin StartTime := GetTickCount; str := string(Line).Trim; for i := 0 to Form7.lv1.Items.Count - 1 do begin if Form7.lv1.Items[i].Checked then begin l1 := Form7.lv1.Items[i].Caption; l2 := Form7.lv1.Items[i].SubItems.Strings[0].Trim; l3 := Form7.lv1.Items[i].SubItems.Strings[1].Trim; l4 := Form7.lv1.Items[i].SubItems.Strings[2].Trim; l5 := Form7.lv1.Items[i].SubItems.Strings[3].Trim; if (AnsiPos(lowercase(l2), str) > 0) then begin adlg(' Write =>: ', clblack, True); EndTime := GetTickCount; adlg(l1 + ' : ', clHighlight, false); adlg(' [ '.Trim, clWebWhiteSmoke, false); adlg(l3 + ' '.Trim, clWebDarkGoldenRod, false); adlg(' ] '.Trim, clWebWhiteSmoke, false); adlg(' [Size :] '.Trim, clWebWhiteSmoke, false); adlg(l5 + ') ...'.Trim, clWebOrangeRed, false); adlg('Done', clWebLime, false); end; end; end; if (AnsiPos('remaining', str) <> 0) then begin str1 := copy(str, pos('remaining', str) + 9, 10); Form7.stat.Panels[3].Text := str1; form7.pb1.Position := Trunc(((maxprogress - StrToInt64(str1)) / maxprogress) * 100); end; if (pos('invalid', lowercase(str)) > 0) or (pos('error ', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) or (pos('the device is not ready', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; end); finally if found then result := True else result := false; ProcessRunning := false; stopprogress := True; Screen.Cursor := 0; end; end; function EmmcDlPathXMl(port, storage, firehose, xml: string): Boolean; var found: Boolean; l1, l2, l3, l4, l5: string; begin result := false; found := false; ProcessRunning := True; stopprogress := false; Screen.Cursor := 11; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -MemoryName ' + storage + ' -f "' + firehose + '" -x ', '"' + xml + '"', procedure(const Line: PAnsiChar) var str, str1: string; i: integer; begin str := string(Line).Trim; for i := 0 to Form7.lv1.Items.Count - 1 do begin if Form7.lv1.Items[i].Checked then begin l1 := Form7.lv1.Items[i].Caption; l2 := Form7.lv1.Items[i].SubItems.Strings[0].Trim; l3 := Form7.lv1.Items[i].SubItems.Strings[1].Trim; l4 := Form7.lv1.Items[i].SubItems.Strings[2].Trim; l5 := Form7.lv1.Items[i].SubItems.Strings[3].Trim; if (AnsiPos(lowercase(l2), str) > 0) then begin log(' Patch ', 0, 0); log(l1 + ' ', 0, 1); log('...', 0, 0); end; end; end; if (AnsiPos('disk', str) <> 0) then begin log(' Patch ', 0, 0); log('Disk ' + ' ', 0, 1); log(' ... ' + #13, 0, 0); end; if (pos('invalid', lowercase(str)) > 0) or (pos('error ', lowercase(str)) > 0) or (pos('failed', lowercase(str)) > 0) or (pos('no response', lowercase(str)) > 0) or (pos('cannot find the file specified', lowercase(str)) > 0) or (pos('status: 87 the parameter', lowercase(str)) > 0) or (pos('the device is not ready', lowercase(str)) > 0) then begin found := false; end; if (pos('Status: 0', lowercase(str)) > 0) or (pos('operation completed successfully', lowercase(str)) > 0) then begin found := True; end; end); finally if found then result := True else result := false; ProcessRunning := false; stopprogress := True; Screen.Cursor := 0; end; end; function EmmcDlReboot(port: string): Boolean; const data1 = '0x3C 0x3F 0x78 0x6D 0x6C 0x20 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x3D 0x22 0x31 0x2E 0x30 0x22 0x3F 0x3E 0x3C 0x64 0x61 0x74 0x61 0x3E 0x3C 0x70 '; data2 = '0x6F 0x77 0x65 0x72 0x20 0x76 0x61 0x6C 0x75 0x65 0x3D 0x22 0x72 0x65 0x73 0x65 0x74 0x22 0x20 0x2F 0x3E 0x3C 0x2F 0x64 0x61 0x74 0x61 0x3E'; var dev: string; found: Boolean; begin ProcessRunning := True; stopprogress := false; dev := ''; found := false; Screen.Cursor := 11; getemmcdl := pathexe + emmc; Application.ProcessMessages; try CMD(getemmcdl + ' -p ' + port + ' -raw ', data1 + data2, procedure(const Line: PAnsiChar) var str: string; begin str := string(Line).Trim; dev := str; if (pos('invalid', dev) > 0) or (pos('failed', dev) > 0) or (pos('cannot find the file specified', dev) > 0) or (pos('status: 87 the parameter', dev) > 0) then begin found := false; end; if (pos('Status: 0', dev) > 0) or (pos('The operation completed successfully', dev) > 0) then begin found := True; end; end); finally if found then begin result := True; log('OK' + #13, clBlue, 1); end else begin result := false; log('Error' + #13, clred, 1); end; ProcessRunning := false; stopprogress := True; Screen.Cursor := 0; end; end; end. and button click codes procedure TForm7.Button5Click(Sender: TObject); var DirXml, storage: string; begin if (Firehose = '') or (RawXML = '') or (PathXML = '') then begin Showmessage('Firehose or RawProgram0.xml or Path0.xml Not found'); exit; end; if (not Pos('9008', cbb1.Text) > 0) then begin Showmessage('Port qualcomm not detected '); exit; end; Screen.Cursor := crHourGlass; Port := Getport(cbb1.Text).Trim; adlg(' Scanning port =>: ', claqua, true); log('Qualcomm HS-USB QDLoader 9008' + #13, 0, 1); adlg(' Connect =>: ', claqua, true); log(Trim(cbb1.Text) + #13, clTeal, 1); DirXml := ExtractFileDir(RawXML) + '\duplicate.xml'; if (not DuplicateXml(DirXml, lv1)) then begin log('Error data xml !!' + #13, clred, 1); Screen.Cursor := 0; exit; end; log('Initialize ... ' + #13, 0, 0); if (not EmmcDlInfo(Port)) then exit; adlg(' Serial =>: ', claqua, true); log(info.serial + #13, 0, 1); adlg(' MSM ID =>: ', claqua, true); log(info.msmid + #13, 0, 1); adlg(' PKHASH =>: ', claqua, true); log(info.hash + #13, 0, 1); adlg(' SBL ID =>: ', claqua, true); log(info.sblid + #13, 0, 1); application.ProcessMessages; if (cbb2.ItemIndex = 0) then storage := 'emmc' else storage := 'ufs'; log('Storage Type ', 0, 0); log(uppercase(storage) + #13, 0, 1); application.ProcessMessages; adlg(' Processing =>: ', clolive, true); log(#13, 0, 1); log('Rawprogram0.xml ' + #13, 0, 1); if (DirXml <> '') then EmmcDlRawXMl(Port, storage, Firehose, DirXml); application.ProcessMessages; log('Processing ', 0, 0); log('Patch0.xml ' + #13, 0, 1); if (PathXML <> '') then EmmcDlPathXMl(Port, storage, Firehose, PathXML); application.ProcessMessages; log(#13, 0, 1); log('Rebooting ... ', 0, 0); EmmcDlReboot(Port); if FileExists(DirXml) then DeleteFile(DirXml); end; Share this post Link to post
Remy Lebeau 1394 Posted February 8, 2022 14 hours ago, kvk1989 said: i have a issue with my project progress bar not working with actual file size Can you be more specific? What is the ACTUAL problem? 14 hours ago, kvk1989 said: here is my codes That is a LOT of code for a seemingly simple problem. Can you narrow it down to a much simpler test case? Share this post Link to post
Virgo 18 Posted February 8, 2022 There does not appear to be anything about progressbar in all this code... Unless ProgressRunning and StopProgress variables have something to do with it. Share this post Link to post
Lajos Juhász 293 Posted February 8, 2022 16 minutes ago, Virgo said: There does not appear to be anything about progressbar in all this code... Unless ProgressRunning and StopProgress variables have something to do with it. There is Form7.pb1.Position (a bad design to call directly from another unit as you cannot be sure that the procedure was called from that object) in the code however that's all we can see (besides the problems that the code full of Application.ProcessMessages also that should be avoided). Share this post Link to post
David Heffernan 2345 Posted February 8, 2022 Make a minimal example that we can run. Or just debug your code. Share this post Link to post
Anders Melander 1783 Posted February 9, 2022 5 hours ago, Virgo said: There does not appear to be anything about progressbar in all this code How can you tell? I'm impressed if you managed to make any sense of it 🙂 Share this post Link to post
qubits 20 Posted February 9, 2022 20 hours ago, kvk1989 said: Form7.pb1.Position := Trunc(((maxprogress - StrToInt64(str1)) / maxprogress) * 100); set break points here, examine Position, if all is good and you see it update while debugging, then maybe all you need is Form7.pb1.Refresh; a bit messy, good luck! Share this post Link to post
kvk1989 2 Posted February 9, 2022 9 hours ago, Remy Lebeau said: Can you be more specific? What is the ACTUAL problem? That is a LOT of code for a seemingly simple problem. Can you narrow it down to a much simpler test case? Form7.stat.Panels[3].Text := str1; //Form7.pb1.Position := Trunc(((maxprogress - StrToInt64(str1)) / // ) * 100); here is main issue (strtoint64) Share this post Link to post
Virgo 18 Posted February 9, 2022 5 hours ago, Anders Melander said: How can you tell? I'm impressed if you managed to make any sense of it 🙂 It's not, that I made sense of it... I just did not notice any other strings mentioning progress... Although I missed that Form7 part.... Share this post Link to post
qubits 20 Posted February 10, 2022 21 hours ago, kvk1989 said: here is main issue (strtoint64) Did you get this going? noticed the 64 bits too, but then your copying 10 chars into the str1, so could potentially overflow a 32 bit integer, unless maybe str1 fails on the conversion and the error is silenced somehow. use a local var and do the conversion before updating pb1, wrap it in a try except and catch it. Share this post Link to post