Patch for Issue 587 - randomly sorted Zip files

Discuss issues related to PS3 Media Server development (only for programmers)

Patch for Issue 587 - randomly sorted Zip files

Postby Donut » Thu Jun 30, 2011 11:20 pm

Hi there.

I created a patch to fix issue number 587. The content of a zip file will now be listed ascending by the filename.


Hope you like it, but every hint or comment for improvement is (of course) welcome


Ciao

Donut

Code: Select all
Index: net/pms/dlna/ZippedFile.java
===================================================================
--- net/pms/dlna/ZippedFile.java   (revision 704)
+++ net/pms/dlna/ZippedFile.java   (working copy)
@@ -23,6 +23,10 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
@@ -45,8 +49,18 @@
       try {
          zip = new ZipFile(z);
          Enumeration<? extends ZipEntry> enm = zip.entries();
+         List<ZipEntry> zipEntryList = new ArrayList<ZipEntry>();
          while (enm.hasMoreElements()) {
-            ZipEntry ze = enm.nextElement();
+            zipEntryList.add(enm.nextElement());
+         }
+         Collections.sort(zipEntryList, new Comparator<ZipEntry>() {
+
+            @Override
+            public int compare(ZipEntry o1, ZipEntry o2) {
+               return o1.getName().compareTo(o2.getName());
+            }
+         });
+         for(ZipEntry ze: zipEntryList){
             addChild(new ZippedEntry(z, ze.getName(), ze.getSize()));
          }
          zip.close();
Donut
 
Posts: 6
Joined: Fri Nov 20, 2009 11:49 am

Re: Patch for Issue 587 - randomly sorted Zip files

Postby Donut » Fri Jul 01, 2011 12:18 am

Hi again,

I just reworked my patch again. Now the content of a zip file is sorted as defined for all other elements in the GUI. I took the pattern from "net.pms.dlna.MapFile.java" (starting with line 165).

Donut

Code: Select all
Index: net/pms/dlna/ZippedFile.java
===================================================================
--- net/pms/dlna/ZippedFile.java   (revision 704)
+++ net/pms/dlna/ZippedFile.java   (working copy)
@@ -23,12 +23,17 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
 import java.util.Enumeration;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipException;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipInputStream;
 
+import net.pms.PMS;
 import net.pms.formats.Format;
 
 import org.slf4j.Logger;
@@ -45,8 +50,28 @@
       try {
          zip = new ZipFile(z);
          Enumeration<? extends ZipEntry> enm = zip.entries();
+         List<ZipEntry> zipEntryList = new ArrayList<ZipEntry>();
          while (enm.hasMoreElements()) {
-            ZipEntry ze = enm.nextElement();
+            zipEntryList.add(enm.nextElement());
+         }
+         Collections.sort(zipEntryList, new Comparator<ZipEntry>() {
+
+            @Override
+            public int compare(ZipEntry o1, ZipEntry o2) {
+               switch(PMS.getConfiguration().getSortMethod()){
+                  case 3: // Case-insensitive ASCIIbetical sort
+                     return o1.getName().compareToIgnoreCase(o2.getName());
+                  case 2:// Sort by modified date, oldest first
+                     return (new Long(o1.getTime()).compareTo(new Long(o2.getTime())));
+                  case 1:// Sort by modified date, newest first
+                     return (new Long(o2.getTime()).compareTo(new Long(o1.getTime())));
+                  default:// locale-sensitive A-Z
+                     return o1.getName().compareTo(o2.getName());
+               }
+               
+            }
+         });
+         for(ZipEntry ze: zipEntryList){
             addChild(new ZippedEntry(z, ze.getName(), ze.getSize()));
          }
          zip.close();
Attachments
sortedZip.patch.zip
(869 Bytes) Downloaded 106 times
Donut
 
Posts: 6
Joined: Fri Nov 20, 2009 11:49 am


Return to Developers

Who is online

Users browsing this forum: No registered users and 2 guests