Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - [VB2010]Estrarre un file zip
Forum - C# / VB.NET - [VB2010]Estrarre un file zip - Pagina 2

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
DHD (Normal User)
Newbie


Messaggi: 14
Iscritto: 20/11/2013

Segnala al moderatore
Postato alle 15:31
Sabato, 23/11/2013
Testo quotato

Postato originariamente da GN:

Il problema è qui
Codice sorgente - presumibilmente C# / VB.NET

  1. If Form2.RadioButton1.Checked Then


Stai facendo riferimanto alla classe Form2 invece che all'istanza. Il valore booleano che indica cosa si deve scaricare divresti passarlo dal form dove ci sono i radiobutton al costruttore di quello che fa il download. In altre parole, dichiara nel form1 (quello di cui hai postato il codice del load) che prenda il parametro e lo assegni a una variabile goobale
Codice sorgente - presumibilmente VB.NET

  1. Dim Versione As Boolean
  2. Sub New (ByVal v As Boolean)
  3.   Versione = v
  4. End Sub


Poi sostuisci la riga di prima con
Codice sorgente - presumibilmente C# / VB.NET

  1. If versione Then


E nel form2, nel punto dove inizializzi il form1 ([ot]ti consiglierei di dare dei nomi più significativi a questi form, e anche ai controlli, perchè altrimenti ci si capisce poco[/ot]) passi il parametro corretto (ovvero radiobutton1.checked)



