oregon ha scritto:
Ma perché in 1) aggiungi
& ""
? Non aggiungi nulla!
E perché non scrivere direttamente
Process.Start("Bin\7z.exe", "x -y Zipped.7z -ounpacked").WaitForExit()
perchè devo ampliarlo, quello è solo un esempio manuale
il codice sarebbe questo:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fd As OpenFileDialog = New OpenFileDialog()
Dim strFileName As String
fd.Title = "Seleziona fil file da estrarre"
fd.InitialDirectory = fd.FileName
fd.Filter = "All files (*.7z)|*.7z"
fd.RestoreDirectory = True
If fd.ShowDialog() = DialogResult.OK Then
strFileName = fd.FileName
TextBox1.Text = fd.FileName
End If
FolderBrowserDialog1.ShowNewFolderButton = False
FolderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop
FolderBrowserDialog1 = New System.Windows.Forms.FolderBrowserDialog
FolderBrowserDialog1.Description = "Scegli dove salvare il file estratto"
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
TextBox2.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim eswitch As String = "x -y"
Dim oswitch As String = "-o"
Dim p As New ProcessStartInfo
p.FileName = "Bin\7z.exe"
p.Arguments = eswitch & " " & ControlChars.Quote & TextBox1.Text & ControlChars.Quote & " " & oswitch & "" & ControlChars.Quote & TextBox2.Text & ControlChars.Quote & """"
'p.WindowStyle = ProcessWindowStyle.Hidden
Process.Start(p)
End Sub
End Class
di cosa intendevo creare
insomma la mia idea era ed ancora, creare un programma che compatti,scompatti e crea eseguibili in > %temp%
1) creo un archivio 7z
2) lo scompatto
3) creo un eseguibile che lanciato installa i file nella cartella temporanea e richiama l'exe
Tutto qui
manca solo la voce 3) e poi sono apposto
questa è la parte 3 ma non mi piace il ragionamento che mi sono fatto
Public Sub RA(ByVal cartella As String)
Dim directories As DirectoryInfo() = New DirectoryInfo(cartella).GetDirectories()
Dim files As FileInfo() = New DirectoryInfo(cartella).GetFiles()
Dim array As FileInfo() = files
For i As Integer = 0 To array.Length - 1
Dim fileInfo As FileInfo = array(i)
If Operators.CompareString(fileInfo.Extension, ".exe", False) = 0 Then
Me.ComboBox1.Items.Add(fileInfo.Name)
Me.exeCol.Add(fileInfo.FullName, Nothing, Nothing, Nothing)
End If
Next
Dim array2 As DirectoryInfo() = directories
For j As Integer = 0 To array2.Length - 1
Dim directoryInfo As DirectoryInfo = array2(j)
Me.RA(directoryInfo.FullName)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Operators.CompareString(Me.Button2.Text, "Ferma", False) = 0 Then
Me.cancellare = True
Me.Button2.Text = "Crea sfx"
Else
Me.SaveFileDialog1.FileName = Path.GetFileName(Me.TextBox2.Text)
Me.SaveFileDialog1.DefaultExt = "exe"
Me.SaveFileDialog1.Filter = "exe files (*.exe)|*.exe"
Me.SaveFileDialog1.RestoreDirectory = True
If Me.SaveFileDialog1.ShowDialog() = DialogResult.OK Then
If Operators.CompareString(Strings.Right(Me.SaveFileDialog1.FileName, 4), ".exe", False) <> 0 Then
Me.SaveFileDialog1.FileName = Me.SaveFileDialog1.FileName + ".exe"
End If
' If File.Exists(Me.TextBox1.Text) Then
' End If
Me.TextBox1.Enabled = False
Me.TextBox2.Enabled = False
Me.ComboBox1.Enabled = False
Me.Button1.Enabled = False
Me.Button2.Text = "Ferma"
Me.Cursor = Cursors.WaitCursor
Me.ToolStripStatusLabel1.Text = "Creazione"
Dim fileInfo As FileInfo = New FileInfo(Me.SaveFileDialog1.FileName)
If fileInfo.Exists Then
fileInfo.Delete()
End If
fileInfo = New FileInfo("config.txt")
If fileInfo.Exists Then
fileInfo.Delete()
End If
fileInfo = New FileInfo("tmp.7z")
If fileInfo.Exists Then
fileInfo.Delete()
End If
Dim array As String() = Strings.Split(Me.SaveFileDialog1.FileName, "\", -1, CompareMethod.Binary)
Dim text As String = Strings.Left(array(Information.UBound(array, 1)), array(Information.UBound(array, 1)).Length - 4)
Dim text2 As String = Me.exeCol(Me.ComboBox1.SelectedIndex + 1).ToString()
Dim text4 As String = Me.TextBox4.Text.ToString()
Dim text3 As String = Me.TextBox3.Text.ToString()
Dim text5 As String = Me.TextBox5.Text.ToString()
text2 = Strings.Right(text2, text2.Length - Me.FolderBrowserDialog1.SelectedPath.Length - 1)
Dim SW As StreamWriter = New StreamWriter("config.txt")
SW.WriteLine(";!@Install@!UTF-8!")
SW.WriteLine("Delete=""%TEMP%\" + text + """")
SW.WriteLine("InstallPath=""%TEMP%\" + text + """")
SW.WriteLine("GUIFlags=""" + text3 + """")
SW.WriteLine("GUIMode=""" + text4 + """")
SW.WriteLine("ExtractTitle="" " + text + """")
SW.WriteLine("ExtractDialogText=""Loading " + text + "...""")
SW.WriteLine(String.Concat(New String() {"ExecuteFile=""%TEMP%\", text, "\", text2, """"}))
SW.WriteLine(";!@InstallEnd@!")
SW.Close()
SW.Dispose()
If String.IsNullOrEmpty(text5) Then
Me.Eseguiprocesso("Bin\7z", "a -t7z " & "-mx" & " tmp.7z " & """" + Me.FolderBrowserDialog1.SelectedPath + "\*""")
Else
Me.Eseguiprocesso("Bin\7z", "a -t7z " & "-mx" & " tmp.7z " & "-p" & text5 & " " & """" + Me.FolderBrowserDialog1.SelectedPath + "\*""")
End If
If Not Me.cancellare Then
Me.Eseguiprocesso("cmd.exe", "/c copy /b Bin\7zsd_LZMA2.sfx + config.txt + tmp.7z """ + Me.SaveFileDialog1.FileName + """")
End If
If Me.cancellare Then
fileInfo = New FileInfo(Me.SaveFileDialog1.FileName)
If fileInfo.Exists Then
fileInfo.Delete()
End If
End If
For Each proc As Process In Process.GetProcessesByName("7z")
proc.Kill()
Next
Me.TextBox1.Enabled = True
Me.TextBox2.Enabled = True
Me.Button1.Enabled = True
Me.ComboBox1.Enabled = True
Me.Button2.Text = "Crea Sfx"
Me.Cursor = Cursors.[Default]
Me.ToolStripStatusLabel1.Text = "Pronto"
Me.ToolStripProgressBar1.Value = 100
If Not Me.cancellare Then
Interaction.MsgBox("¡Applicazione creata con successo!", MsgBoxStyle.Information, ";)")
End If
Me.cancellare = False
Me.ToolStripProgressBar1.Value = 0
End If
End If
End Sub
Public Sub Eseguiprocesso(ByVal programma As String, ByVal argomento As String)
Try
Dim process As Process = New Process()
process.StartInfo.FileName = programma
process.StartInfo.Arguments = argomento
process.StartInfo.UseShellExecute = False
process.StartInfo.CreateNoWindow = True
process.Start()
While Not process.WaitForExit(250) And Not Me.cancellare
Application.DoEvents()
If Me.ToolStripProgressBar1.Value = 100 Then
Me.ToolStripProgressBar1.Value = 0
Else
Dim toolStripProgressBar As ToolStripProgressBar = Me.ToolStripProgressBar1
toolStripProgressBar.Value += 5
End If
If Me.cancellare Then
process.Kill()
End If
End While
process.Close()
process.Dispose()
Catch expr_BD As Exception
ProjectData.SetProjectError(expr_BD)
Dim ex As Exception = expr_BD
Interaction.MsgBox(ex.Message, MsgBoxStyle.Exclamation, ";)")
ProjectData.ClearProjectError()
End Try
End Sub
perchè creo l'eseguibile solo dalla cartella e mi serve anche dal file (caricando il file insomma oltre alla cartella) in due bottoni separati folder e file