コード例 #1
0
        public FileOverviewViewModel(FileOverview fileOverview, IServiceProvider serviceProvider)
        {
            serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            _fileOverview   = fileOverview ?? throw new ArgumentNullException(nameof(fileOverview));

            _brushesProvider = serviceProvider.GetRequiredService <IBrushesProvider>();
            VerifyNcasHeaderSignatureCommand = serviceProvider.GetRequiredService <IVerifyNcasHeaderSignatureCommand>();
            VerifyNcasHashCommand            = serviceProvider.GetRequiredService <IVerifyNcasHashCommand>();
            CopyMissingKeysCommand           = new RelayCommand(CopyMissingKeys);

            _fileOverview.PropertyChanged += OnFileOverviewPropertyChanged;
            _fileOverview.MissingKeys.CollectionChanged += (_, _) =>
            {
                UpdateMissingKeys();
            };

            foreach (var cnmtContainerViewModel in _fileOverview.CnmtContainers.Select((contentOverview, i) => new CnmtContainerViewModel(contentOverview, i + 1, serviceProvider)))
            {
                CnmtContainers.Add(cnmtContainerViewModel);
            }

            SelectedCnmtContainer = CnmtContainers.FirstOrDefault();

            UpdateMissingKeys();
            UpdateNcasHashExceptions();
            UpdateNcasHeadersSignatureExceptions();
        }
コード例 #2
0
 public NxFile(string path, IItem rootItem, FileOverview overview)
 {
     Path     = path;
     RootItem = rootItem;
     Overview = overview;
     FileName = System.IO.Path.GetFileName(path);
 }
コード例 #3
0
            private static PackageType DeterminePackageType(FileOverview fileOverview, CnmtContainer[] cnmtContainers)
            {
                PackageType packageType;

                if (cnmtContainers.Length > 1)
                {
                    var rootItemType = fileOverview.RootItem.GetType();
                    if (rootItemType == typeof(XciItem))
                    {
                        packageType = PackageType.SuperXCI;
                    }
                    else if (rootItemType == typeof(NspItem))
                    {
                        packageType = PackageType.SuperNSP;
                    }
                    else
                    {
                        packageType = PackageType.Unknown;
                    }
                }
                else
                {
                    packageType = PackageType.Normal;
                }

                return(packageType);
            }
コード例 #4
0
 void CreateFavoritesOverviews(FavoritesPageResJson filePageResJson)
 {
     foreach (FileJson fileJson in filePageResJson.files)
     {
         GameObject   fileOverviewPanel = Instantiate(fileOverviewPanelPrefab, FavoritesScrollViewContent.transform);
         FileOverview fileOverview      = fileOverviewPanel.GetComponent <FileOverview>();
         fileOverview.Init(fileJson);
     }
 }
コード例 #5
0
            private FileOverview FillOverview(FileOverview fileOverview, PartitionFileSystemItemBase partitionItem)
            {
                var cnmtContainers = BuildCnmtContainers(partitionItem).ToArray();

                var packageType = DeterminePackageType(fileOverview, cnmtContainers);

                fileOverview.PackageType = packageType;
                fileOverview.CnmtContainers.AddRange(cnmtContainers);

                return(fileOverview);
            }
コード例 #6
0
 void CreateFileOverviews(FilePageResJson filePageResJson)
 {
     foreach (FileJson fileJson in filePageResJson.file_list)
     {
         if (email != null && !email.Equals(WebReq.email) && fileJson.anonymous)
         {
             continue;
         }
         GameObject   fileOverviewPanel = Instantiate(fileOverviewPanelPrefab, filePanel.transform);
         FileOverview fileOverview      = fileOverviewPanel.GetComponent <FileOverview>();
         fileOverview.Init(fileJson);
     }
 }
