Announcement

Collapse
No announcement yet.

Zipex callback function help needed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Zipex callback function help needed

    hi , i new on plugin and callbackoption make me problem with progress bar.

    simply i unpack an archive with:

    ZipEx.ExtractRAR(_SourceFolder .. "\\files.rar", _SourceFolder .. "\\testextract", "testpass", "");
    error = Application.GetLastError();
    if (error ~= 0) then
    Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
    else
    Dialog.Message("Text", "Text");
    end

    and this works good but no Progress indicator shown.

    in examplecode callbackoption are function to make indicator possible:

    function FilesCallback(_SourceFolder)
    if (status == ZipEx.GENERAL) then
    -- general progress
    Progress.SetText("ProgressBar", path);
    Progress.SetCurrentPos("ProgressBar", value);
    elseif (status == ZipEx.COMPRESSING) then
    -- compressing/decompressing files
    Label.SetText("CurrentFile", path..", ratio="..value.."% compressed");
    elseif (status == ZipEx.ADDING) then
    -- adding files
    Label.SetText("CurrentFile", path..", size="..value.." bytes");
    end
    end

    my problem ist to join the 2 parts :

    on first line with path:

    function FilesCallback(_SourceFolder .. "\\files.rar", "35", "0", )

    results bad syntax and i no idea why. Okay i alive 27 hour without sleep but this i not understand.

    please give me a way on the succesroad.

  • #2
    You shouldn't change the arguments in the definition of the callback function - they need to stay exactly as shown in the documentation. What you do inside the callback function with them, is up to you.

    Also, if you don't want to use a custom callback, you can show the built-in StatusDlg for displaying progress.

    Ulrich

    Comment


    • #3
      thats good news , please tell me info about combining pluginprogress with StatusDlg. Must unrar code in StatusDlg or other Dlg. I have brainerror at time about this. Other Setups with internal files are understand but with plugin i have this little trouble. Wonderful are segment of examplecode if you can make.

      Comment


      • #4
        You can use the StatusDlg for this plugin in the exact same manner as you would use it for any built-in action in Setup Factory. Simply show the StatusDlg before the process starts, and hide it afterwards. Here is a code sample:
        Code:
        [COLOR=#008000]-- method 1 - using StatusDlg to show progress[/COLOR]
        StatusDlg[COLOR=#FF0000].[/COLOR]Show()[COLOR=#FF0000];[/COLOR]
        StatusDlg[COLOR=#FF0000].[/COLOR]ShowCancelButton([COLOR=#0000FF]false[/COLOR])[COLOR=#FF0000];[/COLOR]
        StatusDlg[COLOR=#FF0000].[/COLOR]ShowProgressMeter([COLOR=#0000FF]true[/COLOR])[COLOR=#FF0000];[/COLOR]
        StatusDlg[COLOR=#FF0000].[/COLOR]SetMeterRange([COLOR=#000000]0[/COLOR][COLOR=#FF0000],[/COLOR] [COLOR=#000000]100[/COLOR])[COLOR=#FF0000];[/COLOR]
        StatusDlg[COLOR=#FF0000].[/COLOR]SetAutoSize([COLOR=#0000FF]true[/COLOR])[COLOR=#FF0000];[/COLOR]
        
        ZipEx[COLOR=#FF0000].[/COLOR]ExtractRAR(_SourceFolder[COLOR=#FF0000].[/COLOR] [COLOR=#FF0000].[/COLOR] [COLOR=#800080]"[COLOR=#800080]\\[/COLOR]thefile.rar"[/COLOR][COLOR=#FF0000],[/COLOR] _SourceFolder[COLOR=#FF0000].[/COLOR] [COLOR=#FF0000].[/COLOR] [COLOR=#800080]"[COLOR=#800080]\\[/COLOR]testextract"[/COLOR][COLOR=#FF0000],[/COLOR] [COLOR=#800080]""[/COLOR])[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]error[/COLOR] [COLOR=#FF0000]=[/COLOR] Application[COLOR=#FF0000].[/COLOR]GetLastError()[COLOR=#FF0000];[/COLOR]
        StatusDlg[COLOR=#FF0000].[/COLOR]Hide()[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]if[/COLOR] ([COLOR=#0000FF]error[/COLOR] [COLOR=#FF0000]~=[/COLOR] [COLOR=#000000]0[/COLOR]) [COLOR=#0000FF]then[/COLOR]
          Dialog[COLOR=#FF0000].[/COLOR]Message([COLOR=#800080]"Error"[/COLOR][COLOR=#FF0000],[/COLOR] _tblErrorMessages[COLOR=#FF0000][[/COLOR][COLOR=#0000FF]error[/COLOR][COLOR=#FF0000]],[/COLOR] MB_OK[COLOR=#FF0000],[/COLOR] MB_ICONEXCLAMATION)[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]else[/COLOR]
          Dialog[COLOR=#FF0000].[/COLOR]Message([COLOR=#800080]"Info"[/COLOR][COLOR=#FF0000],[/COLOR] [COLOR=#800080]"Extraction succeeded."[/COLOR][COLOR=#FF0000],[/COLOR] MB_OK[COLOR=#FF0000],[/COLOR] MB_ICONINFORMATION)[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]end[/COLOR]
        Running this sample code would produce a status dialog similar to this while the plugin is working: Click image for larger version

Name:	SCRN-2016-08-23-01.png
Views:	133
Size:	6.0 KB
ID:	297097



        Now, as mentioned before, you can also use the custom callback for showing progress. Again, this is similar to the other actions in Setup Factory which allow custom callbacks, like File.Find(), etc. You would define a custom callback function, and have it interact with the user interface, advancing a progress bar on the dialog, or anything else you wish. This sample code uses the custom callback to log the progress in the Debug window.
        Code:
        [COLOR=#008000]-- method 2 - using custom progress - with debug output[/COLOR]
        [COLOR=#0000FF]function[/COLOR] MyZipExCallback(path[COLOR=#FF0000],[/COLOR] value[COLOR=#FF0000],[/COLOR] status)
            [COLOR=#0000FF]if[/COLOR] (status [COLOR=#FF0000]==[/COLOR] ZipEx[COLOR=#FF0000].[/COLOR]GENERAL) [COLOR=#0000FF]then[/COLOR]
                [COLOR=#008000]-- general progress[/COLOR]
                Debug[COLOR=#FF0000].[/COLOR]Print(value[COLOR=#FF0000].[/COLOR] [COLOR=#FF0000].[/COLOR] [COLOR=#800080]"% processed[COLOR=#800080]\r[/COLOR][COLOR=#800080]\n[/COLOR]"[/COLOR])[COLOR=#FF0000];[/COLOR]
            [COLOR=#0000FF]elseif[/COLOR] (status [COLOR=#FF0000]==[/COLOR] ZipEx[COLOR=#FF0000].[/COLOR]COMPRESSING) [COLOR=#0000FF]then[/COLOR]
                [COLOR=#008000]-- compressing/decompressing files[/COLOR]
                Debug[COLOR=#FF0000].[/COLOR]Print([COLOR=#800080]"Processing file "[/COLOR][COLOR=#FF0000].[/COLOR] [COLOR=#FF0000].[/COLOR] path[COLOR=#FF0000]..[/COLOR][COLOR=#800080]", ratio="[/COLOR][COLOR=#FF0000]..[/COLOR]value[COLOR=#FF0000]..[/COLOR][COLOR=#800080]"% compressed[COLOR=#800080]\r[/COLOR][COLOR=#800080]\n[/COLOR]"[/COLOR])[COLOR=#FF0000];[/COLOR]
            [COLOR=#0000FF]elseif[/COLOR] (status [COLOR=#FF0000]==[/COLOR] ZipEx[COLOR=#FF0000].[/COLOR]ADDING) [COLOR=#0000FF]then[/COLOR]
                [COLOR=#008000]-- adding files[/COLOR]
                Debug[COLOR=#FF0000].[/COLOR]Print([COLOR=#800080]"Adding file "[/COLOR][COLOR=#FF0000].[/COLOR] [COLOR=#FF0000].[/COLOR] path[COLOR=#FF0000]..[/COLOR][COLOR=#800080]", ratio="[/COLOR][COLOR=#FF0000]..[/COLOR]value[COLOR=#FF0000]..[/COLOR][COLOR=#800080]" bytes[COLOR=#800080]\r[/COLOR][COLOR=#800080]\n[/COLOR]"[/COLOR])[COLOR=#FF0000];[/COLOR]
            [COLOR=#0000FF]end[/COLOR]
        [COLOR=#0000FF]end[/COLOR]
        
        Debug[COLOR=#FF0000].[/COLOR]ShowWindow()[COLOR=#FF0000];[/COLOR]
        Debug[COLOR=#FF0000].[/COLOR]Clear()[COLOR=#FF0000];[/COLOR]
        ZipEx[COLOR=#FF0000].[/COLOR]ExtractRAR(_SourceFolder[COLOR=#FF0000].[/COLOR] [COLOR=#FF0000].[/COLOR] [COLOR=#800080]"[COLOR=#800080]\\[/COLOR]thefile.rar"[/COLOR][COLOR=#FF0000],[/COLOR] _SourceFolder[COLOR=#FF0000].[/COLOR] [COLOR=#FF0000].[/COLOR] [COLOR=#800080]"[COLOR=#800080]\\[/COLOR]testextract"[/COLOR][COLOR=#FF0000],[/COLOR] [COLOR=#800080]""[/COLOR][COLOR=#FF0000],[/COLOR] [COLOR=#800080]"MyZipExCallback"[/COLOR])[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]error[/COLOR] [COLOR=#FF0000]=[/COLOR] Application[COLOR=#FF0000].[/COLOR]GetLastError()[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]if[/COLOR] ([COLOR=#0000FF]error[/COLOR] [COLOR=#FF0000]~=[/COLOR] [COLOR=#000000]0[/COLOR]) [COLOR=#0000FF]then[/COLOR]
          Dialog[COLOR=#FF0000].[/COLOR]Message([COLOR=#800080]"Error"[/COLOR][COLOR=#FF0000],[/COLOR] _tblErrorMessages[COLOR=#FF0000][[/COLOR][COLOR=#0000FF]error[/COLOR][COLOR=#FF0000]],[/COLOR] MB_OK[COLOR=#FF0000],[/COLOR] MB_ICONEXCLAMATION)[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]else[/COLOR]
          Dialog[COLOR=#FF0000].[/COLOR]Message([COLOR=#800080]"Info"[/COLOR][COLOR=#FF0000],[/COLOR] [COLOR=#800080]"Extraction succeeded."[/COLOR][COLOR=#FF0000],[/COLOR] MB_OK[COLOR=#FF0000],[/COLOR] MB_ICONINFORMATION)[COLOR=#FF0000];[/COLOR]
        [COLOR=#0000FF]end[/COLOR]
        Running this code could result in something like this: Click image for larger version

Name:	SCRN-2016-08-23-02.png
Views:	118
Size:	13.7 KB
ID:	297096



        I hope this now explains how to use the StatusDlg or how to create a custom progress function, and how to call it.

        Ulrich
        Last edited by Ulrich; 08-24-2016, 01:53 PM.

        Comment


        • #5
          Hi Ulrich ,

          now a have understand handling. At past Days i go on wrong way but now its clear und excellent. Thank you for very fast Help und Learning me the Steps.

          Comment


          • #6
            I be back with small question about DebugWindow. Is Title "Debug" Text Changable to other Text and Icon change possible in Example 2 Window? Thank you

            Comment


            • #7
              Now i see packed archive shows data about filenames and directorys. Its possible Way to hide filenames / folders of zipexpacked archive? Thank you

              Comment


              • #8
                It is up to you how to use the information, using the callback function. If you don't want to show the filenames, then don't display them in the custom callback.

                Ulrich

                Comment


                • #9
                  Thank you. I have corrected my Script and it works.

                  Comment

                  Working...
                  X