Click here to Skip to main content
15,445,242 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
I recently switched from using SharpZip to DotNetZip[^] because SharpZip wasn't working out for me. After Referencing the new dll file and writing my code, I had it producing results in debug mode.

However, after I built the application and installed it for a test run, it didn't work. Now it doesn't work in debug mode either and I haven't changed the code I was previously using.

It doesn't give any errors or throw any exceptions. It's simply just not doing anything.

Here's the code I'm using for unzip and zip.

VB
'unpackages the minecraft.jar file
   Private Sub btnUZip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUZip.Click
       'Checks for the folder on the desktop
       If IO.Directory.Exists(Desktop & "\JarUnzipped") Then
           System.IO.File.Delete(Desktop & "\JarUnzipped")
           Try
               'handles the unzipping of the minecraft.jar file
               Dim ZipToUnpack As String = jarpath & "minecraft.jar"
               Dim UnpackDirectory As String = savefolderpath
               Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
                   Dim ze As ZipEntry
                   ' here, we extract every entry, but we could extract conditionally,
                   ' based on entry name, size, date, checkbox status, etc.
                   For Each ze In zip1
                       ze.Extract(UnpackDirectory, ExtractExistingFileAction.OverwriteSilently)
                   Next
               End Using
           Catch
               MsgBox("Something went wrong.")
           End Try
       Else
           Try   'handles the unzipping of the minecraft.jar file
               Dim ZipToUnpack As String = jarpath & "minecraft.jar"
               Dim UnpackDirectory As String = savefolderpath
               Using zip As ZipFile = ZipFile.Read(ZipToUnpack)
                   Dim ze As ZipEntry
                   ' here, we extract every entry, but we could extract conditionally,
                   ' based on entry name, size, date, checkbox status, etc.
                   For Each ze In zip
                       ze.Extract(UnpackDirectory, ExtractExistingFileAction.OverwriteSilently)
                   Next
               End Using
           Catch
               MsgBox("Something went wrong.")
           End Try
      End If
   End Sub
   'creates the newly modded minecraft.jar file
   Private Sub btnZip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnZip.Click
       'Checks for the folder on the desktop
       If IO.File.Exists(ziptocreate) Then
           System.IO.File.Delete(ziptocreate)
           'Handles the Zipping of minecraft.jar
           Dim itempaths As String() = _
             New String() {savefolderpath}
           Try
               Using zip As New ZipFile
                   Dim i As Integer
                   For i = 1 To itempaths.Length - 1
                       ' will add Files or Dirs, recursing and flattening subdirectories.
                       zip.AddItem(itempaths(i), "flat")
                   Next i
                   zip.Save(zippath & "minecraft.jar")
               End Using
           Catch ex1 As Exception
               Console.Error.WriteLine("exception: {0}", ex1.ToString())
           End Try
       Else
           'handles the zipping of minecraft.jar
           Dim itempaths As String() = _
            New String() {savefolderpath}
           Try
               Using zip As New ZipFile
                   Dim i As Integer
                   For i = 1 To itempaths.Length - 1
                       ' will add Files or Dirs, recursing and flattening subdirectories.
                       zip.AddItem(itempaths(i), "flat")
                   Next i
                   zip.Save(zippath & "minecraft.jar")
               End Using
           Catch ex1 As Exception
               Console.Error.WriteLine("exception: {0}", ex1.ToString())
           End Try
       End If
   End Sub




Here's the paths being referenced under
VB
Public Sub frmMod_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


VB
'Obtains the path to the desktop
        Desktop = My.Computer.FileSystem.SpecialDirectories.Desktop
        'Obtains the username for access to the appdata folder
        User = My.Computer.FileSystem.GetParentPath(Desktop)
        'Obtains the Systemdrive for backup storage
        Drive = My.Computer.FileSystem.GetParentPath( _
                My.Computer.FileSystem.GetParentPath(User))
        'finding the minecraft folder in windows vista/7/8
        path4 = User & "\appdata\roaming\.minecraft\"
        'finding the minecraft folder in XP
        path5 = User & "\Application Data\.minecraft\"
        'enables the dotmcf setting
        If IO.Directory.Exists(path4) Then
            dotmcf = path4
        ElseIf IO.Directory.Exists(path5) Then
            dotmcf = path5
        Else
            MsgBox("we cannot find your minecraft folder.")
        End If
        'sets up the paths for zipping and unzipping the minecraft.jar
        savefolderpath = Desktop & "\JarUnzipped\"
        jarpath = dotmcf & "bin\"
        zippath = Drive & "MCBackup\BackedFiles\Mod\"





If anyone spots something I've missed let me know, I've been looking at this code all day trying to figure out what I've doe wrong.
Posted
Comments
Sergey Alexandrovich Kryukov 22-Mar-12 3:08am     CRLF
How about running it under debugger? What's going wrong? --SA
sodacycle 22-Mar-12 3:40am     CRLF
I'm running it under debugger and it's not doing anything. Same no error's exceptions, or results. "Now it doesn't work in debug mode either and I haven't changed the code I was previously using"
Sergey Alexandrovich Kryukov 22-Mar-12 3:43am     CRLF
Under debugger, it cannot be doing anything in principle. I mean step-by-step, of course. Does it go in unexpected way? --SA
sodacycle 22-Mar-12 3:44am    
It doesn't unzip the folder, or give an exception, or give any errors, not even the catch error. It's like the code is nonexistent.
Sergey Alexandrovich Kryukov 22-Mar-12 3:53am     CRLF
Debug it and you will see what's going on. Did you get my previous comment. How about running with F10? There are no such thing as miracle... --SA

At least your last report confirms that I did not see a flaw, except the one with exception. You should remove your "exception handling". You actually suppressing propagation of exceptions. What could happen?

Suppose, on one computer you use the directory which your program has no access to. It often happens to careless programs on Windows 7. By some reason, on other system you do have access. I can see that you are using hard-coded path names in the code. There are no situations where such paths can be useful, but in simple case you can use, say, working directory; typically, in simple console programs you can execute in different working directories. You cannot assume in your code anything related to a particular working directory. This is something not related to the location of your assembly or nothing at all. The user can execute your program from any directories at all, and it will change the locations of paths you are working with. Some use absolute paths; this is even worse.

The program work in one case and throws exception in another. There is no such thing as miracle. Now, as you block propagation of all exceptions, I am not sure that you can see the exception at all. Look, in one case you use MsgBox, is some other — Console. Either of them can be hidden from you. If console is not available (non-console applications), a console output works, but remains completely invisible to the user. This was not a System.Diagnostic.EvenLog which always works.

As a rule of thumb, the exceptions should be caught only on the top of stack of each thread and processed properly. For UI, there is a special way to handle exceptions in the main event cycle (depends on UI library, WPF or Forms). Please see my past answers on the problem.
When i run an application an exception is caught how to handle this?[^],
throw . .then ... rethrowing[^],
Error Logging and Screen Shot.[^],
Catching an Exception[^],
Handling exceptions in class library (dll)[^].

—SA
 
Share this answer
 
It must be zip file corruption. Make use of tool below Zip Fix Toolbox
software is able to start under all popular Windows OS
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900