Пример #1
0
        private async Task <int> AddMaterialData_SplitFile(ThemePack theme, string folder)
        {
            int materialCount = 0;

            //read theme pack materials file (xml)
            string xmlFilePath = Path.Combine(folder, "materials.xml");

            try
            {
                //MaterialGroup newMaterials = await XmlHelper.Deserialize<MaterialGroup>(path); /* the xml file is incomplete sometimes */
                List <Material> newMaterials = await LoadMaterialXML(xmlFilePath);

                materialCount = newMaterials.Count;

                //load my material file
                if (materialDataLoader == null)
                {
                    materialDataLoader = new DataLoader <MaterialGroup>();
                }

                string materialFilePath = Path.Combine(folder, Constants.MATERIAL_DATA_FILE);
                var    materialGroup    = await materialDataLoader.LoadLocalData(materialFilePath);

                if (materialGroup == null)
                {
                    materialGroup = new MaterialGroup();
                }

                //add new materials
                foreach (var m in newMaterials)
                {
                    m.themePackID = theme.id;

                    //image full path
                    string imagePath = Path.Combine(folder, m.image);
                    m.image = imagePath;

                    //thumbnail full path
                    string thumbnailPath = Path.Combine(folder, m.thumbnail);
                    m.thumbnail = thumbnailPath;

                    materialGroup.Materials.Add(m);
                }

                //save data
                string json = JsonSerializer.Serialize(materialGroup);
                await IsolatedStorageHelper.WriteToFileAsync(materialFilePath, json);
            }
            catch (Exception ex)
            {
                somethingWrong = true;
            }

            return(materialCount);
        }
Пример #2
0
        private async Task AddMaterialData_SingleFile(ThemePack theme, string folder)
        {
            //read theme pack materials file (xml)
            string path = Path.Combine(folder, "materials.xml");

            try
            {
                //MaterialGroup newMaterials = await XmlHelper.Deserialize<MaterialGroup>(path); /* the xml file is incomplete sometimes */
                List <Material> newMaterials = await LoadMaterialXML(path);

                //load my material file
                if (materialDataLoader == null)
                {
                    materialDataLoader = new DataLoader <MaterialGroup>();
                }
                var myMaterials = await materialDataLoader.LoadLocalData(Constants.THEME_MODULE, Constants.MY_MATERIAL_FILE);

                if (myMaterials == null)
                {
                    myMaterials = new MaterialGroup();
                }

                //add new materials
                foreach (var m in newMaterials)
                {
                    m.themePackID = theme.id;

                    //image full path
                    string imagePath = Path.Combine(folder, m.image);
                    m.image = imagePath;

                    //thumbnail full path
                    string thumbnailPath = Path.Combine(folder, m.thumbnail);
                    m.thumbnail = thumbnailPath;

                    myMaterials.Materials.Add(m);
                }

                //save data
                string json = JsonSerializer.Serialize(myMaterials);
                await IsolatedStorageHelper.WriteToFileAsync(Constants.THEME_MODULE, Constants.MY_MATERIAL_FILE, json);
            }
            catch (Exception ex)
            {
                somethingWrong = true;
            }
        }
Пример #3
0
        private TextDefinition RequiredThemePackMessage(ThemePack pack)
        {
            switch (pack)
            {
            case ThemePack.Kings:
                return(1154195);    // *Requires the "King's Collection" theme pack

            case ThemePack.Rustic:
                return(1150651);    // * Requires the "Rustic" theme pack

            case ThemePack.Gothic:
                return(1150650);    // * Requires the "Gothic" theme pack

            default:
                return(String.Format("Requires the \"{0}\" theme pack.", null));
            }
        }
Пример #4
0
        private async Task AddMyThemeData(ThemePack themePack, int materialCount)
        {
            try
            {
                if (myThemeDataLoader == null)
                {
                    myThemeDataLoader = new DataLoader <MyThemeData>();
                }

                //load data file
                var data = await myThemeDataLoader.LoadLocalData(Constants.THEME_MODULE, Constants.MY_THEME_DATA_FILE);

                if (data == null)
                {
                    data = new MyThemeData();
                }

                if (data.myThemes.Any(x => x.id == themePack.id))
                {
                    return;
                }

                //add new theme
                MyTheme newTheme = new MyTheme();
                newTheme.id            = themePack.id;
                newTheme.name          = themePack.name;
                newTheme.thumbnail     = themePack.thumbnailUrl;
                newTheme.materialCount = materialCount;
                data.myThemes.Insert(0, newTheme);

                //save data
                string json = JsonSerializer.Serialize(data);
                await IsolatedStorageHelper.WriteToFileAsync(Constants.THEME_MODULE, Constants.MY_THEME_DATA_FILE, json);
            }
            catch (Exception ex)
            {
                somethingWrong = true;
            }
        }
