예제 #1
0
        public virtual bool Save(string fileName, SaveAction saveAction)
        {
            if (!Directory.Exists(this.RootDirectory))
            {
                Directory.CreateDirectory(this.RootDirectory);
            }
            string str = Path.Combine(this.RootDirectory, fileName);

            if (System.IO.File.Exists(str))
            {
                System.IO.File.Copy(str, str + "_Backup", true);
            }
            try
            {
                byte[] buffer = new byte[40960];
                using (MemoryStream memoryStream = new MemoryStream(buffer))
                {
                    using (BinaryWriter writer = new BinaryWriter((Stream)memoryStream))
                    {
                        writer.Write(DateTime.Now.ToFileTime());
                        saveAction(writer);
                        if (memoryStream.Length < 40960L)
                        {
                            long length = 40960L - memoryStream.Length;
                            writer.Write(new byte[length]);
                        }
                        else if (memoryStream.Length > 40960L)
                        {
                            throw new InvalidOperationException("Save file greater than the imposed limit!");
                        }
                    }
                }
                using (FileStream fileStream = new FileStream(str, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    using (BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream))
                        binaryWriter.Write(buffer);
                }
                return(true);
            }
            catch (Exception ex)
            {
                PCSaveDevice.Log("Error while saving : " + (object)ex);
            }
            return(false);
        }
예제 #2
0
        public virtual bool Load(string fileName, LoadAction loadAction)
        {
            if (!Directory.Exists(this.RootDirectory))
            {
                Directory.CreateDirectory(this.RootDirectory);
            }
            bool   flag = false;
            string path = Path.Combine(this.RootDirectory, fileName);

            try
            {
                using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    using (BinaryReader reader = new BinaryReader((Stream)fileStream))
                    {
                        reader.ReadInt64();
                        loadAction(reader);
                        flag = true;
                    }
                }
            }
            catch (Exception ex)
            {
                if (!fileName.EndsWith("_Backup"))
                {
                    if (System.IO.File.Exists(path + "_Backup"))
                    {
                        PCSaveDevice.Log("Loading error, will try with backup : " + (object)ex);
                        return(this.Load(fileName + "_Backup", loadAction));
                    }
                    else
                    {
                        PCSaveDevice.Log("Loading error, no backup found : " + (object)ex);
                    }
                }
                else
                {
                    PCSaveDevice.Log("Error loading backup : " + (object)ex);
                }
            }
            return(flag);
        }