scusa ma non ho capito quasi nulla ( scusa ma non sono molto bravo :( )
il codice è quello che c'è sopra, secondo quello che dici tu dovrebbe diventare questo:
Codice sorgente - presumibilmente VB.NET

  1. Public class Form1
  2.  
  3.       Dim Versione As Boolean
  4.       Sub New (ByVal v As Boolean)
  5.           Versione = v
  6.        End Sub
  7.  
  8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.             'se la directory C:\mods non esiste
  10.             If My.Computer.FileSystem.DirectoryExists("C:\" & "mods\") = False Then
  11.                 'allora la crea
  12.                 MkDir("C:\mods")
  13.             End If
  14.             'imposta testo label5=0%
  15.             Label5.Text = "0%"
  16.             'se è stato selezionato il pacchetto lite in precedenza
  17.             ' lo scarica
  18.             If versione Then
  19.                 Label4.Text = "Pacchetto_Lite.zip"
  20.                 If My.Computer.FileSystem.FileExists("C:\mods\Pacchetto_Lite-1.0.zip") Then
  21.                     Label1.Text = "Pacchetto già scaricato!"
  22.                     MsgBox("Il pacchetto è già stato scaricato!", MsgBoxStyle.Information, "Già Scaricato")
  23.                 Else
  24.                     download.DownloadFileAsync(New Uri("http://miosito.com/file.zip"), "C:\mods\Pacchetto_Lite-1.0.zip")
  25.                 End If
  26.             Else
  27.                 Label4.Text = "Pacchetto_Con_XVM.zip"
  28.                 If My.Computer.FileSystem.FileExists("C:\mods\Pacchetto_Con_XVM-1.0.zip") Then
  29.                     Label1.Text = "Pacchetto già scaricato!"
  30.                     MsgBox("Il pacchetto è già stato scaricato!", MsgBoxStyle.Information, "Già Scaricato")
  31.                 Else
  32.                     download.DownloadFileAsync(New Uri("http://miosito.com/file1.zip"), "C:\mods\Pacchetto_Con_XVM-1.0.zip")
  33.                 End If
  34.             End If
  35.      
  36.         End Sub



però mi da questo errore:
Codice sorgente - presumibilmente C# / VB.NET

  1. 'Public Sub New(v As Boolean)' nel tipo 'Mod_Pack_nuovo.Form6' generato dalla finestra di progettazione deve chiamare il metodo InitializeComponent.



e nel Form 2 ?

Codice sorgente - presumibilmente VB.NET

  1. Imports System.IO
  2. Public Class Form2
  3.  
  4.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  5.         Dim msg As String
  6.         Dim title As String
  7.         Dim style As MsgBoxStyle
  8.         Dim response As MsgBoxResult
  9.         msg = "Il Setup non è stato completato. Uscire comunque ?"   ' Define message.
  10.         style = MsgBoxStyle.YesNo
  11.         title = "Setup non completato"   ' Define title.
  12.         ' Display message.
  13.         response = MsgBox(msg, style, title)
  14.         If response = MsgBoxResult.Yes Then   ' User chose Yes.
  15.             Me.Close()
  16.         Else
  17.             ' Perform some other action.
  18.         End If
  19.     End Sub
  20.  
  21.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  22.         Form7.Show()
  23.         Me.Close()
  24.     End Sub
  25.  
  26.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  27.         Form4.Show()
  28.         Me.Close()
  29.     End Sub
  30. End Class



Ultima modifica effettuata da DHD il 23/11/2013 alle 15:40
PM Quote
Avatar
GN (Member)
Guru


Messaggi: 772
Iscritto: 30/04/2011

Segnala al moderatore
Postato alle 15:47
Sabato, 23/11/2013
Si scusa devi mettere InitializeComponent() dopo Versione= v, mi ero scordato. Nel form2, dov'è che inizializzi e mostri form1?

PM Quote
Avatar
DHD (Normal User)
Newbie


Messaggi: 14
Iscritto: 20/11/2013

Segnala al moderatore
Postato alle 16:30
Sabato, 23/11/2013
Testo quotato

Postato originariamente da GN:

Si scusa devi mettere InitializeComponent() dopo Versione= v, mi ero scordato. Nel form2, dov'è che inizializzi e mostri form1?



nella prima idea che ho avuto, andava direttamente al form per scaricare, poi tra quello della versione ( i radio button ) ho aggiunto un nuovo form con 2 radiobutton. Però stavolta, in quel form non c'è bisogno di scaricare nulla, ma solo di rimuovere un file dopo aver estratto.
[OT]
Anzi, c'è il modo di riscrivere la 2° linea di un file xml ?
la deve riscrivere solo in base al radiobutton scelto dopo il form che dice cosa scaricare.
[/OT]

PM Quote
Avatar
DHD (Normal User)
Newbie


Messaggi: 14
Iscritto: 20/11/2013

Segnala al moderatore
Postato alle 19:12
Sabato, 23/11/2013
Testo quotato

Postato originariamente da DHD:

Testo quotato

Postato originariamente da GN:

Si scusa devi mettere InitializeComponent() dopo Versione= v, mi ero scordato. Nel form2, dov'è che inizializzi e mostri form1?



nella prima idea che ho avuto, andava direttamente al form per scaricare, poi tra quello della versione ( i radio button ) ho aggiunto un nuovo form con 2 radiobutton. Però stavolta, in quel form non c'è bisogno di scaricare nulla, ma solo di rimuovere un file dopo aver estratto.
[OT]
Anzi, c'è il modo di riscrivere la 2° linea di un file xml ?
la deve riscrivere solo in base al radiobutton scelto dopo il form che dice cosa scaricare.
[/OT]



se inserisco InitializeComponent() dopo v non va, mi dice che devvo aggiungere un oggetto all'istanza

ora, dopo aver "rifatto" il progetto sembra andare...

PM Quote
Avatar
DHD (Normal User)
Newbie


Messaggi: 14
Iscritto: 20/11/2013

Segnala al moderatore
Postato alle 19:17
Domenica, 24/11/2013
Davvero non capisco.....
Ora scarica tutto bene, però quando deve installare, usa le istruzioni nell'else:

Form in cui scarica:
Codice sorgente - presumibilmente VB.NET

  1. Imports System.Net
  2. Imports System.IO
  3. Public Class Forms
  4.  
  5.     Public WithEvents TCP As New System.Net.WebClient 'come webclient
  6.     Dim WithEvents download As New WebClient ' come webclient ( downloader )
  7.  
  8.     Private Sub Form6_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  9.         'se la directory C:\mods non esiste
  10.         If My.Computer.FileSystem.DirectoryExists("C:\" & "mods\") = False Then
  11.             'allora la crea
  12.             MkDir("C:\mods")
  13.         End If
  14.         'imposta testo label5=0%
  15.         Label6.Text = "0%"
  16.         'se è stato selezionato il pacchetto lite in precedenza
  17.         ' lo scarica
  18.         If Form3.RadioButton1.Checked Then
  19.             Label4.Text = "Pacchetto_Lite-1.0.zip"
  20.             If My.Computer.FileSystem.FileExists("C:\mods\Pacchetto_Lite-1.0.zip") Then
  21.                 Label1.Text = "Pacchetto già scaricato!"
  22.                 MsgBox("Il pacchetto è già stato scaricato!", MsgBoxStyle.Information, "Già Scaricato")
  23.             Else
  24.                 download.DownloadFileAsync(New Uri("http://www.sito.org/Pacchetto_Lite-1.0.zip?dl=1"), "C:\mods\Pacchetto_Lite-1.0.zip")
  25.             End If
  26.         Else
  27.             If Form3.RadioButton2.Checked = True Then
  28.                 Label4.Text = "Pacchetto_Con_XVM-1.0.zip"
  29.                 If My.Computer.FileSystem.FileExists("C:\mods\Pacchetto_Con_XVM-1.0.zip") Then
  30.                     Label1.Text = "Pacchetto già scaricato!"
  31.                     MsgBox("Il pacchetto è già stato scaricato!", MsgBoxStyle.Information, "Già Scaricato")
  32.                 Else
  33.                     download.DownloadFileAsync(New Uri("http://www.sito.org/Pacchetto_Con_XVM-1.0.zip?dl=1"), "C:\mods\Pacchetto_Con_XVM-1.0.zip")
  34.                 End If
  35.             End If
  36.         End If
  37.     End Sub
  38.  
  39.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  40.         download.CancelAsync()
  41.         ProgressBar1.Value = "0"
  42.         Label5.Text = "0%"
  43.         MsgBox("Download annullato!", MsgBoxStyle.Information)
  44.         File.Delete("C:\mods\" & Label4.Text)
  45.     End Sub
  46.  
  47.     Public Mem1 As String, Mem2 As String
  48.     Private Sub download_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles download.DownloadProgressChanged
  49.         ProgressBar1.Value = e.ProgressPercentage
  50.         Label6.Text = e.ProgressPercentage & "%"
  51.         Label7.Visible = True
  52.         Label8.Visible = True
  53.  
  54.         If e.TotalBytesToReceive > 1073741824 Then
  55.             Mem1 = Math.Round((((e.TotalBytesToReceive / 1024) / 1024) / 1024), 2) & " GB"
  56.         Else
  57.             Mem1 = Math.Round((((e.TotalBytesToReceive / 1024) / 1024)), 2) & " MB"
  58.         End If
  59.  
  60.         Label9.Text = Mem1
  61.  
  62.         If e.BytesReceived > 1073741824 Then
  63.             Mem2 = Math.Round((((e.BytesReceived / 1024) / 1024) / 1024), 2) & " GB"
  64.         Else
  65.             Mem2 = Math.Round((((e.BytesReceived / 1024) / 1024)), 2) & " MB"
  66.         End If
  67.         Label7.Text = Mem2
  68.         If Label5.Text = "100%" Then
  69.             ProgressBar1.Value = "0"
  70.             Label5.Text = "0%"
  71.             Label1.Text = "Download completato!"
  72.             MsgBox("Download completato !", MsgBoxStyle.Information)
  73.         End If
  74.     End Sub
  75.  
  76.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  77.         Form7.Show()
  78.         Me.Hide()
  79.     End Sub
  80. End Class



nel form in cui deve installare ( cioè estrarre ):
Codice sorgente - presumibilmente VB.NET

  1. Imports System.IO
  2. Imports System.IO.Compression
  3. Imports Ionic.Zip
  4. Imports System.Windows.Forms
  5.  
  6. Public Class Form7
  7.  
  8.     Private Sub Form7_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  9.         If Form3.RadioButton1.Checked = True Then
  10.             Label4.Text = "Pacchetto_Lite.zip"
  11.         End If
  12.         If Form3.RadioButton2.Checked = True Then
  13.             Label4.Text = "Pacchetto_Con_XVM.zip"
  14.         End If
  15.     End Sub
  16.  
  17.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  18.         If Directory.Exists(Form2.TextBox1.Text & "res_mods\0.8.9") Then
  19.             Directory.Delete(Form2.TextBox1.Text & "res_mods\0.8.9", True)
  20.         End If
  21.         If Directory.Exists(Form2.TextBox1.Text & "res_mods\xvm") Then
  22.             Directory.Delete(Form2.TextBox1.Text & "res_mods\xvm", True)
  23.         End If
  24.         If Label4.Text = "Pacchetto_Lite.zip" Then
  25.             Dim msg As String
  26.             Dim title As String
  27.             Dim style As MsgBoxStyle
  28.             Dim response As MsgBoxResult
  29.             msg = "Installazione Completata"   ' Define message.
  30.             style = MsgBoxStyle.Information
  31.             title = "MOD"   ' Define title.
  32.             Dim ZipToUnpack As String = "C:\mods\Pacchetto_Lite-1.0.zip"
  33.             Dim TargetDir As String = Form2.TextBox1.Text
  34.             Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)
  35.             Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
  36.                 Dim ea As ZipEntry
  37.                 Me.ProgressBar1.Maximum = zip1.Entries.Count
  38.                 ' here, we extract every entry, but we could extract    
  39.                 ' based on entry name, size, date, etc.  
  40.                 For Each ea In zip1
  41.                     ea.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
  42.                     Me.ProgressBar1.PerformStep()
  43.                 Next
  44.             End Using
  45.             ' Display message.
  46.             response = MsgBox(msg, style, title)
  47.             Button3.Visible = False
  48.             Button1.Visible = True
  49.             Label1.Text = "Installazione completata !"
  50.         Else
  51.             Dim msg As String
  52.             Dim title As String
  53.             Dim style As MsgBoxStyle
  54.             Dim response As MsgBoxResult
  55.             msg = "Installazione Completata"   ' Define message.
  56.             style = MsgBoxStyle.Information
  57.             title = "MOD"   ' Define title.
  58.             Dim ZipToUnpack As String = "C:\mods\Pacchetto_Con_XVM-1.0.zip"
  59.             Dim TargetDir As String = Form2.TextBox1.Text
  60.             Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)
  61.             Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
  62.                 Dim ea As ZipEntry
  63.                 Me.ProgressBar1.Maximum = zip1.Entries.Count
  64.                 ' here, we extract every entry, but we could extract    
  65.                 ' based on entry name, size, date, etc.  
  66.                 For Each ea In zip1
  67.                     ea.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
  68.                     Me.ProgressBar1.PerformStep()
  69.                 Next
  70.             End Using
  71.             ' Display message.
  72.             response = MsgBox(msg, style, title)
  73.             Button3.Visible = False
  74.             Button1.Visible = True
  75.             Label1.Text = "Installazione completata !"
  76.         End If
  77.  
  78.     End Sub
  79.  
  80.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  81.         Dim msg As String = "Rimuovere i file scaricati ?" 'Definisce la variabile titolo come il titolo del msgbox
  82.         Dim stile As MsgBoxStyle = MsgBoxStyle.YesNo 'Definsce la variabile stile com stile del msgbox
  83.         Dim titolo As String = "Pulizia" 'Definisce la variabile titolo del msgbox
  84.         Dim risposta As MsgBoxResult 'Definisce il risultato del msgbox
  85.         risposta = MsgBox(msg, stile, titolo)
  86.         If risposta = MsgBoxResult.Yes Then   'Se l'utente seleziona si.
  87.             Directory.Delete("C:\mods")
  88.             MsgBox("Pulizia completata!", MsgBoxStyle.Information, "Pulizia!")
  89.         Else
  90.             ' Perform some other action.
  91.         End If
  92.         Form8.Show()
  93.         Me.Close()
  94.     End Sub
  95.  
  96.     Public Sub SvuotaDir(ByVal directory As String)
  97.         Dim di As IO.DirectoryInfo = New IO.DirectoryInfo(directory)
  98.         For Each File As IO.FileInfo In di.GetFiles()
  99.             File.Delete()
  100.         Next
  101.     End Sub
  102. End Class



PM Quote
Avatar
DHD (Normal User)
Newbie


Messaggi: 14
Iscritto: 20/11/2013

Segnala al moderatore
Postato alle 19:47
Domenica, 24/11/2013
Ho dovuto mettere me.hide nel form in cui selezionavo il pacchetto...
Codice sorgente - presumibilmente VB.NET

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         If RadioButton1.Checked = False And RadioButton2.Checked = False Then
  3.             MsgBox("Seleziona un pacchetto", MsgBoxStyle.Information, "Pacchetto")
  4.         End If
  5.         Forms.Show()
  6.         Me.Hide()
  7.     End Sub



Intanto va bene così, ma c'è un modo per mettere me.close e far funzionare il form in cui installa ( post precedente )

PM Quote
Avatar
GN (Member)
Guru


Messaggi: 772
Iscritto: 30/04/2011

Segnala al moderatore
Postato alle 20:30
Domenica, 24/11/2013
Perchè vuoi usare close? Se funziona con hide...

P.S. guarda il titolo del thread, "estrarre un file zip", forse ti stai un po'discostando... se hai altri problemi magsri apri un'altro topic e spiegati bene lì.

PM Quote
Avatar
GN (Member)
Guru


Messaggi: 772
Iscritto: 30/04/2011

Segnala al moderatore
Postato alle 20:31
Domenica, 24/11/2013
Perchè vuoi usare close? Se funziona con hide...

P.S. guarda il titolo del thread, "estrarre un file zip", forse ti stai un po'discostando... se hai altri problemi magsri apri un'altro topic e spiegati bene lì.

PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo