Exemplo n.º 1
0
        public async Task LoadImage()
        {
            if (ImageFileName.Contains("ms-appx:Assets"))
            {
                BitmapImage bitmapImage = new BitmapImage(new Uri(ImageFileName, UriKind.RelativeOrAbsolute));
                ImageBrush  brush       = new ImageBrush();
                brush.AlignmentX      = AlignmentX.Left;
                brush.AlignmentY      = AlignmentY.Top;
                brush.Stretch         = Stretch.UniformToFill;
                _picBrush.ImageSource = bitmapImage;
                return;
            }

            var folder = await StaticHelpers.GetSaveFolder();

            var file = await folder.GetFileAsync(ImageFileName);

            using (Windows.Storage.Streams.IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                // Set the image source to the selected bitmap.
                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                    new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                bitmapImage.SetSource(fileStream);
                _picBrush.ImageSource = bitmapImage;
            }
        }
Exemplo n.º 2
0
        public async Task Init(string fileName)
        {
            _saveFileName = fileName + MainPage.SAVED_GAME_EXTENSION;
            _folder       = await StaticHelpers.GetSaveFolder();

            _file = await _folder.CreateFileAsync(_saveFileName, CreationCollisionOption.OpenIfExists);

            _randomAccessStream = await _file.OpenAsync(FileAccessMode.ReadWrite);
        }
