public void Reload() { ReloadKeySet(); LocalFileSystem serverBaseFs = new LocalFileSystem(GetBasePath()); DefaultFsServerObjects fsServerObjects = DefaultFsServerObjects.GetDefaultEmulatedCreators(serverBaseFs, KeySet); GameCard = fsServerObjects.GameCard; SdCard = fsServerObjects.SdCard; SdCard.SetSdCardInsertionStatus(true); FileSystemServerConfig fsServerConfig = new FileSystemServerConfig { FsCreators = fsServerObjects.FsCreators, DeviceOperator = fsServerObjects.DeviceOperator, ExternalKeySet = KeySet.ExternalKeySet }; FsServer = new FileSystemServer(fsServerConfig); FsClient = FsServer.CreateFileSystemClient(); }
public void AppCat_Packages() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) using (var mb = new Metabank(fs, null, TestSources.RPATH)) { var app = mb.CatalogApp.Applications["TestApp"]; var packages = app.Packages.ToList(); Aver.AreEqual("TestApp", app.Name); Aver.AreEqual("App for unit testing", app.Description); Aver.AreEqual(3, packages.Count); Aver.AreEqual("TestPackage1", packages[0].Name); Aver.AreEqual(Metabank.DEFAULT_PACKAGE_VERSION, packages[0].Version); Aver.AreEqual("TestPackage2", packages[1].Name); Aver.AreEqual("older", packages[1].Version); Aver.AreEqual("TestPackage3", packages[2].Name); Aver.AreEqual(Metabank.DEFAULT_PACKAGE_VERSION, packages[2].Version); } }
public void LoadCart(string exeFsDir, string romFsFile = null) { if (romFsFile != null) { _device.Configuration.VirtualFileSystem.LoadRomFs(romFsFile); } LocalFileSystem codeFs = new LocalFileSystem(exeFsDir); MetaLoader metaData = ReadNpdm(codeFs); _device.Configuration.VirtualFileSystem.ModLoader.CollectMods( new[] { TitleId }, _device.Configuration.VirtualFileSystem.ModLoader.GetModsBasePath(), _device.Configuration.VirtualFileSystem.ModLoader.GetSdModsBasePath()); if (TitleId != 0) { EnsureSaveData(new ApplicationId(TitleId)); } LoadExeFs(codeFs, metaData); }
public static void ProcessRomFs(Context ctx) { if (ctx.Options.OutFile == null) { ctx.Logger.LogMessage("Output file must be specified."); return; } var localFs = new LocalFileSystem(ctx.Options.InFile); var builder = new RomFsBuilder(localFs); IStorage romFs = builder.Build(); ctx.Logger.LogMessage($"Building RomFS as {ctx.Options.OutFile}"); romFs.GetSize(out long romFsSize).ThrowIfFailure(); using (var outFile = new FileStream(ctx.Options.OutFile, FileMode.Create, FileAccess.ReadWrite)) { romFs.CopyToStream(outFile, romFsSize, ctx.Logger); } ctx.Logger.LogMessage($"Finished writing {ctx.Options.OutFile}"); }
/// <exception cref="System.IO.IOException"/> private void TestFileCorruption(LocalFileSystem fileSys) { // create a file and verify that checksum corruption results in // a checksum exception on LocalFS string dir = PathUtils.GetTestDirName(GetType()); Path file = new Path(dir + "/corruption-test.dat"); Path crcFile = new Path(dir + "/.corruption-test.dat.crc"); WriteFile(fileSys, file); int fileLen = (int)fileSys.GetFileStatus(file).GetLen(); byte[] buf = new byte[fileLen]; InputStream @in = fileSys.Open(file); IOUtils.ReadFully(@in, buf, 0, buf.Length); @in.Close(); // check .crc corruption CheckFileCorruption(fileSys, file, crcFile); fileSys.Delete(file, true); WriteFile(fileSys, file); // check data corrutpion CheckFileCorruption(fileSys, file, file); fileSys.Delete(file, true); }
private static void Process(string inputFilePath, string outDirPath, XciTaskType taskType, Keyset keyset, Output Out, bool verifyBeforeDecrypting = true) { using (var inputFile = File.Open(inputFilePath, FileMode.Open, FileAccess.Read).AsStorage()) using (var outputFile = File.Open($"{outDirPath}/xciMeta.dat", FileMode.Create)) { var OutDirFs = new LocalFileSystem(outDirPath); IDirectory destRoot = OutDirFs.OpenDirectory("/", OpenDirectoryMode.All); IFileSystem destFs = destRoot.ParentFileSystem; var header = new byte[] { 0x6e, 0x73, 0x5a, 0x69, 0x70, 0x4d, 0x65, 0x74, 0x61, 0x58, 0x43, 0x49, 0x00 }; outputFile.Write(header, 0, header.Length); var xci = new Xci(keyset, inputFile); var xciHeaderData = new byte[0x200]; var xciCertData = new byte[0x200]; inputFile.Read(xciHeaderData, 0); inputFile.Read(xciCertData, 0x7000); outputFile.Write(xciHeaderData, 0, 0x200); outputFile.Write(xciCertData, 0, 0x200); Out.Log(Print.PrintXci(xci)); var root = xci.OpenPartition(XciPartitionType.Root); if (root == null) { throw new InvalidDataException("Could not find root partition"); } ProcessXci.GetTitleKeys(xci, keyset, Out); foreach (var sub in root.Files) { outputFile.WriteByte(0x0A); outputFile.WriteByte(0x0A); var subDirNameChar = Encoding.ASCII.GetBytes(sub.Name); outputFile.Write(subDirNameChar, 0, subDirNameChar.Length); var subPfs = new PartitionFileSystem(new FileStorage(root.OpenFile(sub, OpenMode.Read))); foreach (var subPfsFile in subPfs.Files) { outputFile.WriteByte(0x0A); var subPfsFileNameChar = Encoding.ASCII.GetBytes(subPfsFile.Name); outputFile.Write(subPfsFileNameChar, 0, subPfsFileNameChar.Length); using (IFile srcFile = subPfs.OpenFile(subPfsFile.Name, OpenMode.Read)) { if (taskType == XciTaskType.extractRomFS && subPfsFile.Name.EndsWith(".nca")) { var fullOutDirPath = $"{outDirPath}/{sub.Name}/{subPfsFile.Name}"; Out.Log($"Extracting {subPfsFile.Name}...\r\n"); ProcessNca.Extract(srcFile.AsStream(), fullOutDirPath, verifyBeforeDecrypting, keyset, Out); } else { var destFileName = Path.Combine(sub.Name, subPfsFile.Name); if (!destFs.DirectoryExists(sub.Name)) { destFs.CreateDirectory(sub.Name); } destFs.CreateFile(destFileName, subPfsFile.Size, CreateFileOptions.None); using (IFile dstFile = destFs.OpenFile(destFileName, OpenMode.Write)) { if (taskType == XciTaskType.decrypt && subPfsFile.Name.EndsWith(".nca")) { ProcessNca.Process(srcFile, dstFile, verifyBeforeDecrypting, keyset, Out); } else { srcFile.CopyTo(dstFile); } } } } } } outputFile.WriteByte(0x0A); outputFile.Dispose(); } }
/// <summary> /// загрузить файл данных с сайта и открыть ряд наблюдений /// </summary> /// <param name="fromDate">с какой даты</param> /// <param name="toDate">до какой даты</param> /// <param name="info">Метеостанция, с которой загружается ряд</param> /// <param name="onPercentChange"></param> /// <param name="checkStop"></param> /// <returns></returns> public RawRange GetRange(DateTime fromDate, DateTime toDate, RP5MeteostationInfo info, Action <double> onPercentChange = null, Func <bool> checkStop = null) { if (toDate < fromDate) { throw new WindEnergyException("Даты указаны неверно"); } switch (Vars.Options.RP5SourceEngine) { case RP5SourceType.LocalDBSearch: return(Vars.RP5Database.GetRange(fromDate, toDate, info, onPercentChange, checkStop)); case RP5SourceType.OnlineAPI: if (toDate - fromDate > TimeSpan.FromDays(365 * LOAD_STEP_YEARS)) // если надо скачать больше трёх лет, то скачиваем по частям { TimeSpan span = toDate - fromDate; RawRange res1 = new RawRange(); DateTime dt; int i = 0; int total = (int)(span.TotalDays / (365 * LOAD_STEP_YEARS)) + 1; for (dt = fromDate; dt <= toDate; dt += TimeSpan.FromDays(365 * LOAD_STEP_YEARS)) { if (checkStop != null) { if (checkStop.Invoke()) { break; } } if (onPercentChange != null) { double pc = ((i / (double)total) * 100d); onPercentChange.Invoke(pc); } RawRange r = GetRange(dt, dt + TimeSpan.FromDays(365 * LOAD_STEP_YEARS), info, onPercentChange, checkStop); res1.Add(r); res1.Name = r.Name; res1.Position = r.Position; res1.Meteostation = r.Meteostation; res1.Height = 10; //высота всегда 10м i++; } //DateTime fr = dt - TimeSpan.FromDays(365 * LOAD_STEP_YEARS); //RawRange r1 = GetRange(fr, toDate, info); return(res1); } #region отправка статистики загрузки string dataS, linkS; switch (info.MeteoSourceType) { case MeteoSourceType.Airport: dataS = "cc_id={0}&cc_str={1}&stat_p=1&s_date1={2}&s_ed3={4}&s_ed4={4}&s_ed5={5}&s_date2={3}&s_ed9=0&s_ed10=-1&s_pe=1&lng_id=2&s_dtimehi=-Период---"; linkS = "https://rp5.ru/responses/reStatistMetar.php"; dataS = string.Format(dataS, info.ID, //cc_id info.CC_Code, //cc_str fromDate.Date.ToString("dd.MM.yyyy"), //from toDate.Date.ToString("dd.MM.yyyy"), //to DateTime.Now.Month, //f_ed3 - только месяц DateTime.Now.Day //f_ed5 - только день ); break; case MeteoSourceType.Meteostation: dataS = "wmo_id={0}&stat_p=1&s_date1={1}&s_ed3={3}&s_ed4={3}&s_ed5={4}&s_date2={2}&s_ed9=0&s_ed10=-1&s_pe=1&lng_id=2&s_dtimehi=-срок---"; linkS = "https://rp5.ru/responses/reStatistSynop.php"; dataS = string.Format(dataS, info.ID, //wmo_id fromDate.Date.ToString("dd.MM.yyyy"), //from toDate.Date.ToString("dd.MM.yyyy"), //to DateTime.Now.Month, //f_ed3 - только месяц DateTime.Now.Day //f_ed5 - только день ); break; default: throw new Exception("Этот тип метеостанций не реализован"); } string strS = this.SendStringPostRequest(linkS, dataS, referer: "https://rp5.ru/", cookies: this.CookieData, customHeaders: this.Headers); #endregion #region получение ссылки на файл string data, link; //получение ссылки на файл switch (info.MeteoSourceType) { case MeteoSourceType.Airport: data = "metar={0}&a_date1={1}&a_date2={2}&f_ed3={3}&f_ed4={4}&f_ed5={5}&f_pe={6}&f_pe1={7}&lng_id=2"; link = "https://rp5.ru/responses/reFileMetar.php"; break; case MeteoSourceType.Meteostation: data = "wmo_id={0}&a_date1={1}&a_date2={2}&f_ed3={3}&f_ed4={4}&f_ed5={5}&f_pe={6}&f_pe1={7}&lng_id=2"; link = "https://rp5.ru/responses/reFileSynop.php"; break; default: throw new Exception("Этот тип метеостанций не реализован"); } data = string.Format(data, info.ID, //id fromDate.Date.ToString("dd.MM.yyyy"), //from toDate.Date.ToString("dd.MM.yyyy"), //to DateTime.Now.Month, //f_ed3 - только месяц DateTime.Now.Month, //f_ed4 - только месяц DateTime.Now.Day, //f_ed5 - только день 1, //f_pe 2 //f_pe1- кодировка (1 - ansi, 2 - utf8, 3 - Unicode) ); string str = this.SendStringPostRequest(link, data, referer: "https://rp5.ru/", cookies: this.CookieData, customHeaders: this.Headers); //ОШИБКИ rp5.ru //запросы к reFileSynop.php //FS004 несуществующий wmo_id //FS002 ошибки в исходных данных (параметрах запроса) //FS000 Ошибка авторизации //FS001- //запросы к reStatistSynop.php //S000 Ошибка авторизации //FM000 Время жизни статистики истекло для этой сессии if (str.Contains("FS004")) { throw new WindEnergyException("Для этого id нет архива погоды", ErrorReason.FS004); } if (str.Contains("FS002")) { throw new WindEnergyException("Ошибка в исходных данных", ErrorReason.FS002); } if (str.Contains("FS000")) { throw new WindEnergyException("Ошибка авторизации", ErrorReason.FS000); } if (str.Contains("FS001-")) { throw new WindEnergyException("Неправильный метод запроса. Ожидается POST", ErrorReason.FS001); } if (str.Contains("FM000")) { throw new WindEnergyException("Время жизни статистики истекло для этой сессии", ErrorReason.FM000); } if (str.Contains("FM004")) { throw new WindEnergyException("Внутренняя ошибка. Архив недоступен или не существует", ErrorReason.FM004); } int start = str.IndexOf("href=") + 5; str = str.Substring(start); int end = str.IndexOf(">"); string lnk = str.Substring(0, end); lnk = lnk.Split(' ')[0] ?? ""; bool checkLink = Uri.TryCreate(lnk, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!checkLink) { throw new WindEnergyException("В парсере ответа rp5 произошла ошибка. Скорее всего, парсер устарел, обратитесь к разработчику"); } #endregion #region загрузка файла с сервера string tmp_dl_file = Vars.LocalFileSystem.GetTempFileName(); WebClient webcl = new WebClient(); webcl.DownloadFile(lnk, tmp_dl_file); webcl.Dispose(); //распаковка string tmp_unpack_file = tmp_dl_file + ".csv"; LocalFileSystem.UnGZip(tmp_dl_file, tmp_unpack_file); //открытие файла RawRange res = LoadCSV(tmp_unpack_file, info); res = new RawRange(res.OrderBy(x => x.Date).ToList()); res.Name = info.Name; res.Position = info.Position; res.Meteostation = info; res.Height = 10; //высота всегда 10м new Task(() => Vars.RP5Meteostations.TryAddMeteostation(info)).Start(); //если такой метеостанции нет в БД, то добавляем return(res); #endregion default: throw new Exception("Этот тип БД не реализован"); } }
static Template() { NamingConvention = new TradelrNamingConvention(); FileSystem = new LocalFileSystem(GeneralConstants.APP_ROOT_DIR); Tags = new Dictionary <string, Type>(); }
public void Seed(SmartObjectContext context) { context.MigrateLocaleResources(MigrateLocaleResources); var mediaStorages = context.Set <MediaStorage>(); var fileSystem = new LocalFileSystem(); var storeMediaInDb = true; { var settings = context.Set <Setting>(); // be careful, this setting does not necessarily exist var storeInDbSetting = settings.FirstOrDefault(x => x.Name == "Media.Images.StoreInDB"); if (storeInDbSetting != null) { storeMediaInDb = storeInDbSetting.Value.ToBool(true); // remove old bool StoreInDB because it's not used anymore settings.Remove(storeInDbSetting); } // set current media storage provider system name settings.AddOrUpdate(x => x.Name, new Setting { Name = "Media.Storage.Provider", Value = (storeMediaInDb ? "MediaStorage.SmartStoreDatabase" : "MediaStorage.SmartStoreFileSystem") }); } #region Pictures if (storeMediaInDb) { PageEntities(context, mediaStorages, context.Set <Picture>().OrderBy(x => x.Id), picture => { #pragma warning disable 612, 618 if (picture.PictureBinary != null && picture.PictureBinary.LongLength > 0) { var mediaStorage = new MediaStorage { Data = picture.PictureBinary }; picture.MediaStorage = mediaStorage; picture.PictureBinary = null; } #pragma warning restore 612, 618 }); } #endregion #region Downloads PageEntities(context, mediaStorages, context.Set <Download>().OrderBy(x => x.Id), download => { #pragma warning disable 612, 618 if (download.DownloadBinary != null && download.DownloadBinary.LongLength > 0) { if (storeMediaInDb) { // move binary data var mediaStorage = new MediaStorage { Data = download.DownloadBinary }; download.MediaStorage = mediaStorage; } else { // move to file system. it's necessary because from now on DownloadService depends on current storage provider // and it would not find the binary data anymore if do not move it. var fileName = GetFileName(download.Id, download.Extension, download.ContentType); var path = fileSystem.Combine(@"Media\Downloads", fileName); fileSystem.WriteAllBytes(path, download.DownloadBinary); } download.DownloadBinary = null; } #pragma warning restore 612, 618 }); #endregion #region Queued email attachments var attachmentQuery = context.Set <QueuedEmailAttachment>() .Where(x => x.StorageLocation == EmailAttachmentStorageLocation.Blob) .OrderBy(x => x.Id); PageEntities(context, mediaStorages, attachmentQuery, attachment => { #pragma warning disable 612, 618 if (attachment.Data != null && attachment.Data.LongLength > 0) { if (storeMediaInDb) { // move binary data var mediaStorage = new MediaStorage { Data = attachment.Data }; attachment.MediaStorage = mediaStorage; } else { // move to file system. it's necessary because from now on QueuedEmailService depends on current storage provider // and it would not find the binary data anymore if do not move it. var fileName = GetFileName(attachment.Id, Path.GetExtension(attachment.Name.EmptyNull()), attachment.MimeType); var path = fileSystem.Combine(@"Media\QueuedEmailAttachment", fileName); fileSystem.WriteAllBytes(path, attachment.Data); } attachment.Data = null; } #pragma warning restore 612, 618 }); #endregion }
public virtual void TestGetLocalFsSetsConfs() { LocalFileSystem lfs = FileSystem.GetLocal(conf); CheckFsConf(lfs, conf, 2); }
private void CompressFunct() { var CompressionIO = new byte[104857600]; var blocksPerChunk = CompressionIO.Length / bs + (CompressionIO.Length % bs > 0 ? 1 : 0); var sourceFs = new LocalFileSystem(inFolderPath); var destFs = new LocalFileSystem(outFolderPath); foreach (var file in sourceFs.EnumerateEntries().Where(item => item.Type == DirectoryEntryType.File)) { Out.Log($"{file.FullPath}\r\n"); var outFileName = $"{file.Name}.nsz"; using (var outputFileBase = FolderTools.CreateAndOpen(file, destFs, outFileName)) using (var outputFile = new FilePositionStorage(outputFileBase)) using (var inputFileBase = sourceFs.OpenFile(file.FullPath, OpenMode.Read)) using (var inputFile = new FilePositionStorage(inputFileBase)) { amountOfBlocks = (int)Math.Ceiling((decimal)inputFile.GetSize() / bs); sizeOfSize = (int)Math.Ceiling(Math.Log(bs, 2) / 8); var perBlockHeaderSize = sizeOfSize + 1; var headerSize = 0x15 + perBlockHeaderSize * amountOfBlocks; outputFile.Seek(headerSize); var nsZipMagic = new byte[] { 0x6e, 0x73, 0x5a, 0x69, 0x70 }; var nsZipMagicRandomKey = new byte[5]; secureRNG.GetBytes(nsZipMagicRandomKey); Util.XorArrays(nsZipMagic, nsZipMagicRandomKey); var chunkIndex = 0; nsZipHeader = new byte[headerSize]; Array.Copy(nsZipMagic, 0x00, nsZipHeader, 0x00, 0x05); Array.Copy(nsZipMagicRandomKey, 0x00, nsZipHeader, 0x05, 0x05); nsZipHeader[0x0A] = 0x00; //Version nsZipHeader[0x0B] = 0x01; //Type nsZipHeader[0x0C] = (byte)(bs >> 32); nsZipHeader[0x0D] = (byte)(bs >> 24); nsZipHeader[0x0E] = (byte)(bs >> 16); nsZipHeader[0x0F] = (byte)(bs >> 8); nsZipHeader[0x10] = (byte)bs; nsZipHeader[0x11] = (byte)(amountOfBlocks >> 24); nsZipHeader[0x12] = (byte)(amountOfBlocks >> 16); nsZipHeader[0x13] = (byte)(amountOfBlocks >> 8); nsZipHeader[0x14] = (byte)amountOfBlocks; sha256Compressed = new SHA256Cng(); long maxPos = inputFile.GetSize(); int blocksLeft; int blocksInThisChunk; do { var outputLen = new int[blocksPerChunk]; //Filled with 0 inputFile.Read(CompressionIO); blocksLeft = amountOfBlocks - chunkIndex * blocksPerChunk; blocksInThisChunk = Math.Min(blocksPerChunk, blocksLeft); var opt = new ParallelOptions() { MaxDegreeOfParallelism = this.MaxDegreeOfParallelism }; //for(int index = 0; index < blocksInThisChunk; ++index) Parallel.For(0, blocksInThisChunk, opt, index => { var currentBlockID = chunkIndex * blocksPerChunk + index; var startPosRelative = index * bs; //Don't directly cast bytesLeft to int or sectors over 2 GB will overflow into negative size long startPos = (long)currentBlockID * (long)bs; long bytesLeft = maxPos - startPos; var blockSize = bs < bytesLeft ? bs : (int)bytesLeft; Out.Print($"Block: {currentBlockID + 1}/{amountOfBlocks} ({opt.MaxDegreeOfParallelism})\r\n"); CompressionAlgorithm compressionAlgorithm; outputLen[index] = CompressBlock(ref CompressionIO, startPosRelative, blockSize, out compressionAlgorithm); //Out.Log($"inputLen[{currentBlockID}]: {blockSize}\r\n"); //Out.Log($"outputLen[{currentBlockID}]: {outputLen[index]} bytesLeft={bytesLeft}\r\n"); var offset = currentBlockID * (sizeOfSize + 1); switch (compressionAlgorithm) { case CompressionAlgorithm.None: nsZipHeader[0x15 + offset] = 0x00; break; case CompressionAlgorithm.Zstandard: nsZipHeader[0x15 + offset] = 0x01; break; case CompressionAlgorithm.LZMA: nsZipHeader[0x15 + offset] = 0x02; break; default: throw new ArgumentOutOfRangeException(); } for (var j = 0; j < sizeOfSize; ++j) { nsZipHeader[0x16 + offset + j] = (byte)(outputLen[index] >> ((sizeOfSize - j - 1) * 8)); } }); for (int index = 0; index < blocksInThisChunk; ++index) { var startPos = index * bs; sha256Compressed.TransformBlock(CompressionIO, startPos, outputLen[index], null, 0); var dataToWrite = CompressionIO.AsSpan().Slice(startPos, outputLen[index]); outputFile.Write(dataToWrite); } ++chunkIndex; } while (blocksLeft - blocksInThisChunk > 0); outputFile.Write(nsZipHeader, 0); sha256Header = new SHA256Cng(); sha256Header.ComputeHash(nsZipHeader); var sha256Hash = new byte[0x20]; Array.Copy(sha256Header.Hash, sha256Hash, 0x20); sha256Compressed.TransformFinalBlock(new byte[0], 0, 0); Util.XorArrays(sha256Hash, sha256Compressed.Hash); //Console.WriteLine(sha256Header.Hash.ToHexString()); //Console.WriteLine(sha256Compressed.Hash.ToHexString()); outputFile.Seek(0, SeekOrigin.End); outputFile.Write(sha256Hash.AsSpan().Slice(0, 0x10)); } } }
static void Main(string[] args) { Console.WriteLine("Nintendo Switch NSP Verifier v1.00"); Console.WriteLine("Copyright 2018 CaitSith2"); Console.WriteLine(""); _path = args.Length >= 1 ? string.Join(" ", args) : Environment.CurrentDirectory; if (new[] { "--help", "-h" }.Any(x => x.Equals(_path, StringComparison.InvariantCultureIgnoreCase))) { Console.WriteLine("Usage: NSPVerify [path to NSP directory]"); Console.WriteLine(""); Console.WriteLine("If the tool is run without specifying a path, it will look for NSPs in the current directory and ALL sub-directories of current directory"); return; } if (!Directory.Exists(_path)) { Console.WriteLine("ERROR: Specified directory does not exist. specify --help for usage information."); return; } IFileSystem fs = new LocalFileSystem(_path); var keys = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch", "prod.keys"); if (File.Exists("keys.txt")) { keys = "keys.txt"; } if (!File.Exists(keys)) { Console.WriteLine($"Cannot verify NSPs without keys.txt. Either put it in the same directory as this tool,"); Console.WriteLine($"or place it in \"{Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".switch")}\" named as prod.keys"); PressAnyKey(); return; } var keyset = ExternalKeys.ReadKeyFile(keys); var badlist = new List <string>(); var exceptionlist = new List <string>(); var files = new List <DirectoryEntry>(); files.AddRange(fs.EnumerateEntries("*.nsp", SearchOptions.RecurseSubdirectories)); files.AddRange(fs.EnumerateEntries("*.nsx", SearchOptions.RecurseSubdirectories)); if (files.Count == 0) { Console.WriteLine("Error: No NSP/NSX files in specified directory"); PressAnyKey(); return; } foreach (DirectoryEntry dentry in files) { var file = dentry.FullPath; var filename = Path.GetFileName(file); var relativefilename = Util.GetRelativePath(file, "/"); Console.Write($"Checking {filename}: "); try { bool ok = true; using (var nspfile = fs.OpenFile(file, OpenMode.Read)) { var nspdata = new PartitionFileSystem(new FileStorage(nspfile)); var cnmtfile = nspdata.Files.FirstOrDefault(x => x.Name.ToLowerInvariant().EndsWith(".cnmt.nca")); if (cnmtfile == null) { Console.WriteLine($"\rChecking {filename}: No cnmt.nca file present"); badlist.Add(relativefilename); continue; } var cnmtdata = nspdata.OpenFile(cnmtfile, OpenMode.Read); Cnmt cnmt; using (var sr = new BinaryReader(cnmtdata.AsStream())) { var cnmthash = SHA256.Create().ComputeHash(sr.ReadBytes((int)cnmtdata.GetSize())); if (!cnmtfile.Name.ToLowerInvariant().Contains(cnmthash.Take(16).ToArray().ToHexString())) { //Put failure here Console.WriteLine($"\rChecking {filename}: cnmt.nca file is corrupted"); badlist.Add(relativefilename); cnmtdata.Dispose(); continue; } sr.BaseStream.Position = 0; var cnmtnca = new Nca(keyset, new FileStorage(cnmtdata)); var section = cnmtnca.OpenStorage(0, IntegrityCheckLevel.ErrorOnInvalid); var sectionpfs = new PartitionFileSystem(section); cnmt = new Cnmt(sectionpfs.OpenFile(sectionpfs.Files[0], OpenMode.Read).AsStream()); } foreach (var entry in cnmt.ContentEntries) { var entryfile = nspdata.Files.FirstOrDefault(x => x.Name.ToLowerInvariant().EndsWith(entry.NcaId.ToHexString() + ".nca")); if (entryfile == null) { if (entry.Type != CnmtContentType.DeltaFragment) { //Put failure here Console.WriteLine($"\rChecking {filename}: one of the entries required by the cnmt.nca is missing."); badlist.Add(relativefilename); break; } continue; } using (var entrynca = nspdata.OpenFile(entryfile, OpenMode.Read)) { var hash = SHA256.Create(); using (var sr = new BinaryReader(entrynca.AsStream())) { while (entrynca.GetSize() != sr.BaseStream.Position) { var entryncadata = sr.ReadBytes(0x100000); hash.TransformBlock(entryncadata, 0, entryncadata.Length, entryncadata, 0); Console.Write($"\rChecking {filename}: {((sr.BaseStream.Position * 100.0) / entrynca.GetSize()):0.0}%"); } hash.TransformFinalBlock(new byte[0], 0, 0); } if (hash.Hash.ToHexString().Equals(entry.Hash.ToHexString())) { Console.Write($"\rChecking {filename}: {100:0.0}%"); continue; } //Put failure here Console.WriteLine($"\rChecking {filename}: one of the entries required by the cnmt.nca is corrupted"); badlist.Add(relativefilename); ok = false; break; } } if (ok) { Console.WriteLine($"\rChecking {filename}: OK "); } //Put Success here } } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); exceptionlist.Add($"{relativefilename}{Environment.NewLine}Exception: \"{ex.GetType()}\" {ex.Message}{Environment.NewLine}Stack Trace: {ex.StackTrace}{Environment.NewLine}"); } } badlist.Insert(0, badlist.Count == 0 ? "None of the files are corrupted. :)" : "The following NSP/NSX files are corrupted:"); exceptionlist.Insert(0, exceptionlist.Count == 0 ? "No exceptions to log. :)" : "Exceptions caused while parsing the following NSP/NSX files:"); try { File.WriteAllText("Corrupted NSPs.txt", string.Join(Environment.NewLine, badlist)); File.WriteAllText("Exception Log.txt", string.Join(Environment.NewLine, exceptionlist)); } catch (Exception ex) { Console.WriteLine($"Could not write the output files \"Corrupted NSPs.txt\" and \"Exception Log.txt\" due to the following exception."); Console.WriteLine($"Exception: \"{ex.GetType()}\" {ex.Message}"); Console.WriteLine($"Stack Trace: {ex.StackTrace}{Environment.NewLine}"); Console.WriteLine(string.Join(Environment.NewLine, badlist)); Console.WriteLine(); Console.WriteLine(string.Join(Environment.NewLine, exceptionlist)); Console.WriteLine(); } Console.WriteLine("Done."); PressAnyKey(); }
public void InitializeTest() { LocalFileSystem = new LocalFileSystem(Config.ProjectTestInputPath); LocalFileSystem.Mount("/Mounted", new LocalFileSystem(Config.ProjectTestInputMountedPath)); LocalFileSystem.Mount("/NewMounted", new LocalFileSystem(Config.ProjectTestInputMountedPath), "/DirectoryOnMountedFileSystem"); }
public override void Setup() { base.Setup(); TransferJobs(LocalFileSystem.GetFullPath(PathToConfigTemplate), TargetFileSystem.GetFullPath(PathToConfig)); }
public void CompleteTest() { string rootPath = @"C:\Temp\FileSystems"; Assert.AreEqual(true, Directory.Exists(rootPath)); CleanUpFileSystem(rootPath); IFileSystem fileSystem = new LocalFileSystem(rootPath); IFileSystemConstant constants = fileSystem.WithFileSystemConstant(); IDirectory rootDirectory = fileSystem.RootDirectory; Assert.AreEqual('\\', constants.DirectorySeparatorChar); // Create directory IDirectory d1 = rootDirectory.WithDirectoryCreator().Create("D1"); Assert.AreEqual("D1", d1.Name); Assert.AreEqual(Path.Combine(rootPath, "D1"), d1.WithAbsolutePath().AbsolutePath); EnsureAncestors(d1.WithAncestorEnumerator(), "FileSystems", "Temp", "C:\\"); // Rename directory. d1.WithDirectoryRenamer().ChangeName("D1.1"); Assert.AreEqual("D1.1", d1.Name); Assert.AreEqual(Path.Combine(rootPath, "D1.1"), d1.WithAbsolutePath().AbsolutePath); Assert.AreEqual(false, Directory.Exists(Path.Combine(rootPath, "D1"))); Assert.AreEqual(true, Directory.Exists(Path.Combine(rootPath, "D1.1"))); // Create file IFile f1 = d1.WithFileCreator().Create("F1", "txt"); Assert.AreEqual(true, File.Exists(Path.Combine(rootPath, d1.Name, "F1.txt"))); Assert.AreEqual(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.txt"), f1.WithAbsolutePath().AbsolutePath); Assert.AreEqual("F1", f1.Name); Assert.AreEqual("txt", f1.Extension); Assert.AreEqual(0, f1.WithFileContentSize().FileSize); // Write to file f1.WithFileContentUpdater().SetContent("Text"); Assert.AreEqual("Text", File.ReadAllText(f1.WithAbsolutePath().AbsolutePath)); // Append to file f1.WithFileContentAppender().AppendContent(".T1"); Assert.AreEqual("Text.T1", File.ReadAllText(f1.WithAbsolutePath().AbsolutePath)); // Override file content f1.WithFileContentUpdater().SetContent("T2"); Assert.AreEqual("T2", File.ReadAllText(f1.WithAbsolutePath().AbsolutePath)); // Read file content Assert.AreEqual("T2", f1.WithFileContentReader().GetContent()); Assert.AreEqual(2, f1.WithFileContentSize().FileSize); // Rename file f1.WithFileRenamer().ChangeName("F1.1"); Assert.AreEqual("F1.1", f1.Name); Assert.AreEqual("txt", f1.Extension); Assert.AreEqual(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.1.txt"), f1.WithAbsolutePath().AbsolutePath); Assert.AreEqual(false, File.Exists(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.txt"))); Assert.AreEqual(true, File.Exists(Path.Combine(d1.WithAbsolutePath().AbsolutePath, "F1.1.txt"))); // Enumerate files. IFileEnumerator fe1 = d1.WithFileEnumerator(); Assert.AreEqual(1, fe1.Count()); // Create files and directories. IFile f2 = d1.WithFileCreator().Create("F2", "txt"); IFile f3 = d1.WithFileCreator().Create("F3", "rtf"); IFile f4 = d1.WithFileCreator().Create("f4", "rtf"); IDirectory d12 = d1.WithDirectoryCreator().Create("D2"); IFile f121 = d12.WithFileCreator().Create("F1", "txt"); IFile f122 = d12.WithFileCreator().Create("F2", "txt"); IFile f123 = d12.WithFileCreator().Create("F3", "rtf"); IFile f124 = d12.WithFileCreator().Create("f4", "rtf"); // Enumerate directories. IDirectoryEnumerator de1 = d1.WithDirectoryEnumerator(); Assert.AreEqual(1, de1.Count()); // Searching directories IEnumerable <IDirectory> s1 = rootDirectory.WithDirectoryNameSearch().FindDirectories(TextSearch.CreatePrefixed("D")); Assert.AreEqual(1, s1.Count()); IEnumerable <IDirectory> s2 = rootDirectory.WithDirectoryPathSearch().FindDirectories(TextSearch.CreatePrefixed("D")); Assert.AreEqual(2, s2.Count()); IEnumerable <IDirectory> s3 = rootDirectory.WithDirectoryPathSearch().FindDirectories(TextSearch.CreateSuffixed("2")); Assert.AreEqual(1, s3.Count()); IEnumerable <IDirectory> s4 = rootDirectory.WithDirectoryPathSearch().FindDirectories(TextSearch.CreateEmpty()); Assert.AreEqual(2, s4.Count()); // Searching files IEnumerable <IFile> s5 = rootDirectory.WithFileNameSearch().FindFiles(TextSearch.CreatePrefixed("f1"), TextSearch.CreateEmpty()); Assert.AreEqual(0, s5.Count()); IEnumerable <IFile> s6 = d1.WithFileNameSearch().FindFiles(TextSearch.CreatePrefixed("f1"), TextSearch.CreateEmpty()); Assert.AreEqual(1, s6.Count()); IEnumerable <IFile> s7 = d1.WithFileNameSearch().FindFiles(TextSearch.CreateEmpty(), TextSearch.CreateMatched("txt")); Assert.AreEqual(2, s7.Count()); IEnumerable <IFile> s8 = d1.WithFileNameSearch().FindFiles(TextSearch.CreateContained("f"), TextSearch.CreateEmpty()); Assert.AreEqual(4, s8.Count()); IEnumerable <IFile> s9 = rootDirectory.WithFilePathSearch().FindFiles(TextSearch.CreateSuffixed("2"), TextSearch.CreateEmpty()); Assert.AreEqual(2, s9.Count()); // Delete file f1.WithFileDeleter().Delete(); //Delete directory d1.WithDirectoryDeleter().Delete(); Assert.AreEqual(false, Directory.Exists(Path.Combine(rootPath, "T1"))); }
/// <exception cref="System.IO.IOException"/> internal virtual FsPermission GetPermission(LocalFileSystem fs, Path p) { return(fs.GetFileStatus(p).GetPermission()); }
/// <exception cref="System.IO.IOException"/> internal virtual string GetGroup(LocalFileSystem fs, Path p) { return(fs.GetFileStatus(p).GetGroup()); }
public void RC_Various_Parallel() { using (var fs = new LocalFileSystem(NOPApplication.Instance)) using (var mb = new Metabank(fs, null, TestSources.RPATH)) { Parallel.For(0, TestSources.PARALLEL_LOOP_TO, (i) => { Thread.SpinWait(Ambient.Random.NextScaledRandomInteger(10, 1000)); Aver.IsTrue(mb.CatalogReg.IsSystem); Aver.IsNotNull(mb.CatalogReg.Regions["US"]); Aver.IsNotNull(mb.CatalogReg.Regions["Europe"]); Aver.AreEqual("US", mb.CatalogReg.Regions["US"].Name); Aver.AreEqual("Europe", mb.CatalogReg.Regions["Europe"].Name); Aver.AreEqual("US", mb.CatalogReg["/US"].Name); Aver.AreEqual("Europe", mb.CatalogReg["/Europe"].Name); Aver.AreEqual("East", mb.CatalogReg["/US/East"].Name); Aver.AreEqual("East", mb.CatalogReg["/US/East.r"].Name); Aver.AreEqual("East", mb.CatalogReg["/US.r/East"].Name); Aver.AreEqual("CLE", mb.CatalogReg["/US/East/CLE"].Name); Aver.AreEqual("CLE", mb.CatalogReg["/US/East/CLE.noc"].Name); Aver.AreEqual("CLE", mb.CatalogReg["/US.r/East/CLE.noc"].Name); Aver.AreEqual("CLE", mb.CatalogReg["/US.r/East.r/CLE.noc"].Name); Aver.AreEqual("I", mb.CatalogReg["/US/East/CLE/A/I"].Name); Aver.AreEqual("A", mb.CatalogReg["/US/East/CLE.noc/A.z"].Name); Aver.AreEqual("wmed0001", mb.CatalogReg["/US/East/CLE/A/I/wmed0001"].Name); Aver.AreEqual("wmed0001", mb.CatalogReg["/US/East/CLE.noc/A/I/wmed0001"].Name); Aver.AreEqual("/US/East/CLE/A/I/wmed0001", mb.CatalogReg["/US/East/CLE/A/I/wmed0001"].RegionPath); Aver.AreEqual("/US/East/CLE/A/I/wmed0001", mb.CatalogReg["/US.r/East/CLE.noc/a/i/wmed0001.h"].RegionPath); Aver.AreEqual("US", mb.CatalogReg.NavigateRegion("/US/East").ParentRegion.Name); Aver.AreEqual("US", mb.CatalogReg.NavigateRegion("/US/East.r").ParentRegion.Name); Aver.AreEqual("US", mb.CatalogReg.NavigateRegion("/US.r/East.r").ParentRegion.Name); Aver.AreEqual("East", mb.CatalogReg.NavigateNOC("/US/East/CLE").ParentRegion.Name); Aver.AreEqual("CLE", mb.CatalogReg.NavigateNOC("/US/East/CLE.noc").Name); Aver.AreEqual("A", mb.CatalogReg.NavigateZone("/US/East/CLE/A/I").ParentZone.Name); Aver.AreEqual("A", mb.CatalogReg.NavigateZone("/US/East/CLE/A.z/I").ParentZone.Name); Aver.AreEqual("A", mb.CatalogReg.NavigateZone("/US/East/CLE/A/I.z").ParentZone.Name); Aver.AreEqual("CLE", mb.CatalogReg.NavigateHost("/US/East/CLE/A/I/wmed0001").ParentZone.NOC.Name); Aver.AreEqual("CLE", mb.CatalogReg.NavigateHost("/US/East/CLE.noc/A.z/I.z/wmed0001.h").ParentZone.NOC.Name); Aver.AreEqual("CLE", mb.CatalogReg.NavigateHost("/US.r/East/CLE.noc/A/I.z/wmed0001.h").ParentZone.NOC.Name); var host = mb.CatalogReg.NavigateHost("/US.r/East/CLE.noc/A/I.z/wmed0001.h"); var list = host.ParentSectionsOnPath.ToList(); Aver.AreEqual(5, list.Count); Aver.AreEqual("US", list[0].Name); Aver.AreEqual("East", list[1].Name); Aver.AreEqual("CLE", list[2].Name); Aver.AreEqual("A", list[3].Name); Aver.AreEqual("I", list[4].Name); Aver.AreEqual(0, mb.CatalogReg.CountMatchingPathSegments("US/East/CLE/A/I", "Africa/Cairo")); Aver.AreEqual(2, mb.CatalogReg.CountMatchingPathSegments("US/East/CLE/A/I", "US/East/JFK")); Aver.AreEqual(4, mb.CatalogReg.CountMatchingPathSegments("US/East/CLE/A/I/wmed0001", "US/East/CLE/A/II/wmed0005")); Aver.AreEqual(0.5d, mb.CatalogReg.GetMatchingPathSegmentRatio("/US/East/CLE/A", "/US/East/JFK/A")); Aver.AreEqual(0d, mb.CatalogReg.GetMatchingPathSegmentRatio("Us", "Europe")); Aver.AreEqual(1d, mb.CatalogReg.GetMatchingPathSegmentRatio("EUROPE", "Europe.r")); }); } }
/// <summary> /// Create the local directory if necessary, check permissions and also ensure /// it can be read from and written into. /// </summary> /// <param name="localFS">local filesystem</param> /// <param name="dir">directory</param> /// <param name="expected">permission</param> /// <exception cref="DiskErrorException"/> /// <exception cref="System.IO.IOException"/> /// <exception cref="Org.Apache.Hadoop.Util.DiskChecker.DiskErrorException"/> public static void CheckDir(LocalFileSystem localFS, Path dir, FsPermission expected ) { MkdirsWithExistsAndPermissionCheck(localFS, dir, expected); CheckDirAccess(localFS.PathToFile(dir)); }
public static void Process(Context ctx) { SwitchFs switchFs; var baseFs = new LocalFileSystem(ctx.Options.InFile); if (Directory.Exists(Path.Combine(ctx.Options.InFile, "Nintendo", "Contents", "registered"))) { ctx.Logger.LogMessage("Treating path as SD card storage"); switchFs = SwitchFs.OpenSdCard(ctx.Keyset, baseFs); } else if (Directory.Exists(Path.Combine(ctx.Options.InFile, "Contents", "registered"))) { ctx.Logger.LogMessage("Treating path as NAND storage"); switchFs = SwitchFs.OpenNandPartition(ctx.Keyset, baseFs); } else { ctx.Logger.LogMessage("Treating path as a directory of loose NCAs"); switchFs = SwitchFs.OpenNcaDirectory(ctx.Keyset, baseFs); } if (ctx.Options.ListNcas) { ctx.Logger.LogMessage(ListNcas(switchFs)); } if (ctx.Options.ListTitles) { ctx.Logger.LogMessage(ListTitles(switchFs)); } if (ctx.Options.ListApps) { ctx.Logger.LogMessage(ListApplications(switchFs)); } if (ctx.Options.ExefsOutDir != null || ctx.Options.ExefsOut != null) { ulong id = ctx.Options.TitleId; if (id == 0) { ctx.Logger.LogMessage("Title ID must be specified to dump ExeFS"); return; } if (!switchFs.Titles.TryGetValue(id, out Title title)) { ctx.Logger.LogMessage($"Could not find title {id:X16}"); return; } if (title.MainNca == null) { ctx.Logger.LogMessage($"Could not find main data for title {id:X16}"); return; } NcaSection section = title.MainNca.Sections[(int)ProgramPartitionType.Code]; if (section == null) { ctx.Logger.LogMessage($"Main NCA for title {id:X16} has no ExeFS section"); return; } if (ctx.Options.ExefsOutDir != null) { title.MainNca.ExtractSection(section.SectionNum, ctx.Options.ExefsOutDir, ctx.Options.IntegrityLevel, ctx.Logger); } if (ctx.Options.ExefsOut != null) { title.MainNca.ExportSection(section.SectionNum, ctx.Options.ExefsOut, ctx.Options.Raw, ctx.Options.IntegrityLevel, ctx.Logger); } } if (ctx.Options.RomfsOutDir != null || ctx.Options.RomfsOut != null) { ulong id = ctx.Options.TitleId; if (id == 0) { ctx.Logger.LogMessage("Title ID must be specified to dump RomFS"); return; } if (!switchFs.Titles.TryGetValue(id, out Title title)) { ctx.Logger.LogMessage($"Could not find title {id:X16}"); return; } if (title.MainNca == null) { ctx.Logger.LogMessage($"Could not find main data for title {id:X16}"); return; } NcaSection section = title.MainNca.Sections.FirstOrDefault(x => x?.Type == SectionType.Romfs || x?.Type == SectionType.Bktr); if (section == null) { ctx.Logger.LogMessage($"Main NCA for title {id:X16} has no RomFS section"); return; } if (ctx.Options.RomfsOutDir != null) { var romfs = new RomFsFileSystem(title.MainNca.OpenSection(section.SectionNum, false, ctx.Options.IntegrityLevel, true)); romfs.Extract(ctx.Options.RomfsOutDir, ctx.Logger); } if (ctx.Options.RomfsOut != null) { title.MainNca.ExportSection(section.SectionNum, ctx.Options.RomfsOut, ctx.Options.Raw, ctx.Options.IntegrityLevel, ctx.Logger); } } if (ctx.Options.OutDir != null) { SaveTitle(ctx, switchFs); } if (ctx.Options.NspOut != null) { ProcessNsp.CreateNsp(ctx, switchFs); } if (ctx.Options.SaveOutDir != null) { ExportSdSaves(ctx, switchFs); } if (ctx.Options.Validate) { ValidateSwitchFs(ctx, switchFs); } }
public Horizon(Switch device) { ControlData = new BlitStruct <ApplicationControlProperty>(1); Device = device; State = new SystemStateMgr(); ResourceLimit = new KResourceLimit(this); KernelInit.InitializeResourceLimit(ResourceLimit); MemoryRegions = KernelInit.GetMemoryRegions(); LargeMemoryBlockAllocator = new KMemoryBlockAllocator(MemoryBlockAllocatorSize * 2); SmallMemoryBlockAllocator = new KMemoryBlockAllocator(MemoryBlockAllocatorSize); UserSlabHeapPages = new KSlabHeap( UserSlabHeapBase, UserSlabHeapItemSize, UserSlabHeapSize); CriticalSection = new KCriticalSection(this); Scheduler = new KScheduler(this); TimeManager = new KTimeManager(); Synchronization = new KSynchronization(this); ContextIdManager = new KContextIdManager(); _kipId = InitialKipId; _processId = InitialProcessId; Scheduler.StartAutoPreemptionThread(); KernelInitialized = true; ThreadCounter = new CountdownEvent(1); Processes = new SortedDictionary <long, KProcess>(); AutoObjectNames = new ConcurrentDictionary <string, KAutoObject>(); // Note: This is not really correct, but with HLE of services, the only memory // region used that is used is Application, so we can use the other ones for anything. KMemoryRegionManager region = MemoryRegions[(int)MemoryRegion.NvServices]; ulong hidPa = region.Address; ulong fontPa = region.Address + HidSize; ulong iirsPa = region.Address + HidSize + FontSize; ulong timePa = region.Address + HidSize + FontSize + IirsSize; HidBaseAddress = (long)(hidPa - DramMemoryMap.DramBase); KPageList hidPageList = new KPageList(); KPageList fontPageList = new KPageList(); KPageList iirsPageList = new KPageList(); KPageList timePageList = new KPageList(); hidPageList.AddRange(hidPa, HidSize / KMemoryManager.PageSize); fontPageList.AddRange(fontPa, FontSize / KMemoryManager.PageSize); iirsPageList.AddRange(iirsPa, IirsSize / KMemoryManager.PageSize); timePageList.AddRange(timePa, TimeSize / KMemoryManager.PageSize); HidSharedMem = new KSharedMemory(this, hidPageList, 0, 0, MemoryPermission.Read); FontSharedMem = new KSharedMemory(this, fontPageList, 0, 0, MemoryPermission.Read); IirsSharedMem = new KSharedMemory(this, iirsPageList, 0, 0, MemoryPermission.Read); KSharedMemory timeSharedMemory = new KSharedMemory(this, timePageList, 0, 0, MemoryPermission.Read); TimeServiceManager.Instance.Initialize(device, this, timeSharedMemory, (long)(timePa - DramMemoryMap.DramBase), TimeSize); AppletState = new AppletStateMgr(this); AppletState.SetFocus(true); Font = new SharedFontManager(device, (long)(fontPa - DramMemoryMap.DramBase)); IUserInterface.InitializePort(this); VsyncEvent = new KEvent(this); LoadKeySet(); ContentManager = new ContentManager(device); // TODO: use set:sys (and get external clock source id from settings) // TODO: use "time!standard_steady_clock_rtc_update_interval_minutes" and implement a worker thread to be accurate. UInt128 clockSourceId = new UInt128(Guid.NewGuid().ToByteArray()); IRtcManager.GetExternalRtcValue(out ulong rtcValue); // We assume the rtc is system time. TimeSpanType systemTime = TimeSpanType.FromSeconds((long)rtcValue); // First init the standard steady clock TimeServiceManager.Instance.SetupStandardSteadyClock(null, clockSourceId, systemTime, TimeSpanType.Zero, TimeSpanType.Zero, false); TimeServiceManager.Instance.SetupStandardLocalSystemClock(null, new SystemClockContext(), systemTime.ToSeconds()); if (NxSettings.Settings.TryGetValue("time!standard_network_clock_sufficient_accuracy_minutes", out object standardNetworkClockSufficientAccuracyMinutes)) { TimeSpanType standardNetworkClockSufficientAccuracy = new TimeSpanType((int)standardNetworkClockSufficientAccuracyMinutes * 60000000000); TimeServiceManager.Instance.SetupStandardNetworkSystemClock(new SystemClockContext(), standardNetworkClockSufficientAccuracy); } TimeServiceManager.Instance.SetupStandardUserSystemClock(null, false, SteadyClockTimePoint.GetRandom()); // FIXME: TimeZone shoud be init here but it's actually done in ContentManager TimeServiceManager.Instance.SetupEphemeralNetworkSystemClock(); LocalFileSystem serverBaseFs = new LocalFileSystem(device.FileSystem.GetBasePath()); DefaultFsServerObjects fsServerObjects = DefaultFsServerObjects.GetDefaultEmulatedCreators(serverBaseFs, KeySet); GameCard = fsServerObjects.GameCard; FileSystemServerConfig fsServerConfig = new FileSystemServerConfig { FsCreators = fsServerObjects.FsCreators, DeviceOperator = fsServerObjects.DeviceOperator, ExternalKeySet = KeySet.ExternalKeySet }; FsServer = new FileSystemServer(fsServerConfig); FsClient = FsServer.CreateFileSystemClient(); }
public static void Test() { IFile personXmlFile = LocalFileSystem.FromFilePath("../../PresentationModels/PersonDefinition.xml"); IFile organizationXmlFile = LocalFileSystem.FromFilePath("../../PresentationModels/OrganizationDefinition.xml"); XmlTypeMappingCollection typeMappings = new XmlTypeMappingCollection().AddStandartKeywords(); IModelDefinition personDefiniton = new XmlModelDefinitionBuilder(typeMappings, new FileContentFactory(personXmlFile)).Create(); IModelDefinition organizationDefinition = new XmlModelDefinitionBuilder(typeMappings, new FileContentFactory(organizationXmlFile)).Create(); XmlModelDefinitionSerializer serializer = new XmlModelDefinitionSerializer(typeMappings); using (StringWriter writer = new StringWriter()) { serializer.Serialize(personDefiniton, writer); Console.WriteLine(writer); } IFile mixedXmlFile = LocalFileSystem.FromFilePath("../../PresentationModels/MixedDataSource.xml"); XmlModelValueGetterFactory getterFactory = new XmlModelValueGetterFactory(mixedXmlFile.With <IFileContentReader>().GetContentAsStream()); XmlModelValueGetterCollection persons = getterFactory.Create(personDefiniton); XmlModelValueGetterCollection organizations = getterFactory.Create(organizationDefinition); Console.WriteLine("---------------------"); foreach (IModelValueGetter getter in persons) { Console.WriteLine( "Person: ({0}) {1}, {2}", getter.GetValueOrDefault("ID", -1), getter.GetValueOrDefault("FirstName", String.Empty), getter.GetValueOrDefault("LastName", String.Empty) ); } foreach (IModelValueGetter getter in organizations) { Console.WriteLine( "Organization: ({0}) {1}", getter.GetValueOrDefault("ID", -1), getter.GetValueOrDefault("Name", String.Empty) ); } XmlModelValueSetterFactory setterFactory = new XmlModelValueSetterFactory("DataSource"); CopyModelValueProvider personCopier = new CopyModelValueProvider(personDefiniton, false); foreach (IModelValueGetter getter in persons) { personCopier.Update(setterFactory.Create(personDefiniton), getter); } CopyModelValueProvider organizationCopier = new CopyModelValueProvider(organizationDefinition, false); foreach (IModelValueGetter getter in organizations) { organizationCopier.Update(setterFactory.Create(organizationDefinition), getter); } //IFile newMixedFile = (IFile)LocalFileSystem.FromFilePath("../../PresentationModels/MixedDataSourceNEW.xml"); using (FileStream stream = new FileStream("../../PresentationModels/MixedDataSourceNEW.xml", FileMode.OpenOrCreate)) { setterFactory.SaveToStream(stream); } }
public static void Process(Context ctx) { using (var file = new LocalStorage(ctx.Options.InFile, FileAccess.ReadWrite)) { bool signNeeded = ctx.Options.SignSave; var save = new SaveDataFileSystem(ctx.Keyset, file, ctx.Options.IntegrityLevel, true); if (ctx.Options.Validate) { save.Verify(ctx.Logger); } if (ctx.Options.OutDir != null) { save.SaveDataFileSystemCore.Extract(ctx.Options.OutDir, ctx.Logger); } if (ctx.Options.DebugOutDir != null) { string dir = ctx.Options.DebugOutDir; ExportSaveDebug(ctx, dir, save); } try { if (ctx.Options.ReplaceFileDest != null && ctx.Options.ReplaceFileSource != null) { string destFilename = ctx.Options.ReplaceFileDest; if (!destFilename.StartsWith("/")) { destFilename = '/' + destFilename; } using (IFile inFile = new LocalFile(ctx.Options.ReplaceFileSource, OpenMode.Read)) { using (IFile outFile = save.OpenFile(destFilename, OpenMode.ReadWrite)) { if (inFile.GetSize() != outFile.GetSize()) { outFile.SetSize(inFile.GetSize()); } inFile.CopyTo(outFile, ctx.Logger); ctx.Logger.LogMessage($"Replaced file {destFilename}"); } } signNeeded = true; } if (ctx.Options.RepackSource != null) { var source = new LocalFileSystem(ctx.Options.RepackSource); save.CleanDirectoryRecursively("/"); save.Commit(ctx.Keyset); source.CopyFileSystem(save); signNeeded = true; } } finally { save.Commit(ctx.Keyset); } if (ctx.Options.TrimSave) { save.FsTrim(); signNeeded = true; ctx.Logger.LogMessage("Trimmed save file"); } if (signNeeded) { if (save.Commit(ctx.Keyset)) { ctx.Logger.LogMessage("Successfully signed save file"); } else { ctx.Logger.LogMessage("Unable to sign save file. Do you have all the required keys?"); } return; } if (ctx.Options.ListFiles) { foreach (DirectoryEntry entry in save.EnumerateEntries()) { ctx.Logger.LogMessage(entry.FullPath); } } ctx.Logger.LogMessage(save.Print()); //ctx.Logger.LogMessage(PrintFatLayout(save.SaveDataFileSystemCore)); } }
private void btnSynthCandles_Click(object sender, EventArgs e) { using (var fs = new LocalFileSystem()) { var sdb = new SecDBFileReader(fs, new FileSystemSessionConnectParams(), tbSecDBFile.Text); //var tradedata = sdb.GetAllStreamData() // .Where( s => s is SecDBFileReader.TradeSample) // .Cast<SecDBFileReader.TradeSample>() // .Select( t => new CandleSample(t.TimeStamp) // { // OpenPrice = t.Price, // ClosePrice = t.Price, // HighPrice = t.Price, // LowPrice = t.Price // } // ); var data = sdb.GetAllStreamData().Where(s => s is SecDBFileReader.TradeSample).SynthesizeCandles(tbSecPeriod.Text.AsUInt(), (cs, qs, i) => {}, (cs, ts, i) => // "Beautifier function" { if (i == 0) { cs.OpenPrice = ts.Price; } cs.HighPrice = Math.Max(cs.HighPrice, ts.Price); cs.LowPrice = cs.LowPrice != 0f ? Math.Min(cs.LowPrice, ts.Price) : ts.Price; cs.ClosePrice = ts.Price; if (ts.IsQty) { if (ts.Side == SecDBFileReader.TradeSample.SideType.Buy) { cs.BuyVolume += ts.Qty; } else { cs.SellVolume += ts.Qty; } } } ); m_Data = new CandleTimeSeries("Candles", 0); m_Data.Views.Register( new CandleView("Candle View", 1) { ShowYLevels = true, ShowBalloons = true }); //m_Data.Views.Register( // new CandleMidLineView("MidLineHiLo", 1) // { // MidLineType = MidLineType.HighLow, // LineStyle = new LineStyle{ Color = Color.FromArgb(200, 255, 0,0), Width = 2} // }); m_Data.Views.Register(new CandleBuySellView("BuySell", 2) { }); data.ForEach(s => m_Data.Add(s)); m_Data.YLevels.Register(new TimeSeries.YLevel("Lo", 0) { Value = m_Data.Data.Min(cs => cs.ClosePrice), AffectsScale = true, HLineStyle = new LineStyle { Color = Color.Red, Width = 2 } }); m_Data.YLevels.Register(new TimeSeries.YLevel("Hi", 0) { Value = m_Data.Data.Max(cs => cs.ClosePrice), AffectsScale = true, HLineStyle = new LineStyle { Color = Color.Blue, Width = 2 } }); chart.Series = m_Data; } }
static void run(string[] args) { using (var app = new AzosApplication(allowNesting: true, args: args, rootConfig: null)) { var silent = app.CommandArgs["s", "silent"].Exists; if (!silent) { ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Welcome.txt")); ConsoleUtils.Info("Build information:"); Console.WriteLine(" Azos: " + BuildInformation.ForFramework); Console.WriteLine(" Tool: " + new BuildInformation(typeof(amm.ProgramBody).Assembly)); } if (app.CommandArgs["?", "h", "help"].Exists) { ConsoleUtils.WriteMarkupContent(typeof(ProgramBody).GetText("Help.txt")); return; } var mbPath = app.CommandArgs .AttrByIndex(0) .ValueAsString(System.Environment.GetEnvironmentVariable(BootConfLoader.ENV_VAR_METABASE_FS_ROOT)); if (!Directory.Exists(mbPath)) { throw new Exception("Specified metabase path not found"); } var fromHost = app.CommandArgs["host", "from"].AttrByIndex(0).Value; if (fromHost.IsNullOrWhiteSpace()) { fromHost = System.Environment.GetEnvironmentVariable(BootConfLoader.ENV_VAR_HOST_NAME); } if (!silent) { ConsoleUtils.Info("Metabase path: " + mbPath); ConsoleUtils.Info("Host (this machine): " + fromHost); } var w = System.Diagnostics.Stopwatch.StartNew(); using (var fs = new LocalFileSystem(app)) using (var mb = new Metabank(fs, new FileSystemSessionConnectParams(), mbPath)) { //using (new BootConfLoader(SystemApplicationType.Tool, mb, fromHost)) using (var skyApp = new SkyApplication(app, SystemApplicationType.Tool, mb, fromHost, allowNesting: false, args: null, rootConfig: null)) { if (app.CommandArgs["gbm"].Exists) { generateManifests(mb, silent); } else { validate(mb, silent); } } } if (!silent) { Console.WriteLine(); ConsoleUtils.Info("Run time: " + w.Elapsed.ToString()); } }//using APP }
public void Process() { if (Context.Options.OutDir == null) { Context.Logger.LogMessage("Output directory must be specified."); return; } var localFs = new LocalFileSystem(Context.Options.InFile); var outFs = new LocalFileSystem(Context.Options.OutDir); FsClient.Register("search".ToU8Span(), localFs); FsClient.Register("out".ToU8Span(), outFs); IEnumerable <DirectoryEntryEx> entries = FsClient.EnumerateEntries("search:/", "*.xci", SearchOptions.CaseInsensitive | SearchOptions.RecurseSubdirectories) .Concat(FsClient.EnumerateEntries("search:/", "*.nsp", SearchOptions.CaseInsensitive | SearchOptions.RecurseSubdirectories)) .Concat(FsClient.EnumerateEntries("search:/", "*.nca", SearchOptions.CaseInsensitive | SearchOptions.RecurseSubdirectories)) .Concat(FsClient.EnumerateEntries("search:/", "*.nso", SearchOptions.CaseInsensitive | SearchOptions.RecurseSubdirectories)); { foreach (DirectoryEntryEx entry in entries) { try { Context.Logger.LogMessage(entry.FullPath); string extension = Path.GetExtension(entry.Name); if (extension.ToLower() == ".xci") { ProcessXci(entry.FullPath); } else if (extension.ToLower() == ".nsp") { ProcessNsp(entry.FullPath); } else if (extension.ToLower() == ".nca") { ProcessNcaFile(entry.FullPath); } else if (extension.ToLower() == ".nso") { string parentDirectory = PathTools.GetParentDirectory(entry.FullPath); // Don't process sets multiple times if (LooseNsoSetsProcessed.Contains(parentDirectory)) { continue; } if (IsNsoSetDirectory(parentDirectory)) { ProcessNsoSetDirectory(parentDirectory); LooseNsoSetsProcessed.Add(parentDirectory); } else { ProcessNso(entry.FullPath); } } } catch (Exception ex) { Console.WriteLine($"Error processing {entry.FullPath}"); Console.WriteLine(ex); } } } CalculateVersions(); RenameOutput(); FsClient.Unmount("search"); FsClient.Unmount("out"); }
private void btnLoadSecDB_Click(object sender, EventArgs e) { using (var fs = new LocalFileSystem()) { var sdb = new SecDBFileReader(fs, new FileSystemSessionConnectParams(), tbSecDBFile.Text); Text = "Exchange: {0}, Origin time: {1}, {2}".Args(sdb.SystemHeader.Exchange, sdb.SystemHeader.Date + sdb.SystemHeader.OriginLocalTimeOffset, sdb.SystemHeader.OriginLocalTimeName); MessageBox.Show(sdb.Headers.ToJSON()); m_Data = new CandleTimeSeries("From file", 0); m_Data.YLevels.Register(new TimeSeries.YLevel("LAST_PRICE", 0) { Value = 0f }); //, HLineStyle = new LineStyle{Color=Color.Red}}); m_Data.Views.Register(new CandleView("Candles", 0) { ShowYLevels = true, ShowBalloons = true }); m_Data.Views.Register(new CandleBuySellView("BuySell", 0) { }); m_Data.Views.Register( new CandleMidLineView("MidLineHiLo", 1) { MidLineType = MidLineType.HighLow, LineStyle = new LineStyle { Color = Color.FromArgb(200, 255, 0, 0), Width = 2 } }); m_Data.Views.Register( new CandleMidLineView("MidLineOpCl1", 2) { MidLineType = MidLineType.OpenClose, LineStyle = new LineStyle { Color = Color.FromArgb(200, 50, 0, 200), Width = 1.5f, DashStyle = System.Drawing.Drawing2D.DashStyle.Dot } }); m_Data.MaxSamples = 100000; var data = sdb.GetCandleDataAsCandleSamples(sdb.CandlesMetadata.Resolutions.Min()); data.ForEach(s => m_Data.Add(s)); m_Data.YLevels["LAST_PRICE"].Value = m_Data.DataReveresed.First().ClosePrice; m_Data.YLevels.Register(new TimeSeries.YLevel("Lo", 0) { Value = m_Data.Data.Min(cs => cs.LowPrice), AffectsScale = false, HLineStyle = new LineStyle { Color = Color.Red, Width = 2 } }); m_Data.YLevels.Register(new TimeSeries.YLevel("Hi", 0) { Value = m_Data.Data.Max(cs => cs.HighPrice), AffectsScale = false, HLineStyle = new LineStyle { Color = Color.Blue, Width = 2 } }); m_Data.Views.Register(new CandleView("Candles2", 0, "MLPane") { BlackWhite = true, ShowBalloons = true }); m_Data.Views.Register( new CandleMidLineView("MidLineOpCl2", 1, "MLPane") { MidLineType = MidLineType.OpenClose, ShowYLevels = true, LineStyle = new LineStyle { Color = Color.FromArgb(200, 255, 180, 0), Width = 3f } }); chart.Series = m_Data; //chart.NotifySeriesChange(); } }
public Runner(ConsoleReader reader) { this.reader = reader; fs = LocalFileSystem.Instance; }
public void Setup() { sut = new LocalFileSystem(); }
private void ImportGameDataClicked(object sender, RoutedEventArgs e) { string filter = @" Any game data (*.xci,*.nca,*.nsp)|*.xci;*.nca;*.nsp| NX Card Image (*.xci)|*.xci| Nintendo Content Archive (*.nca)|*.nca| Nintendo Installable Package (*.nsp)|*.nsp ".FilterMultilineString(); FileInfo[] files = RequestOpenFilesFromUser(".*", filter, "Select game data..."); if (files == null) { return; } TaskManagerPage.Current.Queue.Submit(new RunTask("Processing imported game data...", new Task(() => { IEnumerable <FileInfo> ncas = files.Where((f) => { try { new Nca(HACGUIKeyset.Keyset, new LocalFile(f.FullName, OpenMode.Read).AsStorage()); return(true); } catch (Exception) { return(false); } }); IEnumerable <FileInfo> xcis = files.Except(ncas).Where((f) => { try { new Xci(HACGUIKeyset.Keyset, new LocalFile(f.FullName, OpenMode.Read).AsStorage()); return(true); } catch (Exception) { return(false); } }); IEnumerable <FileInfo> nsp = files.Except(ncas).Except(xcis).Where((f) => { try { new PartitionFileSystem(new LocalFile(f.FullName, OpenMode.Read).AsStorage()); return(true); } catch (Exception) { return(false); } }); List <SwitchFs> switchFilesystems = new List <SwitchFs>(); PseudoFileSystem ncaFs = new PseudoFileSystem(); foreach (FileInfo file in ncas) { LocalFileSystem fs = new LocalFileSystem(file.Directory.FullName); // clean up filename so it only ends with .nca, then map to actual name string s = file.Name; while (s.EndsWith(".nca")) { s = s.Substring(0, s.IndexOf(".nca")); } ncaFs.Add($"/{s}.nca", $"/{file.Name}", fs); } if (ncas.Any()) { switchFilesystems.Add(SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, ncaFs)); } foreach (FileInfo file in xcis) { Xci xci = new Xci(HACGUIKeyset.Keyset, new LocalFile(file.FullName, OpenMode.Read).AsStorage()); switchFilesystems.Add(SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, xci.OpenPartition(XciPartitionType.Secure))); } foreach (FileInfo file in nsp) { PartitionFileSystem fs = new PartitionFileSystem(new LocalFile(file.FullName, OpenMode.Read).AsStorage()); switchFilesystems.Add(SwitchFs.OpenNcaDirectory(HACGUIKeyset.Keyset, fs)); } foreach (SwitchFs fs in switchFilesystems) { DeviceService.FsView.LoadFileSystemAsync("Opening imported data...", () => fs, FSView.TitleSource.Imported, false); } }))); }
public static void Process(Context ctx) { SwitchFs switchFs; var baseFs = new LocalFileSystem(ctx.Options.InFile); if (Directory.Exists(Path.Combine(ctx.Options.InFile, "Nintendo", "Contents", "registered"))) { ctx.Logger.LogMessage("Treating path as SD card storage"); switchFs = SwitchFs.OpenSdCard(ctx.Keyset, baseFs); CheckForNcaFolders(ctx, switchFs); } else if (Directory.Exists(Path.Combine(ctx.Options.InFile, "Contents", "registered"))) { ctx.Logger.LogMessage("Treating path as NAND storage"); switchFs = SwitchFs.OpenNandPartition(ctx.Keyset, baseFs); CheckForNcaFolders(ctx, switchFs); } else { ctx.Logger.LogMessage("Treating path as a directory of loose NCAs"); switchFs = SwitchFs.OpenNcaDirectory(ctx.Keyset, baseFs); } if (ctx.Options.ListNcas) { ctx.Logger.LogMessage(ListNcas(switchFs)); } if (ctx.Options.ListTitles) { ctx.Logger.LogMessage(ListTitles(switchFs)); } if (ctx.Options.ListApps) { ctx.Logger.LogMessage(ListApplications(switchFs)); } if (ctx.Options.ExefsOutDir != null || ctx.Options.ExefsOut != null) { ulong id = ctx.Options.TitleId; if (id == 0) { ctx.Logger.LogMessage("Title ID must be specified to dump ExeFS"); return; } if (!switchFs.Titles.TryGetValue(id, out Title title)) { ctx.Logger.LogMessage($"Could not find title {id:X16}"); return; } if (title.MainNca == null) { ctx.Logger.LogMessage($"Could not find main data for title {id:X16}"); return; } if (!title.MainNca.Nca.SectionExists(NcaSectionType.Code)) { ctx.Logger.LogMessage($"Main NCA for title {id:X16} has no ExeFS section"); return; } if (ctx.Options.ExefsOutDir != null) { IFileSystem fs = title.MainNca.OpenFileSystem(NcaSectionType.Code, ctx.Options.IntegrityLevel); fs.Extract(ctx.Options.ExefsOutDir, ctx.Logger); } if (ctx.Options.ExefsOut != null) { title.MainNca.OpenStorage(NcaSectionType.Code, ctx.Options.IntegrityLevel).WriteAllBytes(ctx.Options.ExefsOut, ctx.Logger); } } if (ctx.Options.RomfsOutDir != null || ctx.Options.RomfsOut != null) { ulong id = ctx.Options.TitleId; if (id == 0) { ctx.Logger.LogMessage("Title ID must be specified to dump RomFS"); return; } if (!switchFs.Titles.TryGetValue(id, out Title title)) { ctx.Logger.LogMessage($"Could not find title {id:X16}"); return; } if (title.MainNca == null) { ctx.Logger.LogMessage($"Could not find main data for title {id:X16}"); return; } if (!title.MainNca.Nca.SectionExists(NcaSectionType.Data)) { ctx.Logger.LogMessage($"Main NCA for title {id:X16} has no RomFS section"); return; } ProcessRomfs.Process(ctx, title.MainNca.OpenStorage(NcaSectionType.Data, ctx.Options.IntegrityLevel)); } if (ctx.Options.OutDir != null) { SaveTitle(ctx, switchFs); } if (ctx.Options.NspOut != null) { ProcessPfs.CreateNsp(ctx, switchFs); } if (ctx.Options.SaveOutDir != null) { ExportSdSaves(ctx, switchFs); } if (ctx.Options.Validate) { ValidateSwitchFs(ctx, switchFs); } }
public virtual void ResetLocalFs() { localFs = FileSystem.GetLocal(new Configuration()); localFs.SetVerifyChecksum(true); }