Пример #1
0
        public Result Get(out SaveDataIndexerValue value, ref SaveDataAttribute key)
        {
            value = default;

            lock (Locker)
            {
                Result rc = Initialize();
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = EnsureKvDatabaseLoaded(false);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = KvDatabase.Get(ref key, SpanHelpers.AsByteSpan(ref value));

                if (rc.IsFailure())
                {
                    return(ResultFs.TargetNotFound.LogConverted(rc));
                }

                return(Result.Success);
            }
        }
Пример #2
0
        public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
        {
            saveDataId = default;

            lock (Locker)
            {
                Result rc = Initialize();
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = EnsureKvDatabaseLoaded(false);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                SaveDataIndexerValue value = default;

                rc = KvDatabase.Get(ref key, SpanHelpers.AsByteSpan(ref value));

                if (rc.IsSuccess())
                {
                    return(ResultFs.SaveDataPathAlreadyExists.Log());
                }

                LastPublishedId++;
                ulong newSaveDataId = LastPublishedId;

                value = new SaveDataIndexerValue {
                    SaveDataId = newSaveDataId
                };

                rc = KvDatabase.Set(ref key, SpanHelpers.AsByteSpan(ref value));

                if (rc.IsFailure())
                {
                    LastPublishedId--;
                    return(rc);
                }

                rc = AdjustOpenedInfoReaders(ref key);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                saveDataId = newSaveDataId;
                return(Result.Success);
            }
        }
Пример #3
0
        public Result Get(out SaveDataIndexerValue value, ref SaveDataAttribute key)
        {
            lock (Locker)
            {
                if (IsKeyValueSet && _key.Equals(key))
                {
                    value = _value;
                    return(Result.Success);
                }

                value = default;
                return(ResultFs.TargetNotFound.Log());
            }
        }
Пример #4
0
        public Result GetBySaveDataId(out SaveDataIndexerValue value, ulong saveDataId)
        {
            lock (Locker)
            {
                if (IsKeyValueSet && _value.SaveDataId == saveDataId)
                {
                    value = _value;
                    return(Result.Success);
                }

                value = default;
                return(ResultFs.TargetNotFound.Log());
            }
        }
Пример #5
0
        public Result AddSystemSaveData(ref SaveDataAttribute key)
        {
            lock (Locker)
            {
                if (IsKeyValueSet && _key.Equals(key))
                {
                    return(ResultFs.SaveDataPathAlreadyExists.Log());
                }

                _key          = key;
                IsKeyValueSet = true;

                _value = new SaveDataIndexerValue();

                return(Result.Success);
            }
        }
Пример #6
0
        public Result AddSystemSaveData(ref SaveDataAttribute key)
        {
            lock (Locker)
            {
                Result rc = Initialize();
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = EnsureKvDatabaseLoaded(false);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                foreach (KeyValuePair <SaveDataAttribute, byte[]> kvp in KvDatabase)
                {
                    ref SaveDataIndexerValue value = ref Unsafe.As <byte, SaveDataIndexerValue>(ref kvp.Value[0]);

                    if (key.SaveDataId == value.SaveDataId)
                    {
                        return(ResultFs.SaveDataPathAlreadyExists.Log());
                    }
                }

                var newValue = new SaveDataIndexerValue
                {
                    SaveDataId = key.SaveDataId
                };

                rc = KvDatabase.Set(ref key, SpanHelpers.AsByteSpan(ref newValue));
                if (rc.IsFailure())
                {
                    return(rc);
                }

                rc = AdjustOpenedInfoReaders(ref key);
                if (rc.IsFailure())
                {
                    return(rc);
                }

                return(rc);
            }
Пример #7
0
        public Result Add(out ulong saveDataId, ref SaveDataAttribute key)
        {
            lock (Locker)
            {
                if (IsKeyValueSet && _key.Equals(key))
                {
                    saveDataId = default;
                    return(ResultFs.SaveDataPathAlreadyExists.Log());
                }

                _key          = key;
                IsKeyValueSet = true;

                _value = new SaveDataIndexerValue {
                    SaveDataId = CurrentSaveDataId
                };
                saveDataId = CurrentSaveDataId;
                CurrentSaveDataId++;

                return(Result.Success);
            }
        }
Пример #8
0
 public static void GetSaveDataInfo(out SaveDataInfo info, ref SaveDataAttribute key, ref SaveDataIndexerValue value)
 {
     info = new SaveDataInfo
     {
         SaveDataId        = value.SaveDataId,
         SpaceId           = value.SpaceId,
         Type              = key.Type,
         UserId            = key.UserId,
         SaveDataIdFromKey = key.SaveDataId,
         TitleId           = key.TitleId,
         Size              = value.Size,
         Index             = key.Index,
         Rank              = key.Rank,
         State             = value.State
     };
 }
Пример #9
0
 public SaveDataIndexerLiteInfoReader(ref SaveDataAttribute key, ref SaveDataIndexerValue value)
 {
     SaveDataIndexer.GetSaveDataInfo(out _info, ref key, ref value);
 }