コード例 #7
0
    public void init(FileOverview fileOverview)
    {
        fileCoverImage.sprite = fileOverview.fileCoverImage.sprite;
        authorName.text       = fileOverview.authorName.text;
        description.text      = fileOverview.description.text;
        downloads.text        = fileOverview.downloads.text;
        likes.text            = fileOverview.likes.text;
        date.text             = fileOverview.date.text;
        DownloadKey           = fileOverview.key;
        rateText.text         = fileOverview.rateText.text;
        rateImage.fillAmount  = fileOverview.rateImage.fillAmount;
        fileName.text         = fileOverview.fileName.text;

        WorkShopEvents.loginEvent.AddListener(RequestComments);
        WorkShopEvents.logoutEvent.AddListener(RequestComments);
        string        filePath = Application.dataPath + "/StreamingAssets/DownloadedGameFiles";
        DirectoryInfo d        = new DirectoryInfo(filePath);

        if (WebReq.email != null && DownloadKey.Contains(WebReq.email))
        {
            // NOTHING
        }
        else
        {
            foreach (var currDirectory in d.GetDirectories())
            {
                Debug.Log(currDirectory.Name);
                string filename = Regex.Replace(DownloadKey, @"[^0-9a-zA-Z]+", "");
                if (currDirectory.Name.Equals(filename))
                {
                    // Then there's a match
                    denominator.gameObject.SetActive(true);
                    personalRatingText.gameObject.SetActive(true);
                    visibleUserRating.gameObject.SetActive(true);
                    rateOneButton.SetActive(true);
                    rateTwoButton.SetActive(true);
                    rateThreeButton.SetActive(true);
                    rateFourButton.SetActive(true);
                    rateFiveButton.SetActive(true);

                    break;
                }

                // Hello Moto
            }
        }


        RequestComments();
        //likeToggle.isOn = false;
    }
コード例 #8
0
            public FileOverview CreateXciOverview(XciItem xciItem)
            {
                // NOTE: the secure partition of an XCI is equivalent to an NSP
                var securePartitionItem = xciItem.ChildItems.FirstOrDefault(partition => partition.XciPartitionType == XciPartitionType.Secure);

                var fileOverview = new FileOverview(xciItem);

                if (securePartitionItem == null)
                {
                    var message = LocalizationManager.Instance.Current.Keys.LoadingError_XciSecurePartitionNotFound;
                    xciItem.Errors.Add(message);
                    _logger.LogError(message);
                    return(fileOverview);
                }

                return(FillOverview(fileOverview, securePartitionItem));
            }
コード例 #9
0
        public IEnumerator AnonmyousAuthorPasses()
        {
            // Use the Assert class to test conditions.
            // Use yield to skip a frame.

            loginAndSignUp.loginEmailInput.text    = "*****@*****.**";
            loginAndSignUp.loginPasswordInput.text = "12";
            loginAndSignUp.RequestLogin();

            yield return(new WaitForSeconds(5f));

            adminFilePage.Init(WebReq.email);
            yield return(new WaitForSeconds(5f));

            FileOverview fileOverview = adminFilePage.filePanel.transform.GetChild(2).GetComponent <FileOverview>();

            Assert.IsTrue(fileOverview.authorName.text.Equals("anonymous"));

            yield return(null);
        }
コード例 #10
0
        public void Setup()
        {
            GameObject o = new GameObject("cavasObj");

            o.AddComponent <Canvas>();
            GameObject fileOverviewPanel = Object.Instantiate((GameObject)Resources.Load("Prefabs/File overview Panel"), o.transform);

            fileOverview = fileOverviewPanel.GetComponent <FileOverview>();
            Debug.Log(fileOverview);

            FileJson fileJson = new FileJson();

            fileJson.anonymous              = false;
            fileJson.email                  = "*****@*****.**";
            fileJson.dateUpdated            = "1561736000534";
            fileJson.fileName               = "";
            fileJson.infoDownloadUrl        = new InfoDownloadUrl();
            fileJson.infoDownloadUrl.status = 200;
            fileJson.infoDownloadUrl.URL    = "";
            fileJson.key = "[email protected]|SpangeBob";

            fileOverview.Init(fileJson);
        }