Пример #5
0
        public void SetNeededThemePack(int index, ThemePack pack)
        {
            CraftItem craftItem = m_CraftItems.GetAt(index);

            craftItem.RequiredThemePack = pack;
        }
Пример #6
0
        public void Refresh()
        {
            _accentColors        = new ObservableCollection <AccentColorBase>();
            _appThemes           = new ObservableCollection <AppThemeBase>();
            _themePacks          = new ObservableCollection <ThemePack>();
            _audioVisualisations = new ObservableCollection <IAudioVisualisationContainer>();

            foreach (var t in ThemeManager.Accents.Select(a => new AccentColor {
                Name = a.Name
            }).OrderBy(x => x.TranslatedName))
            {
                _accentColors.Add(t);
            }

            foreach (var t in ThemeManager.AppThemes.Select(a => new AppTheme {
                Name = a.Name
            }).OrderBy(x => x.TranslatedName))
            {
                _appThemes.Add(t);
            }

            _audioVisualisations.Add(DefaultAudioVisualisation.GetDefault());

            var accentColorsFolder = new DirectoryInfo(HurricaneSettings.Instance.AccentColorsDirectory);

            if (accentColorsFolder.Exists)
            {
                foreach (var file in accentColorsFolder.GetFiles("*.xaml"))
                {
                    CustomAccentColor theme;

                    if (CustomAccentColor.FromFile(file.FullName, out theme))
                    {
                        _accentColors.Add(theme);
                    }
                }
            }

            var appThemesFolder = new DirectoryInfo(HurricaneSettings.Instance.AppThemesDirectory);

            if (appThemesFolder.Exists)
            {
                foreach (var file in appThemesFolder.GetFiles("*.xaml"))
                {
                    CustomAppTheme theme;
                    if (CustomAppTheme.FromFile(file.FullName, out theme))
                    {
                        _appThemes.Add(theme);
                    }
                }
            }

            var themePacksFolder = new DirectoryInfo(HurricaneSettings.Instance.ThemePacksDirectory);

            if (themePacksFolder.Exists)
            {
                foreach (var file in themePacksFolder.GetFiles("*.htp"))
                {
                    ThemePack pack;
                    if (ThemePack.FromFile(file.FullName, out pack))
                    {
                        _themePacks.Add(pack);
                    }
                }
            }

            var audioVisualisations = new DirectoryInfo(HurricaneSettings.Instance.AudioVisualisationsDirectory);

            if (audioVisualisations.Exists)
            {
                foreach (var file in audioVisualisations.GetFiles("*.dll"))
                {
                    _audioVisualisations.Add(new CustomAudioVisualisation {
                        FileName = file.Name
                    });
                }
            }
        }
Пример #7
0
        private async Task <bool> ActualDownload()
        {
            somethingWrong         = false;
            this.progressBar.Value = 0;

            if (fileDownloader == null)
            {
                fileDownloader = new FileDownloader();
            }

            ThemePack theme = this.rootGrid.GetDataContext <ThemePack>();

            if (theme == null)
            {
                return(false);
            }

            //download
            string fileName    = string.Format(Constants.THEME_PACK_ZIP_FILE_FORMAT, theme.id);
            string zipFilePath = Path.Combine(Constants.THEME_MODULE, fileName);
            var    storageFile = await fileDownloader.Download(theme.zipUrl, zipFilePath, progressBar);

            if (storageFile == null)
            {
                somethingWrong = true;
            }

            if (downloadCanceled || somethingWrong)
            {
                return(false);
            }

            //unzip
            string unZipfolderName = string.Format("{0}\\{1}", Constants.THEME_MODULE, theme.id);

            await UnZip(storageFile, unZipfolderName);

            if (somethingWrong)
            {
                return(false);
            }

            //delete zip
            somethingWrong = await DeleteZipFile(zipFilePath);

            if (somethingWrong)
            {
                return(false);
            }

            //add materials data
            int materialCount = await AddMaterialData_SplitFile(theme, unZipfolderName);

            if (somethingWrong)
            {
                return(false);
            }

            // claim downloaded
            await AddMyThemeData(theme, materialCount);

            if (somethingWrong)
            {
                return(false);
            }
            else
            {
                theme.Downloaded = true;
            }

            return(true);
        }