Exemple #1
0
        public void SaveFileToDb(SavegameQueueItem itm, MainForm main)
        {
            _main = main;
            using (var db = new LiteDatabase(NMSGMSettings.DbFilePath))
            {
                var saveIndex = db.GetCollection <SavegameDatabaseEntry>("SavegameIndexV1");


                var guid       = Guid.NewGuid();
                var mfBlobInfo = db.FileStorage.Upload(Guid.NewGuid().ToString(), itm.SaveMetafilePath);
                var stBlobInfo = db.FileStorage.Upload(Guid.NewGuid().ToString(), itm.SaveStoragePath);

                var entry = new SavegameDatabaseEntry()
                {
                    mfBlobId          = mfBlobInfo.Id,
                    stBlobId          = stBlobInfo.Id,
                    commitedTimeStamp = DateTime.Now,
                    onHold            = false,
                    decryptionSeed    = itm.decryptionSeed,
                    Type = itm.Type,
                };

                if (itm.Comment != null)
                {
                    entry.comment = itm.Comment;
                }

                saveIndex.Insert(entry);

                _main.Invoke(new Action(() => _main.UpdateLastProtected()));
            }

            _main.Invoke(new Action(() => _main.UpdateDbSize()));
        }
        private void FsWatch_Changed(object sender, FileSystemEventArgs e)
        {
            if (isValidSavegameName(e.Name))
            {
                if (storeQ.Count(p => p.SaveStoragePath == e.FullPath) == 0)
                {
                    var queueItem = new SavegameQueueItem()
                    {
                        DetectionTimestamp = DateTime.Now,
                        WriteRetries       = 0,
                        SaveStoragePath    = e.FullPath,
                        SaveMetafilePath   = Path.Combine(Path.GetDirectoryName(e.FullPath), "mf_" + e.Name),
                        decryptionSeed     = savegameProfile.EncryptionSeed,
                        Type = savegameProfile.SaveProfileType,
                    };

                    storeQ.Enqueue(queueItem);
                }
            }
        }
        public SavegameQueueItem GetMostRecentSaveObject(uint profileId)
        {
            var recentStorageFile = savegameProfile.ProfileDirectory.GetFiles(SavegameHelper.GetStorageFilenameFromProfileId(profileId), SearchOption.TopDirectoryOnly).OrderByDescending(p => p.LastWriteTime).FirstOrDefault();

            if (recentStorageFile != null)
            {
                var queueItem = new SavegameQueueItem()
                {
                    DetectionTimestamp = DateTime.Now,
                    WriteRetries       = 0,
                    SaveStoragePath    = recentStorageFile.FullName,
                    SaveMetafilePath   = Path.Combine(Path.GetDirectoryName(recentStorageFile.FullName), "mf_" + recentStorageFile.Name),
                    decryptionSeed     = savegameProfile.EncryptionSeed,
                    Type    = savegameProfile.SaveProfileType,
                    Comment = "[NMSGM] Automatic backup of savegame slot overwritten during restore."
                };
                return(queueItem);
            }
            else
            {
                return(null);
            }
        }