Exemplo n.º 3
0
        /// <summary>
        ///  I have the Regular and Expansion games embedded as resource files.  this will update them everytime the app starts.
        /// </summary>
        /// <returns></returns>
        public async Task SaveDefaultGamesLocally()
        {
            string   game     = "";
            Assembly assembly = Assembly.Load(new AssemblyName("Catan Game Board"));
            var      folder   = await StaticHelpers.GetSaveFolder();

            var option = CreationCollisionOption.ReplaceExisting;

            char[] sep = new char[] { '.' };

            var    resourceNames = assembly.GetManifestResourceNames();
            string dt            = await ReadTextFromResource(assembly, "BuildDate.dat");

            DateTime buildTime = DateTime.Parse(dt);

            foreach (var name in assembly.GetManifestResourceNames())
            {
                using (var stream = assembly.GetManifestResourceStream(name))
                {
                    string[] tokens = name.Split(sep);
                    int      count  = tokens.Count();
                    string   fn     = tokens[count - 2] + "." + tokens[count - 1];
                    if (tokens[count - 1] != "catangame")
                    {
                        continue;
                    }

                    //
                    //  Check to see if it is there.  if it is, don't mess with it.  Who knows what happened?
                    IStorageItem isiLocal = await folder.TryGetItemAsync(fn);

                    if (isiLocal != null)
                    {
                        if (isiLocal.DateCreated > buildTime)
                        {
                            continue;
                        }
                    }
                    //
                    //  not there -- copy it from the resources
                    using (var reader = new StreamReader(stream))
                    {
                        game = await reader.ReadToEndAsync();

                        var file = await folder.CreateFileAsync(fn, option);

                        await FileIO.WriteTextAsync(file, game);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public async Task <StorageFile> Save()
        {
            try
            {
                string saveString = _currentGame.Serialize();
                if (saveString == "")
                {
                    return(null);
                }

                string fileName = GameName + ".catangame";


                var folder = await StaticHelpers.GetSaveFolder();

                IStorageItem isiLocal = await folder.TryGetItemAsync(fileName);

                if (isiLocal != null)
                {
                    var ret = await StaticHelpers.AskUserYesNoQuestion($"Overwrite {fileName}?", "yes", "no");

                    if (!ret)
                    {
                        return(null);
                    }
                }

                var option = CreationCollisionOption.ReplaceExisting;
                var file   = await folder.CreateFileAsync(fileName, option);

                await FileIO.WriteTextAsync(file, saveString);

                if (CurrentGameName != GameName)
                {
                    _savedGameNames.Add(GameName);
                    _savedStoragefiles.Add(GameName, file);
                    CurrentGameName = GameName;
                }

                return(file);
            }
            catch (Exception exception)
            {
                string        s   = StaticHelpers.GetErrorMessage($"Error saving to file {GameName}", exception);
                MessageDialog dlg = new MessageDialog(s);
                await dlg.ShowAsync();
            }
            return(null);
        }
Exemplo n.º 5
0
        public async Task LoadSettings(string filename)
        {
            try
            {
                StorageFolder folder = await StaticHelpers.GetSaveFolder();

                StorageFile file = await folder.GetFileAsync(filename);

                string contents = await FileIO.ReadTextAsync(file);

                Deserialize(contents);
            }
            catch
            {
            }
        }
Exemplo n.º 6
0
        public async Task LoadGames()
        {
            QueryOptions queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { MainPage.SAVED_GAME_EXTENSION })
            {
                FolderDepth = FolderDepth.Shallow
            };

            Windows.Storage.StorageFolder folder = await StaticHelpers.GetSaveFolder();

            StorageFileQueryResult query = folder.CreateFileQueryWithOptions(queryOptions);

            System.Collections.Generic.IReadOnlyList <Windows.Storage.StorageFile> files = await query.GetFilesAsync();

            foreach (Windows.Storage.StorageFile file in files)
            {
                SavedGames.Add(file.Name);
            }
        }
Exemplo n.º 7
0
        public async Task <IReadOnlyList <StorageFile> > GetSavedFilesInternal()
        {
            var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { ".catangame" });

            queryOptions.FolderDepth = FolderDepth.Shallow;
            var folder = await StaticHelpers.GetSaveFolder();

            var query = folder.CreateFileQueryWithOptions(queryOptions);
            var files = await query.GetFilesAsync();

            _savedGameNames.Clear();
            _savedStoragefiles.Clear();
            foreach (var f in files)
            {
                _savedGameNames.Add(f.DisplayName);
                _savedStoragefiles.Add(f.DisplayName, f);
            }

            return(files);
        }
Exemplo n.º 8
0
        public async Task SaveSettings(string filename)
        {
            try
            {
                string saveString = Serialize();
                if (saveString == "")
                {
                    return;
                }

                StorageFolder folder = await StaticHelpers.GetSaveFolder();

                CreationCollisionOption option = CreationCollisionOption.ReplaceExisting;
                StorageFile             file   = await folder.CreateFileAsync(filename, option);

                await FileIO.WriteTextAsync(file, saveString);
            }
            catch (Exception exception)
            {
                string s = StaticHelpers.GetErrorMessage($"Error saving to file {filename}", exception);
                await StaticHelpers.ShowErrorText(s);
            }
        }
Exemplo n.º 9
0
        private async System.Threading.Tasks.Task LoadNewImage(PlayerModel player)
        {
            _gvPlayers.IsEnabled    = false;
            _gvPlayers.SelectedItem = player;
            try
            {
                Windows.Storage.StorageFolder folder = await StaticHelpers.GetSaveFolder();

                FileOpenPicker picker = new FileOpenPicker()
                {
                    ViewMode = PickerViewMode.List,
                    SuggestedStartLocation = PickerLocationId.PicturesLibrary
                };
                picker.FileTypeFilter.Add(".jpg");
                picker.FileTypeFilter.Add(".jpeg");
                picker.FileTypeFilter.Add(".png");
                picker.FileTypeFilter.Add(".gif");

                Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

                if (file != null)
                {
                    if (player != null)
                    {
                        Windows.Storage.StorageFile fileCopy = await player.CopyImage(file);

                        player.ImageFileName = fileCopy.Name;
                        await player.LoadImage();
                    }
                }
            }
            finally
            {
                _gvPlayers.IsEnabled = true;
            }
        }
Exemplo n.º 10
0
 public Log(StorageFile file)
 {
     _file         = file;
     _saveFileName = _file.DisplayName;
     _folder       = StaticHelpers.GetSaveFolder().Result;
 }