예제 #3
0
 public override void Initialize()
 {
   base.Initialize();
   this.Title = "SaveSlotTitle";
   this.AButtonString = "ChooseWithGlyph";
   this.BButtonString = "ExitWithGlyph";
   this.GameState = ServiceHelper.Get<IGameStateManager>();
   for (int index = 0; index < 3; ++index)
   {
     // ISSUE: object of a compiler-generated type is created
     // ISSUE: variable of a compiler-generated type
     SaveSlotSelectionLevel.\u003C\u003Ec__DisplayClassa cDisplayClassa = new SaveSlotSelectionLevel.\u003C\u003Ec__DisplayClassa();
     // ISSUE: reference to a compiler-generated field
     cDisplayClassa.\u003C\u003E4__this = this;
     // ISSUE: reference to a compiler-generated field
     cDisplayClassa.slot = this.Slots[index] = new SaveSlotInfo()
     {
       Index = index
     };
     PCSaveDevice pcSaveDevice = new PCSaveDevice("FEZ");
     string fileName = "SaveSlot" + (object) index;
     if (!pcSaveDevice.FileExists(fileName))
     {
       // ISSUE: reference to a compiler-generated field
       cDisplayClassa.slot.Empty = true;
     }
     else
     {
       // ISSUE: object of a compiler-generated type is created
       // ISSUE: variable of a compiler-generated type
       SaveSlotSelectionLevel.\u003C\u003Ec__DisplayClassc cDisplayClassc = new SaveSlotSelectionLevel.\u003C\u003Ec__DisplayClassc();
       // ISSUE: reference to a compiler-generated field
       cDisplayClassc.CS\u0024\u003C\u003E8__localsb = cDisplayClassa;
       // ISSUE: reference to a compiler-generated field
       cDisplayClassc.saveData = (SaveData) null;
       // ISSUE: reference to a compiler-generated method
       // ISSUE: reference to a compiler-generated field
       if (!pcSaveDevice.Load(fileName, new LoadAction(cDisplayClassc.\u003CInitialize\u003Eb__4)) || cDisplayClassc.saveData == null)
       {
         // ISSUE: reference to a compiler-generated field
         cDisplayClassa.slot.Empty = true;
       }
       else
       {
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         cDisplayClassa.slot.Percentage = (float) (((double) (cDisplayClassc.saveData.CubeShards + cDisplayClassc.saveData.SecretCubes + cDisplayClassc.saveData.PiecesOfHeart) + (double) cDisplayClassc.saveData.CollectedParts / 8.0) / 32.0);
         // ISSUE: reference to a compiler-generated field
         // ISSUE: reference to a compiler-generated field
         cDisplayClassa.slot.PlayTime = new TimeSpan(cDisplayClassc.saveData.PlayTime);
       }
     }
     if (this.Slots[index].Empty)
     {
       // ISSUE: reference to a compiler-generated method
       this.AddItem((string) null, new Action(cDisplayClassa.\u003CInitialize\u003Eb__5), -1).SuffixText = (Func<string>) (() => StaticText.GetString("NewSlot"));
     }
     else
     {
       // ISSUE: reference to a compiler-generated method
       // ISSUE: reference to a compiler-generated method
       this.AddItem("SaveSlotPrefix", new Action(cDisplayClassa.\u003CInitialize\u003Eb__7), -1).SuffixText = new Func<string>(cDisplayClassa.\u003CInitialize\u003Eb__8);
     }
   }
 }
