Ejemplo n.º 1
0
        //public static Level GetDownloadedLevel(string levelDirectoryName)
        //{
        //    string rootPckPath = PACKAGES_FOLDER_PATH + Path.DirectorySeparatorChar + CultureInfo.CurrentUICulture.TwoLetterISOLanguageName + Path.DirectorySeparatorChar;

        //    using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
        //    {
        //        if (levelDirectoryName.StartsWith(LEVEL_PREFIX) && isoStore.FileExists(rootPckPath + levelDirectoryName + Path.DirectorySeparatorChar + levelDirectoryName + GameDBHelper.DB_FILE_NAME_EXTENSION))
        //        {
        //            string dbPath = rootPckPath + levelDirectoryName + Path.DirectorySeparatorChar + levelDirectoryName + GameDBHelper.DB_FILE_NAME_EXTENSION;
        //            return GetDownloadedLevelFromDbPath(dbPath);


        //            //using (PackageDal dal = new PackageDal(rootPckPath + packDirectoryName + Path.DirectorySeparatorChar + packDirectoryName + PackageDal.DB_FILE_NAME_EXTENSION))
        //            //{
        //            //    if (dal.OpenDatabase())
        //            //    {
        //            //        return dal.GetPackage();
        //            //    }
        //            //}
        //        }
        //    }
        //    return null;
        //}


        //public static Level GetDownloadedLevelFromDbPath(string fullDataBasePath)
        //{
        //    using (LevelDBHelper dal = new LevelDBHelper(fullDataBasePath))
        //    {
        //        if (dal.OpenDatabase())
        //        {
        //            var levels = dal.GetLevels();
        //            if (levels == null || levels.Count == 0)
        //                return null;

        //            return levels.First().Value;
        //        }
        //    }
        //    return null;
        //}


        private static void ExtractZipFile(string archiveFilenameIn, string password, string outFolderPath)
        {
            using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                Stream stream = null;
                try
                {
                    using (UnZipper unzip = new UnZipper(isoStore.OpenFile(archiveFilenameIn, FileMode.Open)))
                    {
                        foreach (string filename in unzip.FileNamesInZip)
                        {
                            stream = unzip.GetFileStream(filename);
                            string correctedFilename = filename.Replace("/", "" + Path.DirectorySeparatorChar);
                            IsolatedStorageHelpers.SaveFileAndCreateParentFolders(outFolderPath + Path.DirectorySeparatorChar + correctedFilename, stream);
                        }
                    }
                }
                finally
                {
                    if (stream != null)
                    {
                        stream.Close(); // Ensure we release resources
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void DeployLevelsInApp(ResourceManager appRessourceManager)
        {
            List <string> levelsToDeployList    = new List <string>();
            List <string> levelsInstalledDbPath = new List <string>();

            // Retrieve package list of current Language
            //ResourceManager rm = new ResourceManager("MovieQuizz2.Resources.AppResources", Assembly.GetExecutingAssembly());
            ResourceManager rm          = appRessourceManager;
            ResourceSet     resourceSet = rm.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

            foreach (DictionaryEntry entry in resourceSet)
            {
                string key = entry.Key as string;
                Debug.WriteLine(key);
                if (key != null && key.StartsWith(LEVEL_PREFIX) && entry.Value.GetType() == typeof(byte[]))
                {
                    Debug.WriteLine(key + " " + entry.Value);
                    levelsToDeployList.Add(key);
                }
            }

            foreach (string levelName in levelsToDeployList)
            {
                string levelNameZip = levelName + LEVEL_COMPRESS_EXTENSION;

                // test if package is already installed
                if (!IsLevelAlreadyInstalled(levelName))
                {
                    //var sr = Application.GetResourceStream(new Uri(f, UriKind.Relative));
                    byte[] sr = rm.GetObject(levelName, CultureInfo.CurrentUICulture) as byte[];


                    if (sr != null)
                    {
                        IsolatedStorageHelpers.SaveFileAndCreateParentFolders(PACKAGES_TEMP_FOLDER_PATH + Path.DirectorySeparatorChar + levelNameZip, sr);
                        string dbPath = InstallLevelFiles(levelNameZip, levelName);
                        levelsInstalledDbPath.Add(dbPath);
                    }
                }
            }

            LevelsNewlyInstalledDbPath = levelsInstalledDbPath;
        }
Ejemplo n.º 3
0
        public void InstallMainDb(ResourceManager appRessourceManager)
        {
            // We install main DB
            Assembly currentAssembly = Assembly.GetExecutingAssembly();

            //string[] resources = currentAssembly.GetManifestResourceNames();

            //// Build the string of resources.
            //foreach (string resource in resources)
            //    Debug.WriteLine(resource);

            // Create a stream for the file in the installation folder.
            IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();

            byte[] main_Db_Ressource = QuizzApp.Ressources.QuizzAppResource.game;

            //Uri uri = new Uri("QuizzApp;component/Ressources/Database/" + MAIN_DATABASE_FILE_NAME, UriKind.Relative);
            //var resStream = Application.GetResourceStream(uri);

            using (Stream input = new MemoryStream(main_Db_Ressource))
            {
                // Create a stream for the new file in the local folder.
                IsolatedStorageHelpers.CreateParentFolders(MAIN_DATABASE_PATH);
                using (IsolatedStorageFileStream output = iso.CreateFile(MAIN_DATABASE_PATH))
                {
                    // Initialize the buffer.
                    byte[] readBuffer = new byte[4096];
                    int    bytesRead  = -1;

                    // Copy the file from the installation folder to the local folder.
                    while ((bytesRead = input.Read(readBuffer, 0, readBuffer.Length)) > 0)
                    {
                        output.Write(readBuffer, 0, bytesRead);
                    }
                }
            }


            // Create Default Difficulties
        }
Ejemplo n.º 4
0
        public void MigrateMovieQuizz1Packs()
        {
            List <int> mq1PacksFinishedIds = new List <int>();

            // Check status
            if (!AreMovieQuizz1MigrationKeysSaved())
            {
                // Loop on all packsTypes
                var mq1Types = EnumHelpers.GetEnumValues <MQ1PacksTypes>();

                foreach (MQ1PacksTypes packType in mq1Types)
                {
                    // Loop on all MQ1 installed packs
                    // if pack is finished, add to list
                    using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        string rootPckPath = MQ1_PACKAGES_FOLDER_PATH + Path.DirectorySeparatorChar + AppSettings.Instance.LanguageOnAppLaunchBck + Path.DirectorySeparatorChar + (int)packType + Path.DirectorySeparatorChar;
                        if (!isoStore.DirectoryExists(rootPckPath))
                        {
                            continue;
                        }

                        // Retrieve directories.
                        List <String> directoryList = new List <String>(isoStore.GetDirectoryNames(rootPckPath + "*"));

                        // Add all directories at this directory
                        foreach (string directoryName in directoryList)
                        {
                            if (directoryName == "pack_30")
                            {
                                int aa = 0;
                                aa++;
                            }

                            if (directoryName.StartsWith(MQ1_PACKAGE_PREFIX) && isoStore.FileExists(rootPckPath + directoryName + Path.DirectorySeparatorChar + directoryName + MigrationDbHelper.DB_FILE_NAME_EXTENSION))
                            {
                                int packId;
                                if (int.TryParse(directoryName.Replace(MQ1_PACKAGE_PREFIX, string.Empty), out packId))
                                {
                                    using (MigrationDbHelper dal = new MigrationDbHelper(rootPckPath + directoryName + Path.DirectorySeparatorChar + directoryName + MigrationDbHelper.DB_FILE_NAME_EXTENSION))
                                    {
                                        if (dal.OpenDatabase() && dal.IsPackFinished(packId))
                                        {
                                            mq1PacksFinishedIds.Add(packId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Save List on AppSettings
                AppSettings.Instance.AddOrUpdateValue(MOVIE_QUIZZ_1_PACKS_TERMINATED_IDS, mq1PacksFinishedIds);

                // Flag import done
                AppSettings.Instance.AddOrUpdateValue(ARE_MOVIE_QUIZZ_1_MIGRATION_KEYS_SAVED, true);

                AppSettings.Instance.Save();
            }



            // DELETE ALL MOVIE QUIZZ 1 PACKS
            if (!AreMovieQuizz1PacksDeletedDone() && AreMovieQuizz1MigrationKeysSaved())
            {
                using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    string rootPckPath = MQ1_PACKAGES_FOLDER_PATH + Path.DirectorySeparatorChar;
                    if (isoStore.DirectoryExists(rootPckPath))
                    {
                        IsolatedStorageHelpers.CleanAndDeleteDirectoryRecursive(rootPckPath);
                    }
                }

                AppSettings.Instance.AddOrUpdateValue(ARE_MOVIE_QUIZZ_1_PACKS_DELETED, true);
                AppSettings.Instance.Save();
            }
        }