public configuration_asset(OldUnityXml.qnx old)
 {
     path    = old.filename;
     entry   = "true";
     type    = "Qnx/Elf";
     content = old.filename;
 }
            public qnx(OldUnityXml.qnx old)
            {
                env = new env(old.env);

                author        = old.author;
                authorId      = old.authorId;
                id            = old.id;
                filename      = old.filename;
                name          = old.name;
                description   = old.description;
                publisher     = old.publisher;
                versionNumber = old.versionNumber;

                int assetCount = 5, splashAssetCount = old.splashScreens.images != null ? old.splashScreens.images.Length : 0;

                assets    = new asset[assetCount + splashAssetCount];
                assets[0] = new asset(old.icon.image, old.icon.image);
                assets[1] = new asset("Data", null);
                assets[2] = new asset("lib", null);
                assets[3] = new asset("SLAwards.bundle", "scoreloop/SLAwards.bundle");
                assets[4] = new asset("Release", null);
                for (int i = 0; i != splashAssetCount; ++i)
                {
                    assets[assetCount + i] = new asset(old.splashScreens.images[i], old.splashScreens.images[i]);
                }

                icon          = new icon(old.icon);
                splashScreens = new splashScreens(old.splashScreens);
                initialWindow = new initialWindow(old.initialWindow);
                configuration = new configuration(old);

                category    = old.category;
                permissions = new permission[old.actions.Length];
                for (int i = 0; i != permissions.Length; ++i)
                {
                    permissions[i] = new permission(old.actions[i]);
                }
            }
        public static string ProcessBarFile()
        {
            try
            {
                // extract file
                string path        = Path.GetDirectoryName(BarFileName);
                string extractPath = path + "/" + Path.GetFileNameWithoutExtension(BarFileName);
                if (Directory.Exists(extractPath))
                {
                    Directory.Delete(extractPath, true);
                }
                if (!Directory.Exists(extractPath))
                {
                    Directory.CreateDirectory(extractPath);
                }
                                #if WIN32
                ZipFile.ExtractToDirectory(BarFileName, extractPath);
                                #else
                using (var zip = Ionic.Zip.ZipFile.Read(BarFileName))
                {
                    zip.ExtractAll(extractPath);
                }
                                #endif

                // delete old meta data
                if (Directory.Exists(extractPath + "/META-INF"))
                {
                    Directory.Delete(extractPath + "/META-INF", true);
                }

                // create directories
                if (!Directory.Exists(extractPath + "/native"))
                {
                    Directory.CreateDirectory(extractPath + "/native");
                }

                // copy scoreloop files
                if (!string.IsNullOrEmpty(ScoreloopBundlePath))
                {
                    path = extractPath + "/native/SLAwards.bundle";
                    DirectoryCopy(ScoreloopBundlePath, path, true);
                }

                // update xml manifest
                if (UseClassicMode)
                {
                    var             serializer = new XmlSerializer(typeof(OldUnityXml.qnx), "http://www.BB10.com/schemas/application/1.0");
                    OldUnityXml.qnx oldObj     = null;
                    using (var file = new FileStream(extractPath + "/native/bar-descriptor.xml", FileMode.Open, FileAccess.Read))
                    {
                        oldObj = (OldUnityXml.qnx)serializer.Deserialize(file);
                    }

                    if (oldObj != null)
                    {
                        serializer = new XmlSerializer(typeof(NewUnityXml.qnx), "http://www.qnx.com/schemas/application/1.0");
                        var newObj = new NewUnityXml.qnx(oldObj);
                        using (var file = new FileStream(extractPath + "/native/bar-descriptor.xml", FileMode.Create, FileAccess.Write))
                        {
                            serializer.Serialize(file, newObj);
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to Deserialize bar-descriptor.xml");
                    }
                }
                else
                {
                    var             serializer = new XmlSerializer(typeof(NewUnityXml.qnx), "http://www.BB10.com/schemas/application/1.0");
                    NewUnityXml.qnx oldObj     = null;
                    using (var file = new FileStream(extractPath + "/native/bar-descriptor.xml", FileMode.Open, FileAccess.Read))
                    {
                        oldObj = (NewUnityXml.qnx)serializer.Deserialize(file);
                    }

                    if (oldObj != null)
                    {
                        serializer = new XmlSerializer(typeof(NewUnityXml.qnx), "http://www.qnx.com/schemas/application/1.0");
                        var newObj = new NewUnityXml.qnx(oldObj);
                        using (var file = new FileStream(extractPath + "/native/bar-descriptor.xml", FileMode.Create, FileAccess.Write))
                        {
                            serializer.Serialize(file, newObj);
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to Deserialize bar-descriptor.xml");
                    }
                }

                // repackage bar file >>>
                // <<< set java variables for windows
                                #if WIN32
                Environment.SetEnvironmentVariable("JAVA_HOME", @"C:\Program Files (x86)\Java\jre7\bin");
                                #endif

                // <<< create log file
                createLogFile();

                // get tool path
                string invokePath;
                if (UseClassicMode)
                {
                                        #if WIN32
                    invokePath = UnityPath + @"\Editor\Data\PlaybackEngines\bb10player\blackberry-tools\bin";
                                        #else
                    invokePath = UnityPath + "/Contents/PlaybackEngines/BB10Player/blackberry-tools/bin";
                                        #endif
                }
                else
                {
                                        #if WIN32
                    invokePath = UnityPath + @"\Editor\Data\PlaybackEngines\blackberryplayer\blackberry-tools\bin";
                                        #else
                    invokePath = UnityPath + "/Contents/PlaybackEngines/BlackBerryPlayer/Tools/blackberry-tools/bin";
                                        #endif
                }

                // <<< run packager
                string exe = "blackberry-nativepackager";
                                #if WIN32
                exe += ".bat";
                                #endif
                logWriter.WriteLine("Running " + exe);
                var info = new ProcessStartInfo(invokePath + "/" + exe, string.Format(@"{2}-package ""{0}"" ""{1}""", extractPath + "_Output.bar", extractPath + "/native/bar-descriptor.xml", !SignBarFile ? "-devMode " : ""));
                info.RedirectStandardOutput = true;
                info.RedirectStandardError  = true;
                info.UseShellExecute        = false;
                info.WorkingDirectory       = extractPath + "/native";
                var process = new Process();
                process.StartInfo           = info;
                process.OutputDataReceived += process_OutputDataReceived;
                process.ErrorDataReceived  += process_ErrorDataReceived;
                if (!process.Start())
                {
                    throw new Exception("Failed to start " + exe);
                }
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
                process.WaitForExit();

                // <<< run signer
                if (SignBarFile)
                {
                    exe = "blackberry-signer";
                                        #if WIN32
                    exe += ".bat";
                                        #endif
                    logWriter.WriteLine("Running " + exe);
                    info = new ProcessStartInfo(invokePath + "/" + exe, string.Format(@"-storepass {0} ""{1}""", KeyPassword, extractPath + "_Output.bar"));
                    info.RedirectStandardOutput = true;
                    info.RedirectStandardError  = true;
                    info.UseShellExecute        = false;
                    process                     = new Process();
                    process.StartInfo           = info;
                    process.OutputDataReceived += process_OutputDataReceived;
                    process.ErrorDataReceived  += process_ErrorDataReceived;
                    if (!process.Start())
                    {
                        throw new Exception("Failed to start " + exe);
                    }
                    process.BeginOutputReadLine();
                    process.BeginErrorReadLine();
                    process.WaitForExit();
                }
            }
            catch (Exception e)
            {
                if (logStream != null)
                {
                    logWriter.Close();
                    logStream.Close();
                    logStream = null;
                }
                return(e.Message);
            }

            if (logStream != null)
            {
                logWriter.Close();
                logStream.Close();
                logStream = null;
            }

            return(null);
        }
 public configuration(OldUnityXml.qnx old)
 {
     name = "Device-Release";
     platformArchitecture = "armle-v7";
     asset = new configuration_asset(old);
 }