예제 #1
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;
   }
 }
예제 #2
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;
            }
        }