Author: jerome
Date: 2008-09-19 12:16:36 +0200 (Fri, 19 Sep 2008)
New Revision: 1916

Added:
   
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/
   
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/
   
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/
   
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatCompressor.java
   
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatMisc.java
Modified:
   
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/AttitunesFunctions.java
   
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/ZIP.java
Log:
* Fixed a bug with linux attitunes uncompression.
* Make use of attitunes studio uncompress function.

Modified: 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/AttitunesFunctions.java
===================================================================
--- 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/AttitunesFunctions.java
        2008-09-19 09:19:17 UTC (rev 1915)
+++ 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/AttitunesFunctions.java
        2008-09-19 10:16:36 UTC (rev 1916)
@@ -31,6 +31,8 @@
 
 import org.w3c.dom.Document;
 import org.xml.sax.SAXException;
+
+import com.tuxisalive.attitunes.format.ATTFormatCompressor;
 
 public class AttitunesFunctions {
        
@@ -61,7 +63,7 @@
                try{
                        ZIP new_zip_file = new ZIP(file, ExtractPath);
                        new_zip_file.uncompress();
-                       return new File(ExtractPath.getAbsolutePath() + "/" + 
directory_name + "/scene.xml");
+                       return new File(ExtractPath.getAbsolutePath() + 
File.separator + directory_name + File.separator +"scene.xml");
                }
                catch(Exception e){
                        return null;
@@ -165,7 +167,7 @@
                result = new Object[attitunes.length][8];
                for (int i=0; i != attitunes.length; i++){
                        //get infos.
-                       File temp = new File(AttitunesDirectory + '/' + 
attitunes[i] + ".att");
+                       File temp = new File(AttitunesDirectory + 
File.separator + attitunes[i] + ".att");
                        result[i] = AttitunesFunctions.getAttituneInfo(temp, 
ExtractPath);
                }
                

Modified: 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/ZIP.java
===================================================================
--- 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/ZIP.java
       2008-09-19 09:19:17 UTC (rev 1915)
+++ 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxdroid/cc/Utils/ZIP.java
       2008-09-19 10:16:36 UTC (rev 1916)
@@ -28,7 +28,8 @@
 import java.io.IOException;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
+import java.util.zip.ZipOutputStream;
+import com.tuxisalive.attitunes.format.*;
 
 /***
  * This class allow to unzip files ( attitunes format in our case ).
@@ -40,7 +41,9 @@
     /** source file or directory (depends of called function **/
     private File src = null;
     /** destination file or directory, also depends of called function **/
-    private File dst = null;
+    private File dst = null;
+    
+    private String name;
 
     
     /***
@@ -50,8 +53,9 @@
      * @param dst : Destination directory.
      */
     public ZIP(File src, File dst) {
-        this.src = src;
-        this.dst = dst;
+        this.src = src;
+        this.dst = dst;
+        System.out.println(this.dst.getAbsolutePath());
     }
 
     
@@ -105,34 +109,7 @@
         zos.close();
     }
 
-    public void uncompress() throws Exception {
-        ZipInputStream zis = new ZipInputStream(new FileInputStream(src));
-
-        ZipEntry zen = null;
-        if (!dst.exists())
-            dst.mkdir();
-        while ((zen = zis.getNextEntry()) != null) {
-            if (zen.isDirectory())
-                new File(dst.getAbsolutePath() + File.separator + 
zen.getName())
-                        .mkdir();
-        
-            else {
-                File f = new File(dst.getAbsolutePath() + File.separator
-                        + zen.getName());
-                if (!f.getParentFile().exists())
-                    f.getParentFile().mkdirs();
-                FileOutputStream out = new FileOutputStream(dst
-                        .getAbsolutePath()
-                        + File.separator + zen.getName());
-                //transfere les byte compresse vers le fichier de sortie
-                byte[] buf = new byte[MAX_PAQUET_SIZE];
-                int offset;
-                while ((offset = zis.read(buf)) > 0)
-                    out.write(buf, 0, offset);
-                out.close();
-            }
-        }
-        zis.closeEntry();
-        zis.close();
+    public void uncompress() throws Exception {
+       ATTFormatCompressor.uncompressAttitune(this.src.getAbsolutePath(), 
this.dst.getAbsolutePath() + "/");
     }
 }
\ No newline at end of file

Added: 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatCompressor.java
===================================================================
--- 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatCompressor.java
                             (rev 0)
+++ 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatCompressor.java
     2008-09-19 10:16:36 UTC (rev 1916)
@@ -0,0 +1,169 @@
+/* This file is part of "Attitunes studio".
+ *    Copyright 2008, kysoh
+ *    Author : Remi Jocaille
+ *    eMail  : [EMAIL PROTECTED]
+ *    Site   : http://www.kysoh.com/
+ *
+ * "Attitunes studio" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Attitunes studio" is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Gadget Mail"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.tuxisalive.attitunes.format;
+
+import java.io.*;
+import java.util.zip.*;
+
+public class ATTFormatCompressor
+{
+       private static ZipOutputStream zos;
+
+       /**
+        * 
+        * @param sourcePath
+        * @return
+        */
+       public static boolean compressAttitune(String attFilePath, String 
sourcePath)
+       {
+               File file = new File(sourcePath);
+               
+               try
+               {
+                       zos = new ZipOutputStream(new FileOutputStream(new 
File(attFilePath)));
+                       recurseFiles(file, sourcePath);
+                       zos.close();
+               }
+               catch (Exception e)
+               {
+                       e.printStackTrace();
+                       return false;
+               }
+               return true;
+       }
+
+       /**
+        * 
+        * @param attFilePath
+        * @param tmpAttDir
+        * @return
+        */
+       public static boolean uncompressAttitune(String attFilePath, String 
destinationPath)
+       {
+               FileOutputStream fos = null;
+               BufferedOutputStream dest = null;
+               FileInputStream fis;
+               ZipInputStream zis;
+               ZipEntry entry;
+               int count;
+               byte data[] = new byte[8192];
+               
+               try
+               {
+                       fis = new FileInputStream(attFilePath);
+                       zis = new ZipInputStream(new BufferedInputStream(fis));
+                       
+               while ((entry = zis.getNextEntry()) != null)
+               {
+                       if (!entry.isDirectory())
+                       {
+                               if (!prepareFileDirectories(destinationPath, 
entry.getName()))
+                               {
+                                       return false;
+                               }
+                               String destFileName = 
ATTFormatMisc.regularizePath(destinationPath + File.separator + 
entry.getName());
+                               try
+                               {
+                                       fos = new 
FileOutputStream(destFileName);
+                               }
+                               catch (Exception e)
+                               {
+                                       return false;
+                               }
+                       dest = new BufferedOutputStream(fos, 8192);
+                       while((count = zis.read(data, 0, 8192)) != -1)
+                       {
+                         dest.write(data, 0, count);
+                       }
+                       dest.flush();
+                       dest.close();
+                       }
+               }
+               zis.close();
+               }
+               catch (Exception e)
+               {
+                       e.printStackTrace();
+                       return false;
+               }
+               
+               return true;
+       }
+
+       /*
+        *
+        */
+       private static void recurseFiles(File file, String basePath) 
+               throws IOException, FileNotFoundException
+       {
+               String filePath;
+               
+               if (file.isDirectory())
+               {
+               String[] fileNames = file.list();
+               if (fileNames != null)
+               {
+                   for (int i=0; i<fileNames.length; i++)
+                   {
+                      recurseFiles(new File(file, fileNames[i]), basePath);
+                   }
+               }
+               }
+           else
+           {
+               byte[] buf = new byte[1024];
+               int len;
+
+               filePath = file.toString().substring(0, basePath.length());
+               ZipEntry zipEntry = new 
ZipEntry(file.toString().replace(filePath, ""));
+               FileInputStream fin = new FileInputStream(file);
+               BufferedInputStream in = new BufferedInputStream(fin);
+               zos.putNextEntry(zipEntry);
+               
+               while ((len = in.read(buf)) >= 0)
+               {
+                       zos.write(buf, 0, len);
+               }
+               
+               in.close();
+               zos.closeEntry();
+           }
+       }
+       
+       /*
+        * 
+        */
+       private static boolean prepareFileDirectories(String destination, 
String entryName)
+       {
+               String outputFileName = 
ATTFormatMisc.regularizePath(destination + entryName);
+               try
+               {
+                       new File(outputFileName.substring(0, 
outputFileName.lastIndexOf(File.separator))).mkdirs();
+               }
+               catch (Exception e)
+               {
+                       return false;
+               }
+               return true;
+       }
+}