コード例 #11
0
        private void VerifyHashes(IProgressReporter progressReporter, FileOverview fileOverview, CancellationToken cancellationToken)
        {
            fileOverview.NcasHashExceptions = null;

            // Build the list of all CnmtContentEntry with their corresponding CnmtItem
            // The CnmtContentEntry contains a reference to an NCA with the expected Sha256 hash
            var itemsToProcess = new List <Tuple <CnmtContentEntry, CnmtItem> >();

            foreach (var cnmtItem in fileOverview.CnmtContainers.Select(container => container.CnmtItem))
            {
                itemsToProcess.AddRange(cnmtItem.Cnmt.ContentEntries.Select(cnmtContentEntry =>
                {
                    cnmtItem.Errors.RemoveAll(NCA_HASH_CATEGORY);
                    return(new Tuple <CnmtContentEntry, CnmtItem>(cnmtContentEntry, cnmtItem));
                }));
            }

            if (itemsToProcess.Count <= 0)
            {
                fileOverview.NcasHashValidity = NcasValidity.NoNca;
                return;
            }

            var occurredExceptions = new List <Exception>();
            var allValid           = true;
            var operationCanceled  = false;

            try
            {
                fileOverview.NcasHashValidity = NcasValidity.InProgress;

                var processedItem = 0;
                foreach (var(cnmtContentEntry, cnmtItem) in itemsToProcess)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    progressReporter.SetPercentage(0.0);

                    var progressText = LocalizationManager.Instance.Current.Keys.NcaHash_ProgressText.SafeFormat(++processedItem, itemsToProcess.Count);
                    progressReporter.SetText(progressText);

                    var expectedNcaHash = cnmtContentEntry.Hash;
                    var expectedNcaId   = cnmtContentEntry.NcaId.ToStrId();

                    // Search for the referenced NCA
                    var ncaItem = fileOverview.NcaItems.FirstOrDefault(item => item.FileName.StartsWith(expectedNcaId + ".", StringComparison.OrdinalIgnoreCase));

                    if (ncaItem == null)
                    {
                        cnmtItem.Errors.Add(NCA_HASH_CATEGORY, LocalizationManager.Instance.Current.Keys.NcaHash_CnmtItem_Error_NcaMissing.SafeFormat(expectedNcaId));
                        continue;
                    }

                    try
                    {
                        ncaItem.Errors.RemoveAll(NCA_HASH_CATEGORY);

                        //=============================================//
                        //===============> Verify Hash <===============//
                        VerifyFileHash(progressReporter, ncaItem.File, _appSettings.ProgressBufferSize, expectedNcaHash, cancellationToken, out var hashValid);
                        //===============> Verify Hash <===============//
                        //=============================================//

                        if (!hashValid)
                        {
                            allValid = false;
                            ncaItem.Errors.Add(NCA_HASH_CATEGORY, LocalizationManager.Instance.Current.Keys.NcaHash_NcaItem_Invalid);
                            _logger.LogError(LocalizationManager.Instance.Current.Keys.NcaHash_Invalid_Log.SafeFormat(ncaItem.DisplayName));
                        }
                        else
                        {
                            _logger.LogInformation(LocalizationManager.Instance.Current.Keys.NcaHash_Valid_Log.SafeFormat(ncaItem.DisplayName));
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        throw;
                    }
                    catch (Exception ex)
                    {
                        allValid = false;
                        occurredExceptions.Add(ex);
                        ncaItem.Errors.Add(NCA_HASH_CATEGORY, LocalizationManager.Instance.Current.Keys.NcaHash_NcaItem_Exception.SafeFormat(ex.Message));
                        _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.NcaHash_Exception_Log.SafeFormat(ncaItem.DisplayName, ex.Message));
                    }
                }
            }
            catch (OperationCanceledException)
            {
                _logger.LogWarning(LocalizationManager.Instance.Current.Keys.Log_NcaHashCanceled);
                operationCanceled = true;
            }
            catch (Exception ex)
            {
                allValid = false;
                occurredExceptions.Add(ex);
                _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.NcasHash_Error_Log.SafeFormat(ex.Message));
            }

            if (operationCanceled)
            {
                fileOverview.NcasHashValidity = NcasValidity.Unchecked;
            }
            else if (occurredExceptions.Count > 0)
            {
                fileOverview.NcasHashExceptions = occurredExceptions;
                fileOverview.NcasHashValidity   = NcasValidity.Error;
            }
            else
            {
                fileOverview.NcasHashValidity = allValid ? NcasValidity.Valid : NcasValidity.Invalid;
            }
        }
