Beispiel #1
0
        public ResultCode Get <T>(DatabaseSessionMetadata metadata, SourceFlag flag, out int count, Span <T> elements) where T : struct, IElement
        {
            count = 0;

            if (!flag.HasFlag(SourceFlag.Database))
            {
                return(GetDefault(flag, ref count, elements));
            }

            int databaseCount = _miiDatabase.GetCount(metadata);

            for (int i = 0; i < databaseCount; i++)
            {
                if (count >= elements.Length)
                {
                    return(ResultCode.BufferTooSmall);
                }

                _miiDatabase.Get(metadata, i, out StoreData storeData);

                elements[count] = default;
                elements[count].SetFromStoreData(storeData);
                elements[count].SetSource(Source.Database);

                count++;
            }

            return(GetDefault(flag, ref count, elements));
        }
Beispiel #2
0
        public ResultCode UpdateLatest <T>(DatabaseSessionMetadata metadata, IStoredData <T> oldMiiData, SourceFlag flag, IStoredData <T> newMiiData) where T : unmanaged
        {
            if (!flag.HasFlag(SourceFlag.Database))
            {
                return(ResultCode.NotFound);
            }

            if (metadata.IsInterfaceVersionSupported(1) && !oldMiiData.IsValid())
            {
                return(oldMiiData.InvalidData);
            }

            ResultCode result = _miiDatabase.FindIndex(metadata, out int index, oldMiiData.CreateId);

            if (result == ResultCode.Success)
            {
                _miiDatabase.Get(metadata, index, out StoreData storeData);

                if (storeData.Type != oldMiiData.Type)
                {
                    return(ResultCode.NotFound);
                }

                newMiiData.SetFromStoreData(storeData);

                if (oldMiiData == newMiiData)
                {
                    return(ResultCode.NotUpdated);
                }
            }

            return(result);
        }
Beispiel #3
0
        private void MarkDirty(DatabaseSessionMetadata metadata)
        {
            _isDirty = true;

            UpdateCounter++;

            metadata.UpdateCounter = UpdateCounter;
        }
Beispiel #4
0
        public bool IsUpdated(DatabaseSessionMetadata metadata)
        {
            bool result = metadata.UpdateCounter != UpdateCounter;

            metadata.UpdateCounter = UpdateCounter;

            return(result);
        }
Beispiel #5
0
        public bool IsUpdated(DatabaseSessionMetadata metadata, SourceFlag flag)
        {
            if (flag.HasFlag(SourceFlag.Database))
            {
                return(_miiDatabase.IsUpdated(metadata));
            }

            return(false);
        }
Beispiel #6
0
        public ResultCode AddOrReplace(DatabaseSessionMetadata metadata, StoreData storeData)
        {
            ResultCode result = _miiDatabase.AddOrReplace(metadata, storeData);

            if (result == ResultCode.Success)
            {
                result = _miiDatabase.SaveDatabase();
            }

            return(result);
        }
Beispiel #7
0
        public ResultCode Delete(DatabaseSessionMetadata metadata, CreateId createId)
        {
            ResultCode result = _miiDatabase.Delete(metadata, createId);

            if (result == ResultCode.Success)
            {
                result = _miiDatabase.SaveDatabase();
            }

            return(result);
        }
Beispiel #8
0
        public ResultCode Move(DatabaseSessionMetadata metadata, int index, CreateId createId)
        {
            ResultCode result = _miiDatabase.Move(metadata, index, createId);

            if (result == ResultCode.Success)
            {
                result = _miiDatabase.SaveDatabase();
            }

            return(result);
        }
Beispiel #9
0
 public void Get(DatabaseSessionMetadata metadata, int index, out StoreData storeData)
 {
     if (!metadata.MiiKeyCode.IsEnabledSpecialMii())
     {
         if (GetAtVirtualIndex(index, out int realIndex, out _))
         {
             index = realIndex;
         }
         else
         {
             index = 0;
         }
     }
Beispiel #10
0
        public ResultCode GetIndex(DatabaseSessionMetadata metadata, CharInfo charInfo, out int index)
        {
            if (!charInfo.IsValid())
            {
                index = -1;

                return(ResultCode.InvalidCharInfo);
            }

            if (_miiDatabase.FindIndex(out index, charInfo.CreateId, metadata.MiiKeyCode.IsEnabledSpecialMii()) != ResultCode.Success)
            {
                return(ResultCode.NotFound);
            }

            return(ResultCode.Success);
        }
Beispiel #11
0
        public uint GetCount(DatabaseSessionMetadata metadata, SourceFlag flag)
        {
            int count = 0;

            if (flag.HasFlag(SourceFlag.Default))
            {
                count += DefaultMii.TableLength;
            }

            if (flag.HasFlag(SourceFlag.Database))
            {
                count += _miiDatabase.GetCount(metadata);
            }

            return((uint)count);
        }
Beispiel #12
0
        public int GetCount(DatabaseSessionMetadata metadata)
        {
            if (!metadata.MiiKeyCode.IsEnabledSpecialMii())
            {
                int count = 0;

                for (int i = 0; i < _database.Length; i++)
                {
                    StoreData tmp = _database.Get(i);

                    if (!tmp.IsSpecial())
                    {
                        count++;
                    }
                }

                return(count);
            }
            else
            {
                return(_database.Length);
            }
        }
Beispiel #13
0
 public void SetInterfaceVersion(DatabaseSessionMetadata metadata, uint interfaceVersion)
 {
     metadata.InterfaceVersion = interfaceVersion;
 }
Beispiel #14
0
        public ResultCode DestroyFile(DatabaseSessionMetadata metadata)
        {
            _isBroken = true;

            return(_miiDatabase.DestroyFile(metadata));
        }
Beispiel #15
0
 public void Format(DatabaseSessionMetadata metadata)
 {
     _miiDatabase.FormatDatabase(metadata);
     _miiDatabase.SaveDatabase();
 }
Beispiel #16
0
 public void SetInterfaceVersion(DatabaseSessionMetadata metadata, uint interfaceVersion)
 {
     _miiDatabase.SetInterfaceVersion(metadata, interfaceVersion);
 }