Property changes on: 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatCompressor.java
___________________________________________________________________
Name: svn:executable
   + *

Added: 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatMisc.java
===================================================================
--- 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatMisc.java
                           (rev 0)
+++ 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatMisc.java
   2008-09-19 10:16:36 UTC (rev 1916)
@@ -0,0 +1,196 @@
+/* This file is part of "Attitunes studio".
+ *    Copyright 2008, kysoh
+ *    Author : Remi Jocaille
+ *    eMail  : [EMAIL PROTECTED]
+ *    Site   : http://www.kysoh.com/
+ *
+ * "Attitunes studio" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Attitunes studio" is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid Gadget Mail"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.tuxisalive.attitunes.format;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class ATTFormatMisc
+{
+       private static String goodSepSlash = "";
+       private static String badSepSlash = "";
+       
+       static
+       {
+               if (System.getProperty("os.name").contains("Windows"))
+               {
+                       goodSepSlash = "\\";
+                       badSepSlash = "/";
+               }
+               else
+               {
+                       goodSepSlash = "/";
+                       badSepSlash = "\\";
+               }
+       }
+
+       /**
+        * 
+        */
+       public static File createTmpAttDir() throws IOException
+       {
+               File tempFile = File.createTempFile("attitunesF", "", null);
+               
+        if (!tempFile.delete())
+        {
+            throw new IOException();
+        }
+        
+        if (!tempFile.mkdir())
+        {
+            throw new IOException();
+        }
+        
+        tempFile.deleteOnExit();
+        return tempFile;
+       }
+       
+       /**
+        * 
+        * @param srcPath
+        * @param destPath
+        * @return
+        */
+       public static boolean copyDir(String srcPath, String destPath)
+       {
+               File src = new File(srcPath);
+               File dest = new File(destPath);
+               
+               if (src.isDirectory())
+               {
+                       dest.mkdirs();
+                       String list[] = src.list();
+
+                       for (int i = 0; i < list.length; i++)
+                       {
+                               String dest1 = dest.getAbsolutePath() + 
File.separator + list[i];
+                               String src1 = src.getAbsolutePath() + 
File.separator + list[i];
+                               if (!copyDir(src1 , dest1))
+                               {
+                                       return false;
+                               }
+                       }
+               }
+               else
+               {
+                       if (!copyfile(srcPath, destPath))
+                       {
+                               return false;
+                       }
+               }
+               return true;
+       }
+       
+       /**
+        * 
+        * @param srcPath
+        * @return
+        */
+       public static boolean deleteDir(String srcPath)
+       {
+               File dir = new File(srcPath);
+               
+               if (dir.isDirectory()) {
+            String[] children = dir.list();
+            for (int i=0; i<children.length; i++) {
+                boolean success = deleteDir(new File(dir, 
children[i]).getAbsolutePath());
+                if (!success) {
+                    return false;
+                }
+            }
+        }
+    
+        // The directory is now empty so delete it
+        return dir.delete();
+
+       }
+       
+       /**
+        * 
+        */
+       public static boolean copyfile(String srcFile, String destFile)
+       {
+           try
+           {
+               File f1 = new File(srcFile);
+               File f2 = new File(destFile);
+               InputStream in = new FileInputStream(f1);
+               OutputStream out = new FileOutputStream(f2);
+               byte[] buf = new byte[1024];
+               int len;
+               
+               while ((len = in.read(buf)) > 0)
+               {
+                       out.write(buf, 0, len);
+               }
+               
+               in.close();
+               out.close();
+           }
+           catch (Exception e)
+           {
+               return false;
+           }
+           
+           return true;
+       }
+       
+       /**
+        * 
+        * @param waveName
+        */
+       public static boolean deleteFile(String filePath)
+       {
+               File f = new File(filePath);
+
+               if (f.exists())
+               {
+                       if (f.delete())
+                       {
+                               return true;
+                       }
+               }
+               return false;
+       }
+       
+       /**
+        * 
+        * @param path
+        * @return
+        */
+       public static String regularizePath(String path)
+       {
+               String result = path;
+               
+               result = result.replace("\\\\", "&&&&");
+               result = result.replace("//", "&&&&");
+               result = result.replace(badSepSlash, "&&&&");
+               result = result.replace("&&&&", goodSepSlash);
+               
+               return result;
+       }
+}


Property changes on: 
software_suite_v2/software/control_center/trunk/control_center/sources/com/tuxisalive/attitunes/format/ATTFormatMisc.java
___________________________________________________________________
Name: svn:executable
   + *


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to