コード例 #12
0
 public void Setup(FileOverview fileOverview)
 {
     _fileOverview = fileOverview ?? throw new ArgumentNullException(nameof(fileOverview));
 }
コード例 #13
0
        private void VerifySignatures(IProgressReporter progressReporter, FileOverview fileOverview)
        {
            fileOverview.NcasHeadersSignatureExceptions = null;
            var ncaItems = fileOverview.NcaItems;

            if (ncaItems.Count <= 0)
            {
                fileOverview.NcasHeadersSignatureValidity = NcasValidity.NoNca;
                return;
            }
            fileOverview.NcasHeadersSignatureValidity = NcasValidity.InProgress;

            var allValid           = true;
            var occurredExceptions = new List <Exception>();

            try
            {
                progressReporter.SetPercentage(0);

                var i = 0;
                foreach (var ncaItem in ncaItems)
                {
                    ncaItem.Errors.RemoveAll(NCA_HEADER_SIGNATURE_CATEGORY);

                    try
                    {
                        //=============================================//
                        //===============> Verify Hash <===============//
                        var validity = ncaItem.Nca.VerifyHeaderSignature();
                        //===============> Verify Hash <===============//
                        //=============================================//
                        ncaItem.HeaderSignatureValidity = validity;

                        if (validity != Validity.Valid)
                        {
                            allValid = false;
                            ncaItem.Errors.Add(NCA_HEADER_SIGNATURE_CATEGORY, LocalizationManager.Instance.Current.Keys.NcaHeaderSignature_Invalid.SafeFormat(validity.ToString()));
                            _logger.LogError(LocalizationManager.Instance.Current.Keys.NcaHeaderSignature_Invalid_Log.SafeFormat(ncaItem.DisplayName, validity.ToString()));
                        }
                        else
                        {
                            _logger.LogInformation(LocalizationManager.Instance.Current.Keys.NcaHeaderSignature_Valid_Log.SafeFormat(ncaItem.DisplayName, validity.ToString()));
                        }
                    }
                    catch (Exception ex)
                    {
                        allValid = false;
                        occurredExceptions.Add(ex);
                        ncaItem.Errors.Add(NCA_HEADER_SIGNATURE_CATEGORY, LocalizationManager.Instance.Current.Keys.NcaHeaderSignature_Error.SafeFormat(ex.Message));
                        _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.NcaHeaderSignature_Error_log.SafeFormat(ncaItem.DisplayName, ex.Message));
                    }

                    progressReporter.SetPercentage(++i / (double)ncaItems.Count);
                }

                progressReporter.SetPercentage(1);
            }
            catch (Exception ex)
            {
                allValid = false;
                occurredExceptions.Add(ex);
                _logger.LogError(ex, LocalizationManager.Instance.Current.Keys.NcasHeaderSignature_Error_Log.SafeFormat(ex.Message));
            }

            if (occurredExceptions.Count > 0)
            {
                fileOverview.NcasHeadersSignatureExceptions = occurredExceptions;
                fileOverview.NcasHeadersSignatureValidity   = NcasValidity.Error;
            }
            else
            {
                fileOverview.NcasHeadersSignatureValidity = allValid ? NcasValidity.Valid : NcasValidity.Invalid;
            }
        }
コード例 #14
0
            public FileOverview CreateNspOverview(NspItem nspItem)
            {
                var fileOverview = new FileOverview(nspItem);

                return(FillOverview(fileOverview, nspItem));
            }