/// <summary>
 /// Constructs a new savegame metadata container for a Cartridge, using metadata
 /// from a GWS metadata container.
 /// </summary>
 /// <param name="tag">Cartridge to save.</param>
 /// <param name="gwsMetadata">Metadata of a GWS file.</param>
 public CartridgeSavegame(CartridgeTag tag, WF.Player.Core.Formats.GWS.Metadata gwsMetadata, string gwsFilename)
 {
     Timestamp = gwsMetadata.SaveCreateDate;
     Name      = gwsMetadata.SaveName;
     HashColor = GetHashColor(Name);
     SetFileProperties(tag, gwsFilename);
 }
Beispiel #2
0
        private bool AcceptSavegame(string filename)
        {
            // Copies this savegame to the content folders of each cartridge
            // whose name matches the cartridge name in the savegame metadata.

            System.Diagnostics.Debug.WriteLine("CartridgeStore: Trying to accept savegame " + filename);

            // Refreshes the progress.
            string businessTag = "accept:" + filename;

            _isBusyAggregator[businessTag] = true;

            // Gets the cartridge this savegame is associated with.
            bool isAborted = false;

            WF.Player.Core.Formats.GWS.Metadata saveMetadata = null;
            try
            {
                using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isf.FileExists(filename))
                    {
                        System.Diagnostics.Debug.WriteLine("CartridgeStore: WARNING: Savegame file not found: " + filename);

                        isAborted = true;
                    }

                    if (!isAborted)
                    {
                        using (IsolatedStorageFileStream fs = isf.OpenFile(filename, System.IO.FileMode.Open))
                        {
                            saveMetadata = WF.Player.Core.Formats.GWS.LoadMetadata(fs);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Logs this.
                DebugUtils.DumpException(ex, "loading savegame metadata", true);

                // Abort!
                isAborted = true;
            }

            bool foundMatch = false;

            if (!isAborted)
            {
                // For each matching tag, creates an associated savegame and copies the file to each
                // tag's content folder.
                List <CartridgeTag> matches;
                lock (_syncRoot)
                {
                    matches = Items.Where(ct => ct.Title == saveMetadata.CartridgeName).ToList();
                }
                if (matches.Count > 0)
                {
                    using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        foreach (CartridgeTag tag in matches)
                        {
                            // Creates a savegame.
                            CartridgeSavegame save = new CartridgeSavegame(tag, saveMetadata, System.IO.Path.GetFileName(filename));

                            // Copies the new file to the right isolated storage.
                            if (filename != save.SavegameFile)
                            {
                                isf.CopyFile(filename, save.SavegameFile, true);
                            }

                            // Adds the savegame to its tag.
                            tag.AddSavegame(save);

                            foundMatch = true;
                        }
                    }
                }
            }

            // Refreshes the progress.
            _isBusyAggregator[businessTag] = false;

            return(!isAborted && foundMatch);
        }