/// <summary> /// Add new method with zero source code /// </summary> /// <param name="name">Name of new method</param> /// <param name="path">Path of file with source</param> public void AddMethod(string name, string path) { ProjectChanged = true; FileNames.Add(name, path); Comments.Add(name, ""); char[,] source = new char[16, 16]; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { source[i, j] = '0'; } } source[0, 0] = '#';// Empty method immediately ends running Sources.Add(name, source); FilesChanged.Add(name, true); }
/// <summary> /// 仅仅添加外部b64数据 /// </summary> /// <param name="item"></param> /// <param name="b64data"></param> public void AddPlain(string item, string b64data) { if (FileNames.Contains(item) == false) { Count++; FileNames.Add(item); FileDatas.Add(item, null); } if (FileStringDatas.ContainsKey(item) == false) { FileStringDatas.Add(item, b64data); } else { FileStringDatas[item] = (b64data); } }
public static void Prepare(string[] args) { if (args[0].Equals("/lang")) { if (args.Length > 1) { UserSettings.All.LanguageCode = args[1]; } } //Check each arg to know if it's a file. foreach (var arg in args) { if (File.Exists(arg)) { FileNames.Add(arg); } } }
private XDocument LoadFromStarterPack(string baseDir, string fileName) { var name = $"{baseDir}{fileName}.xml"; ViewModels.MainWindow.Trace.Add(new ViewModels.TraceItem() { Msg = $"Loading {name}" }); XDocument doc = null; try { doc = XDocument.Load($"{baseDir}{fileName}.xml"); FileNames.Add(fileName); doc.Changed += (s, e) => IsDirty = true; } catch (Exception ex) { } return(doc); }
public async Task <DialogResult> ShowDialog(Window window) { var dialog = new Avalonia.Controls.SaveFileDialog { DefaultExtension = DefaultExtension, Directory = InitialDirectory, InitialFileName = FileName, Title = Title, Filters = filters }; var file = await dialog.ShowAsync(window.window); FileNames.Clear(); if (file != null) { FileNames.Add(file); } return(FileNames.Count > 0 ? DialogResult.OK : DialogResult.Cancel); }
/// <summary> /// Shows the dialog to the user. /// </summary> /// <param name="owner">The window that owns this dialog.</param> public async Task <DialogResult> ShowDialog(Form owner) { var dialog = new Modern.WindowKit.Controls.SaveFileDialog { DefaultExtension = DefaultExtension, Directory = InitialDirectory, InitialFileName = FileName, Title = Title, Filters = filters }; var file = await dialog.ShowAsync(owner.window); FileNames.Clear(); if (file is not null) { FileNames.Add(file); } return(FileNames.Count > 0 ? DialogResult.OK : DialogResult.Cancel); }
private void OnClick(object sender, EventArgs e) { using (System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog()) { ofd.AddExtension = true; ofd.Filter = FilterString; ofd.Multiselect = IsMultiselect; if (ofd.ShowDialog() != DialogResult.OK) { IsFileNameValid = false; } else { FileName = ofd.FileName; IsFileNameValid = true; foreach (string fileName in ofd.FileNames) { FileNames.Add(fileName); } } } }
public MPQDS1(Stream stream, LevelPreset level, LevelType levelType, IEngineDataManager engineDataManager, IResourceManager resourceManager) { var br = new BinaryReader(stream); Version = br.ReadInt32(); Width = br.ReadInt32() + 1; Height = br.ReadInt32() + 1; Act = br.ReadInt32() + 1; if (Version >= 10) { TagType = br.ReadInt32(); if (TagType == 1 || TagType == 2) { NumberOfTags = 1; } } FileCount = 0; if (Version >= 3) { FileCount = br.ReadInt32(); for (int i = 0; i < FileCount; i++) { var fn = new StringBuilder(); while (true) { var b = br.ReadByte(); if (b == 0) { break; } fn.Append((char)b); } var fnStr = fn.ToString(); if (fnStr.StartsWith(@"\d2\")) { fnStr = fnStr.Substring(4); } FileNames.Add(fnStr); } } if (Version >= 9 && Version <= 13) { br.ReadBytes(8); } if (Version >= 4) { NumberOfWalls = br.ReadInt32(); NumberOfFloors = Version >= 16 ? br.ReadInt32() : 1; } else { NumberOfFloors = 1; NumberOfWalls = 1; NumberOfTags = 1; } var layoutStream = new List <int>(); if (Version < 4) { layoutStream.AddRange(new[] { 1, 9, 5, 12, 11 }); } else { for (var x = 0; x < NumberOfWalls; x++) { layoutStream.Add(1 + x); layoutStream.Add(5 + x); } for (var x = 0; x < NumberOfFloors; x++) { layoutStream.Add(9 + x); } layoutStream.Add(11); if (NumberOfTags > 0) { layoutStream.Add(12); } } WallLayers = new MPQDS1WallLayer[NumberOfWalls]; for (var l = 0; l < NumberOfWalls; l++) { WallLayers[l] = new MPQDS1WallLayer { Orientations = new MPQDS1WallOrientationTileProps[Width * Height], Props = new MPQDS1TileProps[Width * Height] }; } FloorLayers = new MPQDS1FloorLayer[NumberOfFloors]; for (var l = 0; l < NumberOfFloors; l++) { FloorLayers[l] = new MPQDS1FloorLayer { Props = new MPQDS1TileProps[Width * Height] }; } ShadowLayers = new MPQDS1ShadowLayer[1]; for (var l = 0; l < 1; l++) { ShadowLayers[l] = new MPQDS1ShadowLayer { Props = new MPQDS1TileProps[Width * Height] }; } TagLayers = new MPQDS1TagLayer[NumberOfTags]; for (var l = 0; l < NumberOfTags; l++) { TagLayers[l] = new MPQDS1TagLayer { Number = -1 }; } foreach (var idx in layoutStream) { for (var y = 0; y < Height; y++) { for (var x = 0; x < Width; x++) { switch (idx) { // Walls case 1: case 2: case 3: case 4: WallLayers[idx - 1].Props[x + (y * Width)] = new MPQDS1TileProps { Prop1 = br.ReadByte(), Prop2 = br.ReadByte(), Prop3 = br.ReadByte(), Prop4 = br.ReadByte() }; break; // Orientations case 5: case 6: case 7: case 8: // TODO: Orientations if (Version < 7) { br.ReadBytes(4); } else { WallLayers[idx - 5].Orientations[x + (y * Width)] = new MPQDS1WallOrientationTileProps { Orientation1 = br.ReadByte(), Orientation2 = br.ReadByte(), Orientation3 = br.ReadByte(), Orientation4 = br.ReadByte(), }; } break; // Floors case 9: case 10: FloorLayers[idx - 9].Props[x + (y * Width)] = new MPQDS1TileProps { Prop1 = br.ReadByte(), Prop2 = br.ReadByte(), Prop3 = br.ReadByte(), Prop4 = br.ReadByte() }; break; // Shadow case 11: ShadowLayers[idx - 11].Props[x + (y * Width)] = new MPQDS1TileProps { Prop1 = br.ReadByte(), Prop2 = br.ReadByte(), Prop3 = br.ReadByte(), Prop4 = br.ReadByte() }; break; // Tags case 12: TagLayers[idx - 12].Number = br.ReadInt32(); break; default: throw new OpenDiablo2Exception($"Unknown layer {idx} encountered."); } } } } // Load the objects NumberOfObjects = br.ReadInt32(); Objects = new MPQDS1Object[NumberOfObjects]; for (var i = 0; i < NumberOfObjects; i++) { Objects[i] = new MPQDS1Object { Type = br.ReadInt32(), Id = br.ReadInt32(), X = br.ReadInt32(), Y = br.ReadInt32(), }; if (Version > 5) { Objects[i].DS1Flags = br.ReadInt32(); } Objects[i].Info = engineDataManager.Objects.First(x => x.Id == Objects[i].Id); } if (Version >= 12 && (TagType == 1 || TagType == 2)) { if (Version >= 18) { br.ReadInt32(); // Skip a byte (but why?) } NumberOfGroups = br.ReadInt32(); Groups = new MPQDS1Group[NumberOfGroups]; for (var i = 0; i < NumberOfGroups; i++) { Groups[i] = new MPQDS1Group { TileX = br.ReadInt32(), TileY = br.ReadInt32(), Width = br.ReadInt32(), Height = br.ReadInt32() }; if (Version >= 13) { br.ReadInt32(); // Unknown group property value (what is this???) } } } else { Groups = new MPQDS1Group[0]; } if (Version >= 14) { // TODO: NPC Paths } var dt1Mask = level.Dt1Mask; for (var i = 0; i < 32; i++) { var isMasked = ((dt1Mask >> i) & 1) == 1; if (!isMasked || levelType.File[i] == "0") { continue; } DT1s[i] = resourceManager.GetMPQDT1(@"data\global\tiles\" + levelType.File[i].Replace("/", "\\")); } LookupTable = new List <DS1LookupTable>(); foreach (var dt1 in DT1s.Where(x => x != null)) { foreach (var tile in dt1.Tiles) { LookupTable.Add(new DS1LookupTable { MainIndex = tile.MainIndex, Orientation = tile.Orientation, SubIndex = tile.SubIndex, Frame = tile.RarityOrFrameIndex, TileRef = tile }); } } }
private static async Task Process(bool Verbose, Uri Directory, string[] ContactURLs, bool TermsOfServiceAgreed, bool NewKey, string[] DomainNames, DateTime?NotBefore, DateTime?NotAfter, string HttpRootFolder, int PollingInterval, int KeySize, string EMail, string Country, string Locality, string StateOrProvince, string Organization, string OrganizationalUnit, string FileName, string Password) { using (AcmeClient Client = new AcmeClient(Directory)) { Log.Informational("Connecting to directory.", new KeyValuePair <string, object>("URL", Directory.ToString())); AcmeDirectory AcmeDirectory = await Client.GetDirectory(); if (AcmeDirectory.ExternalAccountRequired) { Log.Warning("An external account is required."); } if (AcmeDirectory.TermsOfService != null) { Log.Informational("Terms of service available.", new KeyValuePair <string, object>("URL", AcmeDirectory.TermsOfService.ToString())); } if (AcmeDirectory.Website != null) { Log.Informational("Web site available.", new KeyValuePair <string, object>("URL", AcmeDirectory.Website.ToString())); } Log.Informational("Getting account."); AcmeAccount Account; try { Account = await Client.GetAccount(); Log.Informational("Account found.", new KeyValuePair <string, object>("Created", Account.CreatedAt), new KeyValuePair <string, object>("Initial IP", Account.InitialIp), new KeyValuePair <string, object>("Status", Account.Status), new KeyValuePair <string, object>("Contact", Account.Contact)); if (ContactURLs != null && !AreEqual(Account.Contact, ContactURLs)) { Log.Informational("Updating contact URIs in account."); Account = await Account.Update(ContactURLs); Log.Informational("Account updated.", new KeyValuePair <string, object>("Created", Account.CreatedAt), new KeyValuePair <string, object>("Initial IP", Account.InitialIp), new KeyValuePair <string, object>("Status", Account.Status), new KeyValuePair <string, object>("Contact", Account.Contact)); } } catch (AcmeAccountDoesNotExistException) { Log.Warning("Account not found. Creating account.", new KeyValuePair <string, object>("Contact", ContactURLs), new KeyValuePair <string, object>("TermsOfServiceAgreed", TermsOfServiceAgreed)); Account = await Client.CreateAccount(ContactURLs, TermsOfServiceAgreed); Log.Informational("Account created.", new KeyValuePair <string, object>("Created", Account.CreatedAt), new KeyValuePair <string, object>("Initial IP", Account.InitialIp), new KeyValuePair <string, object>("Status", Account.Status), new KeyValuePair <string, object>("Contact", Account.Contact)); } if (NewKey) { Log.Informational("Generating new key."); await Account.NewKey(); Log.Informational("New key generated."); } if (DomainNames != null) { if (!string.IsNullOrEmpty(HttpRootFolder)) { CheckExists(HttpRootFolder); HttpRootFolder = Path.Combine(HttpRootFolder, ".well-known"); CheckExists(HttpRootFolder); HttpRootFolder = Path.Combine(HttpRootFolder, "acme-challenge"); CheckExists(HttpRootFolder); } Log.Informational("Creating order."); AcmeOrder Order = await Account.OrderCertificate(DomainNames, NotBefore, NotAfter); Log.Informational("Order created.", new KeyValuePair <string, object>("Status", Order.Status), new KeyValuePair <string, object>("Expires", Order.Expires), new KeyValuePair <string, object>("NotBefore", Order.NotBefore), new KeyValuePair <string, object>("NotAfter", Order.NotAfter), new KeyValuePair <string, object>("Identifiers", Order.Identifiers)); List <string> FileNames = null; try { foreach (AcmeAuthorization Authorization in await Order.GetAuthorizations()) { Log.Informational("Processing authorization.", new KeyValuePair <string, object>("Type", Authorization.Type), new KeyValuePair <string, object>("Value", Authorization.Value), new KeyValuePair <string, object>("Status", Authorization.Status), new KeyValuePair <string, object>("Expires", Authorization.Expires), new KeyValuePair <string, object>("Wildcard", Authorization.Wildcard)); AcmeChallenge Challenge; bool Manual = true; int Index = 1; int NrChallenges = Authorization.Challenges.Length; string s; for (Index = 1; Index <= NrChallenges; Index++) { Challenge = Authorization.Challenges[Index - 1]; if (Challenge is AcmeHttpChallenge HttpChallenge) { Log.Informational(Index.ToString() + ") HTTP challenge.", new KeyValuePair <string, object>("Resource", HttpChallenge.ResourceName), new KeyValuePair <string, object>("Response", HttpChallenge.KeyAuthorization), new KeyValuePair <string, object>("Content-Type", "application/octet-stream")); if (!string.IsNullOrEmpty(HttpRootFolder)) { string ChallengeFileName = Path.Combine(HttpRootFolder, HttpChallenge.Token); File.WriteAllBytes(ChallengeFileName, Encoding.ASCII.GetBytes(HttpChallenge.KeyAuthorization)); if (FileNames == null) { FileNames = new List <string>(); } FileNames.Add(ChallengeFileName); Log.Informational("Acknowleding challenge."); Challenge = await HttpChallenge.AcknowledgeChallenge(); Log.Informational("Challenge acknowledged.", new KeyValuePair <string, object>("Status", Challenge.Status)); Manual = false; } else if (!Verbose) { Console.Out.WriteLine(Index.ToString() + ") HTTP challenge."); Console.Out.WriteLine("Resource: " + HttpChallenge.ResourceName); Console.Out.WriteLine("Response: " + HttpChallenge.KeyAuthorization); Console.Out.WriteLine("Content-Type: " + "application/octet-stream"); } } else if (Challenge is AcmeDnsChallenge DnsChallenge) { Log.Informational(Index.ToString() + ") DNS challenge.", new KeyValuePair <string, object>("Domain", DnsChallenge.ValidationDomainNamePrefix + Authorization.Value), new KeyValuePair <string, object>("TXT Record", DnsChallenge.KeyAuthorization)); if (!Verbose) { Console.Out.WriteLine(Index.ToString() + ") DNS challenge."); Console.Out.WriteLine("Domain: " + DnsChallenge.ValidationDomainNamePrefix + Authorization.Value); Console.Out.WriteLine("TXT Record: " + DnsChallenge.KeyAuthorization); } } } if (Manual) { Console.Out.WriteLine(); Console.Out.WriteLine("No automated method found to respond to any of the authorization challenges. " + "You can respond to a challenge manually. After configuring the corresponding " + "resource, enter the number of the corresponding challenge and press ENTER to acknowledge it."); do { Console.Out.Write("Challenge to acknowledge: "); s = Console.In.ReadLine(); }while (!int.TryParse(s, out Index) || Index <= 0 || Index > NrChallenges); Log.Informational("Acknowleding challenge."); Challenge = await Authorization.Challenges[Index - 1].AcknowledgeChallenge(); Log.Informational("Challenge acknowledged.", new KeyValuePair <string, object>("Status", Challenge.Status)); } AcmeAuthorization Authorization2 = Authorization; do { Log.Informational("Waiting to poll authorization status.", new KeyValuePair <string, object>("ms", PollingInterval)); System.Threading.Thread.Sleep(PollingInterval); Log.Informational("Polling authorization."); Authorization2 = await Authorization2.Poll(); Log.Informational("Authorization polled.", new KeyValuePair <string, object>("Type", Authorization2.Type), new KeyValuePair <string, object>("Value", Authorization2.Value), new KeyValuePair <string, object>("Status", Authorization2.Status), new KeyValuePair <string, object>("Expires", Authorization2.Expires), new KeyValuePair <string, object>("Wildcard", Authorization2.Wildcard)); }while (Authorization2.Status == AcmeAuthorizationStatus.pending); if (Authorization2.Status != AcmeAuthorizationStatus.valid) { switch (Authorization2.Status) { case AcmeAuthorizationStatus.deactivated: throw new Exception("Authorization deactivated."); case AcmeAuthorizationStatus.expired: throw new Exception("Authorization expired."); case AcmeAuthorizationStatus.invalid: throw new Exception("Authorization invalid."); case AcmeAuthorizationStatus.revoked: throw new Exception("Authorization revoked."); default: throw new Exception("Authorization not validated."); } } } using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(KeySize)) { Log.Informational("Finalizing order."); SignatureAlgorithm SignAlg = new RsaSha256(RSA); Order = await Order.FinalizeOrder(new Security.ACME.CertificateRequest(SignAlg) { CommonName = DomainNames[0], SubjectAlternativeNames = DomainNames, EMailAddress = EMail, Country = Country, Locality = Locality, StateOrProvince = StateOrProvince, Organization = Organization, OrganizationalUnit = OrganizationalUnit }); Log.Informational("Order finalized.", new KeyValuePair <string, object>("Status", Order.Status), new KeyValuePair <string, object>("Expires", Order.Expires), new KeyValuePair <string, object>("NotBefore", Order.NotBefore), new KeyValuePair <string, object>("NotAfter", Order.NotAfter), new KeyValuePair <string, object>("Identifiers", Order.Identifiers)); if (Order.Status != AcmeOrderStatus.valid) { switch (Order.Status) { case AcmeOrderStatus.invalid: throw new Exception("Order invalid."); default: throw new Exception("Unable to validate oder."); } } if (Order.Certificate == null) { throw new Exception("No certificate URI provided."); } System.Security.Cryptography.X509Certificates.X509Certificate2[] Certificates = await Order.DownloadCertificate(); string CertificateFileName; string CertificateFileName2; int Index = 1; byte[] Bin; DerEncoder KeyOutput = new DerEncoder(); SignAlg.ExportPrivateKey(KeyOutput); StringBuilder PemOutput = new StringBuilder(); PemOutput.AppendLine("-----BEGIN RSA PRIVATE KEY-----"); PemOutput.AppendLine(Convert.ToBase64String(KeyOutput.ToArray(), Base64FormattingOptions.InsertLineBreaks)); PemOutput.AppendLine("-----END RSA PRIVATE KEY-----"); CertificateFileName = FileName + ".key"; Log.Informational("Saving private key.", new KeyValuePair <string, object>("FileName", CertificateFileName)); File.WriteAllText(CertificateFileName, PemOutput.ToString(), Encoding.ASCII); foreach (X509Certificate2 Certificate in Certificates) { if (Index == 1) { CertificateFileName = FileName; } else { CertificateFileName = FileName + Index.ToString(); } CertificateFileName2 = CertificateFileName + ".pem"; CertificateFileName += ".cer"; Bin = Certificate.Export(X509ContentType.Cert); Log.Informational("Saving certificate.", new KeyValuePair <string, object>("FileName", CertificateFileName), new KeyValuePair <string, object>("FileName2", CertificateFileName2), new KeyValuePair <string, object>("FriendlyName", Certificate.FriendlyName), new KeyValuePair <string, object>("HasPrivateKey", Certificate.HasPrivateKey), new KeyValuePair <string, object>("Issuer", Certificate.Issuer), new KeyValuePair <string, object>("NotAfter", Certificate.NotAfter), new KeyValuePair <string, object>("NotBefore", Certificate.NotBefore), new KeyValuePair <string, object>("SerialNumber", Certificate.SerialNumber), new KeyValuePair <string, object>("Subject", Certificate.Subject), new KeyValuePair <string, object>("Thumbprint", Certificate.Thumbprint)); File.WriteAllBytes(CertificateFileName, Bin); PemOutput.Clear(); PemOutput.AppendLine("-----BEGIN CERTIFICATE-----"); PemOutput.AppendLine(Convert.ToBase64String(Bin, Base64FormattingOptions.InsertLineBreaks)); PemOutput.AppendLine("-----END CERTIFICATE-----"); File.WriteAllText(CertificateFileName2, PemOutput.ToString(), Encoding.ASCII); Index++; } } } finally { if (FileNames != null) { foreach (string FileName2 in FileNames) { File.Delete(FileName2); } } } } } }
public void LoadData(string csvFile) { if (csvFile == null || csvFile == "") { MessageBox.Show("Please select a session.", "Error", MessageBoxButton.OK); return; } foreach (string path in csvPaths) { if (path == csvFile) { MessageBox.Show("Session already loaded.", "Error", MessageBoxButton.OK); return; } } Session session; session.path = csvFile; session.isVR = false; int index = csvFile.LastIndexOf('\\'); session.filename = csvFile.Substring(index + 1); session.color = new SolidColorBrush(); session.frameStart = new List <double>(); session.frameEnd = new List <double>(); session.frameTimes = new List <double>(); session.reprojectionStart = new List <double>(); session.reprojectionEnd = new List <double>(); session.reprojectionTimes = new List <double>(); session.vSync = new List <double>(); session.appMissed = new List <bool>(); session.warpMissed = new List <bool>(); session.appMissesCount = 0; session.warpMissesCount = 0; session.validAppFrames = 0; session.lastFrameTime = 0; session.validReproFrames = 0; session.lastReprojectionTime = 0; try { using (var reader = new StreamReader(csvFile)) { // header -> csv layout may differ, identify correct columns based on column title var line = reader.ReadLine(); int indexFrameStart = 0; int indexFrameTimes = 0; int indexFrameEnd = 0; int indexReprojectionStart = 0; int indexReprojectionTimes = 0; int indexReprojectionEnd = 0; int indexVSync = 0; int indexAppMissed = 0; int indexWarpMissed = 0; var metrics = line.Split(','); for (int i = 0; i < metrics.Count(); i++) { if (String.Compare(metrics[i], "AppRenderStart") == 0 || String.Compare(metrics[i], "TimeInSeconds") == 0) { indexFrameStart = i; } // MsUntilRenderComplete needs to be added to AppRenderStart to get the timestamp if (String.Compare(metrics[i], "AppRenderEnd") == 0 || String.Compare(metrics[i], "MsUntilRenderComplete") == 0) { indexFrameEnd = i; } if (String.Compare(metrics[i], "MsBetweenAppPresents") == 0 || String.Compare(metrics[i], "MsBetweenPresents") == 0) { indexFrameTimes = i; } if (String.Compare(metrics[i], "ReprojectionStart") == 0) { indexReprojectionStart = i; } //MsUntilDisplayed needs to be added to AppRenderStart, we don't have a reprojection start timestamp in this case if (String.Compare(metrics[i], "ReprojectionEnd") == 0 || String.Compare(metrics[i], "MsUntilDisplayed") == 0) { indexReprojectionEnd = i; } if (String.Compare(metrics[i], "MsBetweenReprojections") == 0 || String.Compare(metrics[i], "MsBetweenLsrs") == 0) { indexReprojectionTimes = i; } if (String.Compare(metrics[i], "VSync") == 0) { indexVSync = i; session.isVR = true; } if (String.Compare(metrics[i], "AppMissed") == 0 || String.Compare(metrics[i], "Dropped") == 0) { indexAppMissed = i; } if (String.Compare(metrics[i], "WarpMissed") == 0 || String.Compare(metrics[i], "LsrMissed") == 0) { indexWarpMissed = i; } } while (!reader.EndOfStream) { line = reader.ReadLine(); var values = line.Split(','); // last row may contain warning message if (values.Count() != metrics.Count()) { break; } // non VR titles only have app render start and frame times metrics // app render end and reprojection end get calculated based on ms until render complete and ms until displayed metric if (double.TryParse(values[indexFrameStart], out var frameStart) && double.TryParse(values[indexFrameTimes], out var frameTimes) && int.TryParse(values[indexAppMissed], out var appMissed)) { if (frameStart > 0) { session.validAppFrames++; session.lastFrameTime = frameStart; } session.frameStart.Add(frameStart); session.frameTimes.Add(frameTimes); session.appMissed.Add(Convert.ToBoolean(appMissed)); session.appMissesCount += appMissed; } if (double.TryParse(values[indexFrameEnd], out var frameEnd) && double.TryParse(values[indexReprojectionEnd], out var reprojectionEnd)) { if (session.isVR) { session.frameEnd.Add(frameEnd); session.reprojectionEnd.Add(reprojectionEnd); } else { session.frameEnd.Add(frameStart + frameEnd / 1000.0); session.reprojectionEnd.Add(frameStart + reprojectionEnd / 1000.0); } } if (double.TryParse(values[indexReprojectionStart], out var reprojectionStart) && double.TryParse(values[indexReprojectionTimes], out var reprojectionTimes) && double.TryParse(values[indexVSync], out var vSync) && int.TryParse(values[indexWarpMissed], out var warpMissed)) { if (reprojectionStart > 0) { session.validReproFrames++; session.lastReprojectionTime = reprojectionStart; } session.reprojectionStart.Add(reprojectionStart); session.reprojectionTimes.Add(reprojectionTimes); session.vSync.Add(vSync); session.warpMissed.Add(Convert.ToBoolean(warpMissed)); session.warpMissesCount += warpMissed; } } } } catch (IOException) { MessageBox.Show("Could not access file.", "Error", MessageBoxButton.OK); return; } if (session.frameStart.Count() == 0) { // looks like we did not capture any metrics here we support for visualizing MessageBox.Show("Wrong format. Did not save any metrics for visualization.", "Error", MessageBoxButton.OK); } Sessions.Add(session); // frame range size is about 500 if (session.frameStart.Count() <= 600) { frameRanges.Add(0, (session.frameStart.Count() - 1)); } else { frameRanges.Add(0, 500); } UpdateGraphs(); UpdateColorIdentifier(); CsvPaths.Add(csvFile); FileNames.Add(session.Filename); }
public static void Prepare(string[] args) { FileNames.Clear(); for (var i = 0; i < args.Length; i++) { switch (args[i]) { case "/lang": case "-lang": { //Changes the language of the app, example: -lang pt if (args.Length > i + 1) { try { //Fail silently if the language is not properly set. UserSettings.All.LanguageCode = new CultureInfo(args[i + 1]).ThreeLetterISOLanguageName; i++; } catch (Exception e) { LogWriter.Log(e, $"The language code {args[i + 1]} was not recognized."); } } break; } case "-d": case "/d": case "-download": case "/download": { if (args.Length > i + 2) { IsInDownloadMode = true; i++; DownloadMode = args[i++]; DownloadPath = args[i++]; } break; } case "-sm": case "/sm": case "-softmode": case "/softmode": { //Forces using software mode. UserSettings.All.DisableHardwareAcceleration = true; break; } case "-hm": case "/hm": case "-hardmode": case "/hardmode": { //Forces using hardware mode. UserSettings.All.DisableHardwareAcceleration = false; break; } case "-settings": { //Enables the mode which will try to save the settings using administrative privileges. IsInSettingsMode = true; break; } default: { var path = args[i].Trim('"').Trim('\''); //Anything else is treated as file to be imported. if (File.Exists(path)) { FileNames.Add(path); } break; } } } }
public MPQDS1(Stream stream, LevelPreset level, LevelType levelType, IEngineDataManager engineDataManager, IResourceManager resourceManager) { var br = new BinaryReader(stream); Version = br.ReadInt32(); Width = br.ReadInt32() + 1; Height = br.ReadInt32() + 1; Act = br.ReadInt32() + 1; if (Version >= 10) { TagType = br.ReadInt32(); if (TagType == 1 || TagType == 2) { NumberOfTags = 1; } } FileCount = 0; if (Version >= 3) { FileCount = br.ReadInt32(); for (int i = 0; i < FileCount; i++) { var fn = new StringBuilder(); while (true) { var b = br.ReadByte(); if (b == 0) { break; } fn.Append((char)b); } var fnStr = fn.ToString(); if (fnStr.StartsWith("\\d2\\")) { fnStr = fnStr.Substring(4); } FileNames.Add(fnStr); } } if (Version >= 9 && Version <= 13) { br.ReadBytes(8); } if (Version >= 4) { NumberOfWalls = br.ReadInt32(); if (Version >= 16) { NumberOfFloors = br.ReadInt32(); } else { NumberOfFloors = 1; } } else { NumberOfFloors = 1; NumberOfWalls = 1; NumberOfTags = 1; } var layoutStream = new List <int>(); if (Version < 4) { layoutStream.AddRange(new int[] { 1, 9, 5, 12, 11 }); } else { for (var x = 0; x < NumberOfWalls; x++) { layoutStream.Add(1 + x); layoutStream.Add(5 + x); } for (var x = 0; x < NumberOfFloors; x++) { layoutStream.Add(9 + x); } layoutStream.Add(11); if (NumberOfTags > 0) { layoutStream.Add(12); } } WallLayers = new MPQDS1WallLayer[NumberOfWalls]; for (var l = 0; l < NumberOfWalls; l++) { WallLayers[l] = new MPQDS1WallLayer { Orientations = new MPQDS1WallOrientationTileProps[Width * Height], Props = new MPQDS1TileProps[Width * Height] }; } FloorLayers = new MPQDS1FloorLayer[NumberOfFloors]; for (var l = 0; l < NumberOfFloors; l++) { FloorLayers[l] = new MPQDS1FloorLayer { Props = new MPQDS1TileProps[Width * Height] }; } ShadowLayers = new MPQDS1ShadowLayer[1]; for (var l = 0; l < 1; l++) { ShadowLayers[l] = new MPQDS1ShadowLayer { Props = new MPQDS1TileProps[Width * Height] }; } for (int n = 0; n < layoutStream.Count; n++) { for (var y = 0; y < Height; y++) { for (var x = 0; x < Width; x++) { switch (layoutStream[n]) { // Walls case 1: case 2: case 3: case 4: WallLayers[layoutStream[n] - 1].Props[x + (y * Width)] = new MPQDS1TileProps { Prop1 = br.ReadByte(), Prop2 = br.ReadByte(), Prop3 = br.ReadByte(), Prop4 = br.ReadByte() }; break; // Orientations case 5: case 6: case 7: case 8: // TODO: Orientations if (Version < 7) { br.ReadBytes(4); } else { WallLayers[layoutStream[n] - 5].Orientations[x + (y * Width)] = new MPQDS1WallOrientationTileProps { Orientation1 = br.ReadByte(), Orientation2 = br.ReadByte(), Orientation3 = br.ReadByte(), Orientation4 = br.ReadByte(), }; } break; // Floors case 9: case 10: FloorLayers[layoutStream[n] - 9].Props[x + (y * Width)] = new MPQDS1TileProps { Prop1 = br.ReadByte(), Prop2 = br.ReadByte(), Prop3 = br.ReadByte(), Prop4 = br.ReadByte() }; break; // Shadow case 11: ShadowLayers[layoutStream[n] - 11].Props[x + (y * Width)] = new MPQDS1TileProps { Prop1 = br.ReadByte(), Prop2 = br.ReadByte(), Prop3 = br.ReadByte(), Prop4 = br.ReadByte() }; break; // Tags case 12: // TODO: Tags br.ReadBytes(4); break; } } } } var dt1Mask = level.Dt1Mask; for (int i = 0; i < 32; i++) { var isMasked = ((dt1Mask >> i) & 1) == 1; if (!isMasked || levelType.File[i] == "0") { continue; } DT1s[i] = resourceManager.GetMPQDT1("data\\global\\tiles\\" + levelType.File[i].Replace("/", "\\")); } LookupTable = new List <DS1LookupTable>(); foreach (var dt1 in DT1s.Where(x => x != null)) { foreach (var tile in dt1.Tiles) { LookupTable.Add(new DS1LookupTable { MainIndex = tile.MainIndex, Orientation = tile.Orientation, SubIndex = tile.SubIndex, Frame = tile.RarityOrFrameIndex, TileRef = tile }); } } }
/// Main view model, which takes width and height of screen to set limits to image size public MainWindowViewModel(int width, int height, MainWindow window) { // get ref of main window _mainWindow = window; // get cancellation token token = tokenSource.Token; // get all the image files and fill the different lists foreach (var file in Directory.EnumerateFiles(ImageLabeling.input_path) .Where(x => ImageLabeling.extensions.Any(ext => ext == Path.GetExtension(x).ToLower())).OrderBy(x => x)) { Files.Add(file); FileNames.Add(Path.GetFileName(file)); Images.Add(new ImageLabel() { Filename = Path.GetFileName(file), Filepath = file, Image = new Image() { Source = new Bitmap(file), MaxWidth = width * 0.9, MaxHeight = height * 0.9, Stretch = Avalonia.Media.Stretch.Uniform }, isTagged = false, Tag = String.Empty }); } // init the currentX properties and per tag count CurrentIndex = 0; CurrentProgress = 0; CurrentFileName = FileNames[CurrentIndex]; foreach (var clas in ImageLabeling.classes) { PerTagCount[clas] = 0; } // if resuming, read csv, get class names and tagged images if (ImageLabeling.isResuming) { string line; // we already checked that the file exists and contains a valid header in startButton handler using (System.IO.StreamReader file = new System.IO.StreamReader(Path.Combine(ImageLabeling.output_path, ImageLabeling.csv_name))) { // loop through the lines to read the records if there are while ((line = file.ReadLine()) != null) { var splits = line.Split(","); // this is header, skip it if (splits[0] == "Filepath") { continue; } var image = Images.Where(x => x.Filepath == splits[0]).First(); image.isTagged = true; for (int i = 1; i < splits.Length; i++) { if (splits[i] == "1") { image.Tag = ImageLabeling.classes[i - 1]; } } TaggedImages.Add(image); PerTagCount[image.Tag]++; } } CurrentTaggedCount = TaggedImages.Count; // update the current index to be that of the first untagged image for (int i = 0; i < Files.Count; i++) { if (!TaggedImages.Select(x => x.Filepath).Contains(Files[i])) { break; } else { CurrentIndex++; } } // if all images are tagged, set index to first image if (CurrentIndex == Files.Count) { CurrentIndex = 0; } CurrentFileName = FileNames[CurrentIndex]; CurrentProgress = (int)(((float)TaggedImages.Count / Images.Count) * 100); // delete all the copied images foreach (var directory in Directory.EnumerateDirectories(ImageLabeling.output_path)) { foreach (var file in Directory.EnumerateFiles(directory)) { File.Delete(file); } } } // create the folders else { Directory.CreateDirectory(ImageLabeling.output_path); foreach (var clas in ImageLabeling.classes) { Directory.CreateDirectory(Path.Combine(ImageLabeling.output_path, clas)); } } // start new thread for automatic CSV writing every minute Task.Run(() => WriteCSV(), token); }
public static void Prepare(string[] args) { FileNames.Clear(); for (var i = 0; i < args.Length; i++) { switch (args[i]) { case "/lang": case "-lang": { //Changes the language of the app, example: -lang pt if (args.Length > i + 1) { try { //Fail silently if the language is not properly set. UserSettings.All.LanguageCode = new CultureInfo(args[i + 1]).ThreeLetterISOLanguageName; i++; } catch (Exception e) { LogWriter.Log(e, $"The language code {args[i + 1]} was not recognized."); } } break; } case "-d": case "/d": case "-download": case "/download": { if (args.Length > i + 2) { IsInDownloadMode = true; i++; DownloadMode = args[i++]; DownloadPath = args[i++]; } break; } case "-sm": case "/sm": case "-softmode": case "/softmode": { //Forces using software mode. UserSettings.All.DisableHardwareAcceleration = true; break; } case "-hm": case "/hm": case "-hardmode": case "/hardmode": { //Forces using hardware mode. UserSettings.All.DisableHardwareAcceleration = false; break; } case "-settings": { //Enables the mode which will try to save the settings using administrative privileges. IsInSettingsMode = true; break; } case "-n": case "/n": case "/new": case "-new": { NewInstance = true; break; } case "-o": case "/o": case "/open": case "-open": { if (args.Length <= i + 1) { return; } //-open screen-recorder(webcam-recorder/board-recorder/editor/options/startup/minimized) Open = true; #region Get window to open var window = args[++i]; switch (window) { case "m": case "min": case "minimized": WindownToOpen = -1; break; case "up": case "start": case "startup": WindownToOpen = 0; break; case "s": case "screen": case "screen-recorder": WindownToOpen = 1; break; case "w": case "webcam": case "webcam-recorder": WindownToOpen = 2; break; case "b": case "board": case "board-recorder": WindownToOpen = 3; break; case "e": case "editor": WindownToOpen = 4; break; case "o": case "options": WindownToOpen = 5; break; default: Open = false; break; } #endregion break; } case "-r": case "/r": case "/region": case "-region": { try { //-region/-r 100,50,500,200 if (args.Length > i + 1) { Region = Rect.Parse(args[++i]); } } catch (Exception ex) { LogWriter.Log(ex, "Not possible to parse the capture rectangle from arguments", args[i++]); } break; } case "-f": case "/f": case "/framerate": case "-framerate": case "/frequency": case "-frequency": { if (args.Length <= i + 1) { return; } //-framerate/-f (60fps/60fpm/60fph/manual/interaction) ParseFramerate(args[++i].Trim()); break; } case "-l": case "/l": case "/limit": case "-limit": { //-limit/-l 01:30 if (args.Length <= i + 1) { return; } if (TimeSpan.TryParse(args[++i].Trim(), CultureInfo.InvariantCulture, out var time)) { Limit = time; } break; } case "-c": case "/c": case "/capture": case "-capture": { StartCapture = true; break; } default: { var path = args[i].Trim('"').Trim('\''); //Anything else is treated as file to be imported. if (File.Exists(path)) { FileNames.Add(path); } break; } } } }