.class Datein in eine .jar einfügen

  • VB.NET

Es gibt 35 Antworten in diesem Thema. Der letzte Beitrag () ist von propper.

    OK Ich habe mir die Libary gedownloaded aber welche Datei in diesem Archiv soll ich denn in die Verweise einfügen (habe noch nie eine externe Libary eingefügt ^^ )

    @VincentTB
    heißt du Vincentgri auf Youtube?? :)

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „propper“ ()

    Ja, ich bin Vincentgri :D

    Zu deinem Problem, die DLL befindet sich da: DotNetZipLib-DevKit-v1.9\Tools\Ionic.Zip.dll.
    Aber ich habs gerade getestet, bei Datei 34 bricht er ab, kann man glaube auch nicht umgehen...
    Was aber klappt ist das entpacken mit 7zip (es wird halt nur nicht die aux.class entpackt).
    Vielleicht könnte man es wie WinRAR versuchen, und die Datei in aux_class umbenennen und beim packen dann halt wieder in aux.class zu ändern.
    Das Problem haben viele, siehe *klick*

    Edit: Hier ist ne Lösung. Jetzt müsste man noch wissen, wie man 1. Dateien beim entpacken überspringt und 2. wie man Dateien in einem Archiv umbenennt, ohne es zu entpacken...
    Mfg
    Vincent

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „VincentTB“ ()

    So, ich weiß nicht, ob das jetzt als Doppelpost betrachtet wird, aber es wird so unübersichtlich, wenn ich das editieren würde. Naja, ich habe die einfache Lösung :)
    Nachdem ich mich gestern noch mal zwei Stunden hingesetzt und verschiedene Sachen ausprobiert habe, kam mir in den Sinn, dass man ja eigentlich einfach nur die aux.class in dem Archiv umbenennen muss, dann entpackt man das Archiv, fügt Mods ein, und packt es wieder. Also, im Internet steht nicht viel von Dateien im Archiv ändern, aber dann habe ich endlich etwas gefunden, was funktioniert, ohne dass das ganze Archiv entpackt werden muss :D *klickl*

    Also geht ihr wie folgt vor:
    Ihr downloadet euch das, verweist auf die DLL und erstellt am besten eine neue Sub:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System
    2. Imports ComponentAce.Compression.ZipForge
    3. Imports ComponentAce.Compression.Archiver
    4. Private Sub RenameFileInZip(ZipFile As String, oldName As String, newName As String)
    5. Dim archiver As ZipForge = New ZipForge()
    6. ' Set the name of the archive file we want to create
    7. archiver.FileName = ZipFile
    8. ' open an existing ZIP file
    9. archiver.OpenArchive(System.IO.FileMode.Open)
    10. ' rename a file in archive
    11. archiver.RenameFile(oldName, newName)
    12. ' close archive
    13. archiver.CloseArchive()
    14. End Sub

    Ihr ruft dass am besten so auf:

    VB.NET-Quellcode

    1. Me.RenameFileInZip(MinecraftZIP.FullName, "aux.class", "aux_class")


    Danach "konvertiert" ihr die Jar zum zip Archiv, entpackt das, fügt Mods ein, löscht den META-INF Ordner, und fügt das ganze wieder zu einem Archiv zusammen. Jetzt müsst ihr das Umbenennen nur noch rückgängig machen und schon habt ihr nen guten Modpack Installer :thumbup:
    Mfg
    Vincent

    Also ich habe es jetzt auch ausprobiert und das funktioniert(konvertieren zu .zip und die Datei umbenennen in aux_class):
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Private Sub RenameFileInZip(ByVal ZipFile As String, ByVal oldName As String, ByVal newName As String)
    2. Dim archiver As ZipForge = New ZipForge()
    3. ' Set the name of the archive file we want to create
    4. archiver.FileName = ZipFile
    5. ' open an existing ZIP file
    6. archiver.OpenArchive(System.IO.FileMode.Open)
    7. ' rename a file in archive
    8. archiver.RenameFile(oldName, newName)
    9. ' close archive
    10. archiver.CloseArchive()
    11. End Sub
    12. Private Sub Button_patch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_patch.Click
    13. File.Copy("C:\Neu\minecraft.jar", "C:\Neu\minecraft.zip")
    14. RenameFileInZip("C:\Neu\minecraft.zip", "aux.class", "aux_class")
    15. End Sub

    aber bei diesen code ist was falsch:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Shared Sub CopyToZip(ByVal inArchive As String, ByVal outArchive As String, ByVal tempPath As String)
    2. Dim inZip As ZipFile = Nothing
    3. Dim outZip As ZipFile = Nothing
    4. Try
    5. inZip = New ZipFile(inArchive)
    6. outZip = New ZipFile(outArchive)
    7. Dim tempNames As New List(Of String)()
    8. Dim originalNames As New List(Of String)()
    9. Dim I As Integer = 0
    10. For Each entry As ZipEntry In inZip
    11. If Not entry.IsDirectory Then
    12. Dim tempName As String = Path.Combine(tempPath, "tmp.tmp")
    13. Dim oldName As String = entry.FileName
    14. Dim buffer As Byte() = New Byte(4025) {}
    15. Dim inStream As Stream = Nothing
    16. Dim stream As FileStream = Nothing
    17. Try
    18. inStream = entry.OpenReader()
    19. stream = New FileStream(tempName, FileMode.Create, FileAccess.ReadWrite)
    20. Dim size As Integer = 0
    21. While (InlineAssignHelper(size, inStream.Read(buffer, 0, buffer.Length))) > 0
    22. stream.Write(buffer, 0, size)
    23. End While
    24. inStream.Close()
    25. stream.Flush()
    26. stream.Close()
    27. inStream = New FileStream(tempName, FileMode.Open, FileAccess.Read)
    28. outZip.AddEntry(oldName, inStream)
    29. outZip.Save()
    30. Catch exe As Exception
    31. Throw exe
    32. Finally
    33. Try
    34. inStream.Close()
    35. Catch ignore As Exception
    36. End Try
    37. Try
    38. stream.Close()
    39. Catch ignore As Exception
    40. End Try
    41. End Try
    42. End If
    43. Next
    44. Catch e As Exception
    45. Throw e
    46. End Try
    47. End Sub

    Bei Zeile 22 zeigt er bei "InlineAssignHelper" immer einen Fehler an, das diese Instanz nicht deklariert wurde! Wie hast du das denn hinbekommen, dass das funktioniert? (Ich will ja nicht einfach ein Objekt deklarieren was den namen "InlineAssignHelper" trägt)
    Und dannnoch eine Frage:

    VB.NET-Quellcode

    1. Dim inZip As ZipFile = Nothing
    2. Dim outZip As ZipFile = Nothing

    Sollen da die Pfade zu der ZIP-Datei und der Datei zum hinzufügen hin oder was soll dahin?

    propper schrieb:

    InlineAssignHelper
    Das ist eine Hilfsfunktion, die du dir selbst definieren kannst

    VB.NET-Quellcode

    1. Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, value As T) As T
    2. target = value
    3. Return value
    4. End Function
    -> learningthensharing.blogspot.de/2009/01/ftp-using-vbnet.html
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --
    Also ich habe jetzt ein bisschen gesucht und in unserem Fall muss man ja erstmal InlineAssignHelper deklarieren und da ich nicht weiß was da rein muss habe ich versucht einfach so zu warten ohne zu gucken ob "inStream" oder so fertig ist:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Try
    2. inStream = entry.OpenReader()
    3. Stream = New FileStream(tempName, FileMode.Create, FileAccess.ReadWrite)
    4. Dim size As Integer = 0
    5. 'While (InlineAssignHelper(size, inStream.Read(buffer, 0, buffer.Length))) > 0
    6. 'stream.Write(buffer, 0, size)
    7. 'End While
    8. Dim time As Integer = 3000
    9. Dim Stopw As New Stopwatch
    10. Stopw.Start()
    11. Do Until Stopw.ElapsedMilliseconds >= time
    12. Application.DoEvents()
    13. Loop
    14. inStream.Close()
    15. Stream.Flush()
    16. Stream.Close()
    17. inStream = New FileStream(tempName, FileMode.Open, FileAccess.Read)
    18. outZip.AddEntry(oldName, inStream)
    19. outZip.Save()
    20. Catch exe As Exception
    21. Throw exe
    22. Finally

    Also habe ich versucht es auszuprobieren aber ich wusste gar nicht wie.
    Ich weiß nicht was bei InArchive, OutArcive und tempPath hin muss (also eigentlich überall ^^)
    Ich habe schon ein bisschen rumprobiert aber es hat nicht geklappt!

    EDIT: Vincent. Du hast es doch schonmal geschafft. Aber wie? :wacko: )
    ach so Ich hatte gedacht das währe ein Beispiel für dei Funktion! :D

    EDIT:
    Ich habe es immer noch nicht herausgefunden ?( .
    @VincentTB du hast es doch schon mal hinbekommen. Aber wie?

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „propper“ ()

    Hier ist mein Code für einen funktionierenden Modinstaller. Ich bin leider zu faul, da jetzt alles auszukommentieren, such dir einfach das raus, was du wirklich brauchst, also nicht einfach Strg+A & Strg+C machen Manches wird dir nicht weiterhelfen, aber ich habe gerade echt wenig Zeit, alles rauszusortieren. Hoffe, ich kann damit dir und einigen anderen helfen.
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System' This namespace contains the main class - ZipForge.
    2. Imports ComponentAce.Compression.ZipForge
    3. Imports ComponentAce.Compression.Archiver
    4. Imports System.IO
    5. Imports Ionic.Zip
    6. Imports System.Threading
    7. Imports System.ComponentModel
    8. Imports System.Text.RegularExpressions
    9. Public Class frm_main
    10. Private _backgroundWorker1 As System.ComponentModel.BackgroundWorker
    11. Private _saveCanceled As Boolean
    12. Private _totalBytesAfterCompress As Long
    13. Private _totalBytesBeforeCompress As Long
    14. Private _nFilesCompleted As Integer
    15. Private _progress2MaxFactor As Integer
    16. Private _entriesToZip As Integer
    17. Private rvn_ZipFile As String = "zipfile"
    18. Private rvn_DirToZip As String = "dirToZip"
    19. Private _operationCanceled As Boolean
    20. Private nFilesCompleted As Integer
    21. Private totalEntriesToProcess As Integer
    22. Private rvn_ExtractDir As String = "extractdir"
    23. Private WithEvents BGWStart As New BackgroundWorker
    24. Private Delegate Sub SaveEntryProgress(ByVal e As SaveProgressEventArgs)
    25. Private Delegate Sub ButtonClick(ByVal sender As Object, ByVal e As EventArgs)
    26. Private Delegate Sub ZipProgress(ByVal e As ExtractProgressEventArgs)
    27. Dim MinecraftJAR As String
    28. Dim MinecraftZIP As New FileInfo(Application.StartupPath & "\minecraft.zip")
    29. Const aux As String = "aux.class"
    30. Dim ExtractPath As New DirectoryInfo(Application.StartupPath & "\minecraftjarextract")
    31. Dim WithEvents wc As New Net.WebClient
    32. Dim zahl As Integer = 5
    33. Dim WithEvents BGWMods As New BackgroundWorker
    34. Dim filename As String
    35. Dim ModsOrdner As New DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft\mods")
    36. Dim MinecraftOrdner As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\.minecraft"
    37. Dim CoreModsOrdner As New DirectoryInfo(MinecraftOrdner & "\coremods")
    38. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    39. Dim minecraftjardatei As New FileInfo(IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft\bin\minecraft.jar"))
    40. txt_minecraftpfad.Text = minecraftjardatei.FullName
    41. If Not ModsOrdner.Exists Then
    42. ModsOrdner.Create()
    43. End If
    44. End Sub
    45. Private Sub SetProgressBars()
    46. If Me.prg_process.InvokeRequired Then
    47. 'Me.ProgressBar1.Invoke(New MethodInvoker(Me, DirectCast(Me.SetProgressBars, IntPtr)))
    48. Me.prg_process.Invoke(New MethodInvoker(AddressOf SetProgressBars))
    49. Else
    50. Me.prg_process.Value = 0
    51. Me.prg_process.Maximum = Me._entriesToZip
    52. Me.prg_process.Minimum = 0
    53. Me.prg_process.Step = 1
    54. Me.prg_process.Value = 0
    55. Me.prg_process.Minimum = 0
    56. Me.prg_process.Maximum = 1
    57. Me.prg_process.Step = 2
    58. End If
    59. End Sub
    60. Private Sub RenameFileInZip(ZipFile As String, oldName As String, newName As String)
    61. Dim archiver As ZipForge = New ZipForge()
    62. ' Set the name of the archive file we want to create
    63. archiver.FileName = ZipFile
    64. ' open an existing ZIP file
    65. archiver.OpenArchive(System.IO.FileMode.Open)
    66. ' rename a file in archive
    67. archiver.RenameFile(oldName, newName)
    68. ' close archive
    69. archiver.CloseArchive()
    70. End Sub
    71. Private Sub zip1_SaveProgress(ByVal sender As Object, ByVal e As SaveProgressEventArgs)
    72. If Me._saveCanceled Then
    73. e.Cancel = True
    74. Return
    75. End If
    76. Select Case e.EventType
    77. Case ZipProgressEventType.Saving_AfterWriteEntry
    78. Me.StepArchiveProgress(e)
    79. Exit Select
    80. Case ZipProgressEventType.Saving_Completed
    81. Me.SaveCompleted()
    82. Exit Select
    83. Case ZipProgressEventType.Saving_EntryBytesRead
    84. Me.StepEntryProgress(e)
    85. Exit Select
    86. End Select
    87. End Sub
    88. Private Sub StepArchiveProgress(ByVal e As SaveProgressEventArgs)
    89. If Me.prg_process.InvokeRequired Then
    90. Me.prg_process.Invoke(New SaveEntryProgress(AddressOf Me.StepArchiveProgress), New Object() {e})
    91. ElseIf Not Me._saveCanceled Then
    92. Me._nFilesCompleted += 1
    93. Me.prg_process.Style = ProgressBarStyle.Blocks
    94. Me.prg_process.PerformStep()
    95. Me._totalBytesAfterCompress = (Me._totalBytesAfterCompress + e.CurrentEntry.CompressedSize)
    96. Me._totalBytesBeforeCompress = (Me._totalBytesBeforeCompress + e.CurrentEntry.UncompressedSize)
    97. ' progressBar2 is the one dealing with the item being added to the archive
    98. ' if we got this event, then the add of that item (or file) is complete, so we
    99. ' update the progressBar2 appropriately.
    100. Me.prg_process.Value = CInt(Me.prg_process.Maximum = 1)
    101. MyBase.Update()
    102. End If
    103. End Sub
    104. Private Sub SaveCompleted()
    105. If Me.lblStatus.InvokeRequired Then
    106. Me.lblStatus.Invoke(New MethodInvoker(AddressOf SaveCompleted))
    107. 'Me.lblStatus.Invoke(New MethodInvoker(Me, DirectCast(Me.SaveCompleted, IntPtr)))
    108. Else
    109. Me.lblStatus.Text = String.Format("Done, Compressed {0} files, {1:N0}% of original", Me._nFilesCompleted, ((100 * Me._totalBytesAfterCompress) / CDbl(Me._totalBytesBeforeCompress)))
    110. Schritt3()
    111. End If
    112. End Sub
    113. Private Sub StepEntryProgress(ByVal e As SaveProgressEventArgs)
    114. If Me.prg_process.InvokeRequired Then
    115. Me.prg_process.Invoke(New SaveEntryProgress(AddressOf Me.StepEntryProgress), New Object() {e})
    116. ElseIf Not Me._saveCanceled Then
    117. If (Me.prg_process.Maximum = 1) Then
    118. Dim entryMax As Long = e.TotalBytesToTransfer
    119. Dim absoluteMax As Long = &H7FFFFFFF
    120. Me._progress2MaxFactor = 0
    121. Do While (entryMax > absoluteMax)
    122. entryMax = CLng((entryMax / 2))
    123. Me._progress2MaxFactor += 1
    124. Loop
    125. If (CInt(entryMax) < 0) Then
    126. entryMax = (entryMax * -1)
    127. End If
    128. Me.prg_process.Maximum = CInt(entryMax)
    129. Me.lblStatus.Text = String.Format("{0} of {1} files...({2})", (Me._nFilesCompleted + 1), Me._entriesToZip, e.CurrentEntry.FileName)
    130. End If
    131. Dim xferred As Integer = CInt((e.BytesTransferred >> Me._progress2MaxFactor))
    132. Me.prg_process.Value = CInt(IIf((xferred >= Me.prg_process.Maximum), Me.prg_process.Maximum, xferred))
    133. MyBase.Update()
    134. End If
    135. End Sub
    136. Private Sub ZipUp(tbDirToZip As String, tbZipToCreate As String)
    137. Dim folderName As String = tbDirToZip
    138. If (((Not folderName Is Nothing) AndAlso (folderName <> "")) AndAlso ((Not tbZipToCreate Is Nothing) AndAlso (tbZipToCreate <> ""))) Then
    139. If File.Exists(tbZipToCreate) Then
    140. If (MessageBox.Show(String.Format("The file you have specified ({0}) already exists. Do you want to overwrite this file?", _
    141. tbZipToCreate), "Confirmation is Required", _
    142. MessageBoxButtons.YesNo, MessageBoxIcon.Question) <> DialogResult.Yes) Then
    143. Return
    144. End If
    145. File.Delete(tbZipToCreate)
    146. End If
    147. Me._saveCanceled = False
    148. Me._nFilesCompleted = 0
    149. Me._totalBytesAfterCompress = 0
    150. Me._totalBytesBeforeCompress = 0
    151. Me.btn_start.Enabled = False
    152. Me.btnCancel.Enabled = True
    153. Me.lblStatus.Text = "Minecraft wird gepackt..."
    154. Dim options As New WorkerOptions
    155. options.ZipName = tbZipToCreate
    156. options.Folder = folderName
    157. _backgroundWorker1 = New System.ComponentModel.BackgroundWorker()
    158. _backgroundWorker1.WorkerSupportsCancellation = False
    159. _backgroundWorker1.WorkerReportsProgress = False
    160. AddHandler Me._backgroundWorker1.DoWork, New DoWorkEventHandler(AddressOf Me.DoSave)
    161. _backgroundWorker1.RunWorkerAsync(options)
    162. End If
    163. End Sub
    164. Private Sub UnzipFile(ByVal sender As Object, ByVal e As DoWorkEventArgs)
    165. Dim extractCancelled As Boolean = False
    166. Dim args() As String = CType(e.Argument, String())
    167. Dim zipToRead As String = args(0)
    168. Dim extractDir As String = args(1)
    169. Try
    170. Using zip As ZipFile = ZipFile.Read(zipToRead)
    171. totalEntriesToProcess = zip.Entries.Count
    172. SetProgressBarMax(zip.Entries.Count)
    173. AddHandler zip.ExtractProgress, New EventHandler(Of ExtractProgressEventArgs)(AddressOf Me.zip_ExtractProgress)
    174. zip.ExtractAll(extractDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
    175. End Using
    176. Catch ex1 As Exception
    177. MessageBox.Show(String.Format("Ein problem ist beim entpacken aufgetreten. {0}", ex1.Message), "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
    178. End Try
    179. End Sub
    180. Private Sub zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
    181. If _operationCanceled Then
    182. e.Cancel = True
    183. Return
    184. End If
    185. If (e.EventType = ZipProgressEventType.Extracting_AfterExtractEntry) Then
    186. StepEntryProgress(e)
    187. ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractAll) Then
    188. '' do nothing
    189. End If
    190. End Sub
    191. Private Sub StepEntryProgress(ByVal e As ExtractProgressEventArgs)
    192. If prg_process.InvokeRequired Then
    193. prg_process.Invoke(New ZipProgress(AddressOf StepEntryProgress), New Object() {e})
    194. Else
    195. prg_process.PerformStep()
    196. System.Threading.Thread.Sleep(100)
    197. 'set a label with status information
    198. nFilesCompleted = nFilesCompleted + 1
    199. lblStatus.Text = String.Format("{0} of {1} files...({2})", nFilesCompleted, totalEntriesToProcess, e.CurrentEntry.FileName)
    200. Me.Update()
    201. End If
    202. End Sub
    203. Private Sub SetProgressBarMax(ByVal n As Integer)
    204. If prg_process.InvokeRequired Then
    205. prg_process.Invoke(New Action(Of Integer)(AddressOf SetProgressBarMax), New Object() {n})
    206. Else
    207. prg_process.Value = 0
    208. prg_process.Maximum = n
    209. prg_process.Step = 1
    210. End If
    211. End Sub
    212. Private Sub Schritt1() 'ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
    213. Status("Füge Mods ein...")
    214. BGWMods.RunWorkerAsync()
    215. End Sub
    216. Private Sub Schritt3()
    217. tmr_close.Start()
    218. End Sub
    219. Private Sub Schritt2()
    220. Dim newminecraft As New FileInfo(txt_minecraftpfad.Text)
    221. Status("Packe das Archiv...")
    222. If newminecraft.Exists Then
    223. newminecraft.Delete()
    224. End If
    225. Me.Invoke(Sub() ZipUp(ExtractPath.FullName, newminecraft.FullName))
    226. End Sub
    227. Private Sub Status(State As String)
    228. Me.Invoke(Sub() lbl_action.Text = State)
    229. End Sub
    230. Private Sub btn_start_Click(sender As Object, e As EventArgs) Handles btn_start.Click
    231. btn_start.Enabled = False
    232. BGWStart.WorkerReportsProgress = True
    233. BGWStart.RunWorkerAsync()
    234. End Sub
    235. Private Sub BGWStart_DoWork(sender As Object, e As DoWorkEventArgs) Handles BGWStart.DoWork
    236. BGWStart.ReportProgress(Nothing, "Konvertiere minecraft.jar...")
    237. If MinecraftZIP.Exists Then
    238. MinecraftZIP.Delete()
    239. End If
    240. MinecraftJAR = txt_minecraftpfad.Text
    241. IO.File.Copy(MinecraftJAR, MinecraftZIP.FullName)
    242. If chk_backup.Checked Then
    243. Status("Backup wird erstellt...")
    244. Dim backupOrdner As New DirectoryInfo(IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft\bin\Backup"))
    245. If Not backupOrdner.Exists Then
    246. backupOrdner.Create()
    247. End If
    248. Dim filename As String = DateTime.Now.ToString.Replace(":", "_")
    249. IO.File.Move(txt_minecraftpfad.Text, backupOrdner.FullName & "\" & filename & ".jar")
    250. End If
    251. BGWStart.ReportProgress(Nothing, "Ändere aux.class...")
    252. Me.RenameFileInZip(MinecraftZIP.FullName, aux, "aux_class")
    253. If ExtractPath.Exists = True Then
    254. IO.Directory.Delete(ExtractPath.FullName, True)
    255. End If
    256. ExtractPath.Create()
    257. BGWStart.ReportProgress(Nothing, "Entpacken...")
    258. Dim TargetDir As String = ExtractPath.FullName
    259. Using zip1 As ZipFile = ZipFile.Read(MinecraftZIP.FullName)
    260. AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress
    261. Dim i As ZipEntry
    262. ' here, we extract every entry, but we could extract
    263. ' based on entry name, size, date, etc.
    264. For Each i In zip1
    265. i.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
    266. Next
    267. End Using
    268. End Sub
    269. Private Sub BGWStart_ProgressChanged(sender As Object, e As ProgressChangedEventArgs) Handles BGWStart.ProgressChanged
    270. Status(e.UserState.ToString)
    271. End Sub
    272. Private Sub BGWStart_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles BGWStart.RunWorkerCompleted
    273. Status("Entpacken erfolgreich")
    274. Schritt1()
    275. End Sub
    276. Private Sub BGWMods_DoWork(sender As Object, e As DoWorkEventArgs) Handles BGWMods.DoWork
    277. Status("Mods werden installiert")
    278. Dim i As Integer
    279. Dim MetainfOrdner As New DirectoryInfo(ExtractPath.FullName & "\META-INF")
    280. If Not ModsOrdner.Exists Then
    281. ModsOrdner.Create()
    282. End If
    283. If Not CoreModsOrdner.Exists Then
    284. CoreModsOrdner.Create()
    285. End If
    286. If MetainfOrdner.Exists Then
    287. Me.Invoke(Sub() lblStatus.Text = "lösche META-INF Ordner")
    288. IO.Directory.Delete(MetainfOrdner.FullName, True)
    289. End If
    290. For i = 0 To lst.Items.Count - 1
    291. If lst.GetItemChecked(i) = True Then
    292. Me.Invoke(Sub() lblStatus.Text = "Aktueller Mod: " & lst.Items.Item(i).ToString)
    293. Select Case lst.Items.Item(i).ToString
    294. Case "Forge"
    295. InstallMod("Forge.zip", installTyp.input)
    296. Case "Optifine HD"
    297. InstallMod("OptiFineHD.zip", installTyp.input)
    298. End Select
    299. End If
    300. Next
    301. Schritt2()
    302. End Sub
    303. Enum installTyp
    304. input 'ZIP Archiv wird entpackt und in die minecraft.jar direkt eingefügt
    305. Add 'ZIP Archiv wird in den Mods Ordner entpackt
    306. CopyInModsFolderOnly 'Datei wird in den Mods Ordner kopiert
    307. CopyInCoreModsFolderOnly 'Die Datei wird in den CoreMods Ordner kopiert
    308. InDirectory 'ZIP Archiv wird in den .minecraft Ordner entpackt
    309. End Enum
    310. Private Sub InstallMod(file As String, install As installTyp)
    311. Dim pfad As DirectoryInfo = Nothing
    312. Dim datei As New FileInfo(Application.StartupPath & "\mods\" & file)
    313. If install = installTyp.Add Then
    314. pfad = New DirectoryInfo(ModsOrdner.FullName)
    315. ElseIf install = installTyp.input Then
    316. pfad = New DirectoryInfo(ExtractPath.FullName)
    317. ElseIf install = installTyp.CopyInModsFolderOnly Then
    318. Try
    319. datei.CopyTo(ModsOrdner.FullName & "\" & datei.Name)
    320. Catch
    321. End Try
    322. Exit Sub
    323. ElseIf install = installTyp.InDirectory Then
    324. pfad = New DirectoryInfo(IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ".minecraft"))
    325. ElseIf install = installTyp.CopyInCoreModsFolderOnly Then
    326. Try
    327. datei.CopyTo(CoreModsOrdner.FullName & "\" & datei.Name)
    328. Catch
    329. End Try
    330. Exit Sub
    331. End If
    332. Dim TargetDir As String = pfad.FullName
    333. Using zip1 As ZipFile = ZipFile.Read(datei.FullName)
    334. 'AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress
    335. Dim i As ZipEntry
    336. ' here, we extract every entry, but we could extract
    337. ' based on entry name, size, date, etc.
    338. For Each i In zip1
    339. i.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
    340. Next
    341. End Using
    342. End Sub
    343. Private Sub MyExtractProgress(sender As Object, e As Ionic.Zip.ExtractProgressEventArgs)
    344. If e.BytesTransferred > 0 AndAlso e.TotalBytesToTransfer > 0 Then
    345. Me.Invoke(Sub() prg_process.Value = CInt(e.BytesTransferred * 100 \ e.TotalBytesToTransfer))
    346. End If
    347. Me.Invoke(Sub() lblStatus.Text = e.CurrentEntry.ToString.Replace("ZipEntry::", "Aktuelle Datei: "))
    348. End Sub
    349. Private Sub chk_select_CheckedChanged(sender As Object, e As EventArgs) Handles chk_select.CheckedChanged
    350. Dim state As Boolean
    351. sate = chk_select.Checked
    352. End If
    353. For i As Integer = 0 To lst.Items.Count - 1
    354. lst.SetItemChecked(i, state)
    355. Next
    356. End Sub
    357. Public Class WorkerOptions
    358. ' Fields
    359. 'Public Comment As String
    360. 'Public CompressionLevel As CompressionLevel
    361. 'Public Encoding As String
    362. 'Public Encryption As EncryptionAlgorithm
    363. Public Folder As String
    364. 'Public Password As String
    365. 'Public Zip64 As Zip64Option
    366. 'Public ZipFlavor As Integer
    367. Public ZipName As String
    368. End Class
    Mfg
    Vincent

    @VincentTB
    Ich finde es ja witzig, dass du den wichtigsten Schritt entfernt hast :)
    DoSave. bzw. überhaupt den letzten Schritt, ich hab mir das mal angeschaut und naja so funkt es nicht :D

    Ohne den wird das glaube ich nichts ;)
    Mfg: Gather
    Private Nachrichten bezüglich VB-Fragen werden Ignoriert!


    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Gather“ ()

    Haha, das gibts doch nicht :pinch: ... Naja, der Code ist im Anhang (wegen der 15.000 Zeichen Beschränkung) oder hier mit Syntax, wo hoffentlich nichts fehlt...

    Anmerkung zu dem Code: IO ist im .Net Framework 3.0 irgendwie total unbrauchbar... Deswegen das ganze My-Zeugs und kein Path.Combine. Außerdem ist es an manchen Stellen schon son bisschen unsauber programmiert, weil ich halt nicht wusste, dass IO.Directory.Delete im .Net Framework 3.0 nicht immer funktioniert und deswegen auch son paar überflüssige Subs. Außerdem solltet ihr nicht alles direkt kopieren, weil ich zb auch maximilians framework ui benutzte... Voraussetzung ist, dass ein Ordner "mods" in dem Ordner der Anwendung ist, wo dann die ganzen Mods sind. Ich hoffe, ich konnte helfen.
    Dateien
    • Code.txt

      (26,85 kB, 203 mal heruntergeladen, zuletzt: )
    Mfg
    Vincent