예제 #4
0
        public PCSaveDevice(string gameName)
        {
            this.RootDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), gameName);
            if (PCSaveDevice.CloudSavesSynced)
            {
                return;
            }
            RemoteStorage remoteStorage = CommunityExpress.Instance.RemoteStorage;

            for (int index = 0; index < 3; ++index)
            {
                string str = "SaveSlot" + (object)index;
                PCSaveDevice.CloudEntry cloudEntry = new PCSaveDevice.CloudEntry()
                {
                    Exists = remoteStorage.FileExists(str)
                };
                try
                {
                    if (cloudEntry.Exists)
                    {
                        CommunityExpressNS.File file = remoteStorage.GetFile(str);
                        cloudEntry.Data = file.ReadBytes();
                        using (MemoryStream memoryStream = new MemoryStream(cloudEntry.Data))
                        {
                            using (BinaryReader binaryReader = new BinaryReader((Stream)memoryStream))
                                cloudEntry.LastModifiedTimestamp = new long?(binaryReader.ReadInt64());
                        }
                    }
                }
                catch (Exception ex)
                {
                    PCSaveDevice.Log(string.Concat(new object[4]
                    {
                        (object)"Error getting cloud save #",
                        (object)index,
                        (object)" : ",
                        (object)ex
                    }));
                    cloudEntry.Corrupted = true;
                }
                try
                {
                    if (remoteStorage.FileExists(str + "_LastDelete"))
                    {
                        using (MemoryStream memoryStream = new MemoryStream(remoteStorage.GetFile(str + "_LastDelete").ReadBytes()))
                        {
                            using (BinaryReader binaryReader = new BinaryReader((Stream)memoryStream))
                                cloudEntry.LastDeletedTimestamp = new long?(binaryReader.ReadInt64());
                        }
                    }
                }
                catch (Exception ex)
                {
                    PCSaveDevice.Log(string.Concat(new object[4]
                    {
                        (object)"Error getting last delete time for cloud save #",
                        (object)index,
                        (object)" : ",
                        (object)ex
                    }));
                }
                string path = Path.Combine(this.RootDirectory, str);
                if (!System.IO.File.Exists(path))
                {
                    if (cloudEntry.Exists && !cloudEntry.Corrupted && (!cloudEntry.LastDeletedTimestamp.HasValue || cloudEntry.LastDeletedTimestamp.Value < cloudEntry.LastModifiedTimestamp.Value))
                    {
                        PCSaveDevice.Log("Copying back cloud save #" + (object)index + " to local because it did not exist locally");
                        try
                        {
                            using (FileStream fileStream = new FileStream(path, FileMode.Create))
                            {
                                using (BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream))
                                    binaryWriter.Write(cloudEntry.Data);
                            }
                        }
                        catch (Exception ex)
                        {
                            PCSaveDevice.Log(string.Concat(new object[4]
                            {
                                (object)"Error copying cloud entry data to local for cloud save #",
                                (object)index,
                                (object)" : ",
                                (object)ex
                            }));
                        }
                    }
                }
                else
                {
                    long num = long.MinValue;
                    try
                    {
                        using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        {
                            using (BinaryReader binaryReader = new BinaryReader((Stream)fileStream))
                                num = binaryReader.ReadInt64();
                        }
                    }
                    catch (Exception ex)
                    {
                        PCSaveDevice.Log("Error while loading local file for timestamp compare : " + (object)ex);
                    }
                    if (cloudEntry.LastDeletedTimestamp.HasValue && cloudEntry.LastDeletedTimestamp.Value > num)
                    {
                        PCSaveDevice.Log("Deleting local save #" + (object)index + " because of pending cloud deletion");
                        System.IO.File.Delete(path);
                        num = long.MinValue;
                    }
                    if (cloudEntry.Exists && !cloudEntry.Corrupted && (!cloudEntry.LastDeletedTimestamp.HasValue || cloudEntry.LastDeletedTimestamp.Value < cloudEntry.LastModifiedTimestamp.Value) && cloudEntry.LastModifiedTimestamp.Value > num)
                    {
                        PCSaveDevice.Log("Copying back cloud save #" + (object)index + " to local because the local copy is older");
                        try
                        {
                            using (FileStream fileStream = new FileStream(path, FileMode.Create))
                            {
                                using (BinaryWriter binaryWriter = new BinaryWriter((Stream)fileStream))
                                    binaryWriter.Write(cloudEntry.Data);
                            }
                        }
                        catch (Exception ex)
                        {
                            PCSaveDevice.Log(string.Concat(new object[4]
                            {
                                (object)"Error copying cloud entry data to local for cloud save #",
                                (object)index,
                                (object)" : ",
                                (object)ex
                            }));
                        }
                    }
                }
                PCSaveDevice.CloudSavesSynced = true;
            }
        }
예제 #5
0
 private void ReloadSlots()
 {
   for (int index = 0; index < 3; ++index)
   {
     SaveSlotInfo saveSlotInfo = this.Slots[index] = new SaveSlotInfo()
     {
       Index = index
     };
     PCSaveDevice pcSaveDevice = new PCSaveDevice("FEZ");
     string fileName = "SaveSlot" + (object) index;
     if (!pcSaveDevice.FileExists(fileName))
     {
       saveSlotInfo.Empty = true;
     }
     else
     {
       SaveData saveData = (SaveData) null;
       if (!pcSaveDevice.Load(fileName, (LoadAction) (stream => saveData = SaveFileOperations.Read(new CrcReader(stream)))) || saveData == null)
       {
         saveSlotInfo.Empty = true;
       }
       else
       {
         saveSlotInfo.Percentage = (float) (((double) (saveData.CubeShards + saveData.SecretCubes + saveData.PiecesOfHeart) + (double) saveData.CollectedParts / 8.0) / 32.0);
         saveSlotInfo.PlayTime = new TimeSpan(saveData.PlayTime);
         saveSlotInfo.SaveData = saveData;
       }
     }
   }
 }