コード例 #1
0
ファイル: Torrent.cs プロジェクト: SuRGeoNix/BitSwarm
        public void FillFromMetadata()
        {
            try
            {
                if (metadata.file == null)
                {
                    bitSwarm.StopWithError("No metadata found");
                }

                string curFilePath = Path.Combine(metadata.file.Options.Folder, metadata.file.Filename);
                string curPath     = (new FileInfo(curFilePath)).DirectoryName;

                metadata.file.Dispose();
                BDictionary bInfo = (BDictionary)bParser.Parse(curFilePath);

                if (file.infoHash != Utils.ArrayToStringHex(sha1.ComputeHash(bInfo.EncodeAsBytes())))
                {
                    bitSwarm.StopWithError("[CRITICAL] Metadata SHA1 validation failed");
                }

                file.name = ((BString)bInfo["name"]).ToString();

                string torrentName = Utils.GetValidFileName(file.name) + ".torrent";

                if (!File.Exists(Path.Combine(curPath, torrentName)))
                {
                    File.Move(curFilePath, Path.Combine(bitSwarm.OptionsClone.FolderTorrents, torrentName));
                }

                FillFromInfo(bInfo);
            } catch (Exception e) { bitSwarm.StopWithError($"FillFromMetadata(): {e.Message} - {e.StackTrace}"); }
        }