Ejemplo n.º 1
0
        public static ReferenceCountedDisposable <ISaveDataExtraDataAccessor> CreateShared(
            ref ReferenceCountedDisposable <ISaveDataExtraDataAccessor> accessor)
        {
            var resultConvertAccessor = new SaveDataExtraDataResultConvertAccessor(ref accessor);

            return(new ReferenceCountedDisposable <ISaveDataExtraDataAccessor>(resultConvertAccessor));
        }
        public Result GetCache(out ReferenceCountedDisposable <ISaveDataExtraDataAccessor> accessor,
                               SaveDataSpaceId spaceId, ulong saveDataId)
        {
            UnsafeHelpers.SkipParamInit(out accessor);

            using ScopedLock <SdkRecursiveMutexType> scopedLock = ScopedLock.Lock(ref _mutex);

            LinkedListNode <Cache> currentNode = _accessorList.First;

            while (true)
            {
                if (currentNode is null)
                {
                    return(ResultFs.TargetNotFound.Log());
                }

                if (currentNode.ValueRef.Contains(spaceId, saveDataId))
                {
                    break;
                }

                currentNode = currentNode.Next;
            }

            ReferenceCountedDisposable <ISaveDataExtraDataAccessor> tempAccessor = null;

            try
            {
                tempAccessor = currentNode.ValueRef.Lock();

                // Return early if the accessor was already disposed
                if (tempAccessor is null)
                {
                    // Note: Nintendo doesn't remove the accessor from the list in this case
                    _accessorList.Remove(currentNode);
                    return(ResultFs.TargetNotFound.Log());
                }

                accessor = SaveDataExtraDataResultConvertAccessor.CreateShared(ref tempAccessor);
                return(Result.Success);
            }
            finally
            {
                tempAccessor?.Dispose();
            }
        }