// Path: source-code/app/src/main/java/org/buildmlearn/toolkit/ToolkitApplication.java
// public class ToolkitApplication extends Application {
// 
//     private static String dir;
// 
//     private static boolean isExternalStorageAvailable = false;
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for unzipped apks
//      */
//     public static String getUnZipDir() {
//         return dir + Constants.UNZIP;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         storagePathsValidate();
//     }
// 
//     public void storagePathsValidate() {
//         if (checkExternalStorage()) {
//             isExternalStorageAvailable = true;
//             dir = Environment.getExternalStorageDirectory().getAbsolutePath();
//         } else {
//             dir = getFilesDir().getAbsolutePath();
//         }
// 
//         ArrayList<String> paths = new ArrayList<>();
//         paths.add(getProjectDir());
//         paths.add(getApkDir());
//         paths.add(getSavedDir());
//         paths.add(getUnZipDir());
// 
//         for (String path : paths) {
//             File f = new File(path);
//             if (!f.isDirectory()) {
//                 f.mkdirs();
//             }
//         }
//     }
// 
//     /**
//      * @return folder file
//      * @brief Returns external storage directory.
//      */
//     public File getDir() {
//         return Environment.getExternalStorageDirectory();
//     }
// 
//     /**
//      * @return folder path
//      * @brief Returns directory for BuildmLearn toolkit  manually created files.
//      */
//     public String getProjectDir() {
//         return dir + Constants.BUILD_M_LEARN_PATH;
// 
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for saved projects
//      */
//     public String getSavedDir() {
//         return dir + Constants.SAVED_DIR;
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for saved projects
//      */
//     public String getDraftDir() {
//         return dir + Constants.DRAFT_DIR;
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for storing generated apks
//      */
//     public String getApkDir() {
//         return dir + Constants.APK_DIR;
//     }
// 
//     /**
//      * @return true if external storage is present, else false
//      * @brief Checks if external storage is present for storing data
//      */
//     public boolean checkExternalStorage() {
// 
//         boolean result = false;
//         File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/BuildmLearn123/");
//         if (!f.isDirectory()) {
//             result = f.mkdirs();
//             f.delete();
//         }
//         return result;
//     }
// 
//     public boolean isExternalStorageAvailable() {
//         return isExternalStorageAvailable;
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for Download directory
//      */
//     public String getDownloadDirectory() {
//         return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
//     }
// }


import android.content.Context;
import org.buildmlearn.toolkit.ToolkitApplication;
import org.buildmlearn.toolkit.model.Template;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
package org.buildmlearn.toolkit.utilities;

/**
 * Created by scopeinfinity on 14/3/16.
 */





/**
 * @brief Class for extracting .buildmlearn file from apk.
 */
public class RestoreThread extends Thread {
    private static final String TEMP_FOLDER = "rtf";
    private final Context context;
    private final InputStream zipInputStream;

    private OnRestoreComplete listener;

    public RestoreThread(Context context, InputStream zipInputStream) {
        this.context = context;
        this.zipInputStream = zipInputStream;
    }

    public void setRestoreListener(OnRestoreComplete listener) {
        this.listener = listener;
    }

    @Override
    public void run() {
        try {
            String assetDirectory = "assets";
            File assetDir = new File(ToolkitApplication.getUnZipDir() + TEMP_FOLDER + "/" + assetDirectory);
            assetDir.mkdirs();
            //Deleting Previous Files if Exists
            File[] templateAssets = assetDir.listFiles();
// Path: source-code/app/src/main/java/org/buildmlearn/toolkit/ToolkitApplication.java
// public class ToolkitApplication extends Application {
// 
//     private static String dir;
// 
//     private static boolean isExternalStorageAvailable = false;
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for unzipped apks
//      */
//     public static String getUnZipDir() {
//         return dir + Constants.UNZIP;
//     }
// 
//     @Override
//     public void onCreate() {
//         super.onCreate();
//         storagePathsValidate();
//     }
// 
//     public void storagePathsValidate() {
//         if (checkExternalStorage()) {
//             isExternalStorageAvailable = true;
//             dir = Environment.getExternalStorageDirectory().getAbsolutePath();
//         } else {
//             dir = getFilesDir().getAbsolutePath();
//         }
// 
//         ArrayList<String> paths = new ArrayList<>();
//         paths.add(getProjectDir());
//         paths.add(getApkDir());
//         paths.add(getSavedDir());
//         paths.add(getUnZipDir());
// 
//         for (String path : paths) {
//             File f = new File(path);
//             if (!f.isDirectory()) {
//                 f.mkdirs();
//             }
//         }
//     }
// 
//     /**
//      * @return folder file
//      * @brief Returns external storage directory.
//      */
//     public File getDir() {
//         return Environment.getExternalStorageDirectory();
//     }
// 
//     /**
//      * @return folder path
//      * @brief Returns directory for BuildmLearn toolkit  manually created files.
//      */
//     public String getProjectDir() {
//         return dir + Constants.BUILD_M_LEARN_PATH;
// 
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for saved projects
//      */
//     public String getSavedDir() {
//         return dir + Constants.SAVED_DIR;
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for saved projects
//      */
//     public String getDraftDir() {
//         return dir + Constants.DRAFT_DIR;
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for storing generated apks
//      */
//     public String getApkDir() {
//         return dir + Constants.APK_DIR;
//     }
// 
//     /**
//      * @return true if external storage is present, else false
//      * @brief Checks if external storage is present for storing data
//      */
//     public boolean checkExternalStorage() {
// 
//         boolean result = false;
//         File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/BuildmLearn123/");
//         if (!f.isDirectory()) {
//             result = f.mkdirs();
//             f.delete();
//         }
//         return result;
//     }
// 
//     public boolean isExternalStorageAvailable() {
//         return isExternalStorageAvailable;
//     }
// 
//     /**
//      * @return Folder path
//      * @brief Returns folder path for Download directory
//      */
//     public String getDownloadDirectory() {
//         return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
//     }
// }


// Path: source-code/app/src/main/java/org/buildmlearn/toolkit/utilities/RestoreThread.java
import android.content.Context;
import org.buildmlearn.toolkit.ToolkitApplication;
import org.buildmlearn.toolkit.model.Template;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

package org.buildmlearn.toolkit.utilities;

/**
 * Created by scopeinfinity on 14/3/16.
 */





/**
 * @brief Class for extracting .buildmlearn file from apk.
 */
public class RestoreThread extends Thread {
    private static final String TEMP_FOLDER = "rtf";
    private final Context context;
    private final InputStream zipInputStream;

    private OnRestoreComplete listener;

    public RestoreThread(Context context, InputStream zipInputStream) {
        this.context = context;
        this.zipInputStream = zipInputStream;
    }

    public void setRestoreListener(OnRestoreComplete listener) {
        this.listener = listener;
    }

    @Override
    public void run() {
        try {
            String assetDirectory = "assets";
            File assetDir = new File(ToolkitApplication.getUnZipDir() + TEMP_FOLDER + "/" + assetDirectory);
            assetDir.mkdirs();
            //Deleting Previous Files if Exists
            File[] templateAssets = assetDir.listFiles();
            for (File data : templateAssets) {