Skip to content

Commit

Permalink
Exit don't show again thingy
Browse files Browse the repository at this point in the history
Added MoreLinq too
  • Loading branch information
Traderain committed Nov 27, 2016
1 parent 78ec9d1 commit 1f2f788
Show file tree
Hide file tree
Showing 77 changed files with 8,823 additions and 91 deletions.
Binary file modified .vs/VolvoWrench/v14/.suo
Binary file not shown.
5 changes: 4 additions & 1 deletion VolvoWrench/Demo stuff/GoldSource/Verification.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

215 changes: 129 additions & 86 deletions VolvoWrench/Demo stuff/GoldSource/Verification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using MoreLinq;

namespace VolvoWrench.Demo_stuff.GoldSource
{
public partial class Verification : Form
public sealed partial class Verification : Form
{
public List<string> DemopathList;
public Verification()
{
InitializeComponent();
DemopathList = new List<string>();
AllowDrop = true;
}

public static Dictionary<string,CrossParseResult> Df = new Dictionary<string, CrossParseResult>();
Expand All @@ -27,75 +30,119 @@ private void button1_Click(object sender, EventArgs e)
Multiselect = true
};

if (of.ShowDialog() == DialogResult.OK)
if (of.ShowDialog() == DialogResult.OK && of.FileNames.Length > 1)
{
mrtb.Text = @"Please wait. Parsing demos...";
Verify(of.FileNames);
}
else
{
mrtb.Text = @"No file selected/bad file/only 1 file selected!";
}
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}

private void demostartCommandToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
{
if (DemopathList.ToArray().Length <= 32)
Clipboard.SetText("startdemos " + DemopathList
.Select(Path.GetFileNameWithoutExtension)
.OrderBy(x => int.Parse(Regex.Match(x+"0", @"\d+").Value))
.ToList()
.Aggregate((c, n) => c + " " + n));
else
{
Clipboard.SetText(DemopathList
.Select(Path.GetFileNameWithoutExtension)
.OrderBy(x => int.Parse(Regex.Match(x+"0", @"\d+").Value))
.Batch(32)
.Aggregate(String.Empty,(x,y) => x + ";startdemos " + (y.Aggregate((c,n) => c + " " + n))).Substring(1));

}
using (var ni = new NotifyIcon())
{
ni.Icon = SystemIcons.Exclamation;
ni.Visible = true;
ni.ShowBalloonTip(5000, "VolvoWrench", "Demo names copied to clipboard", ToolTipIcon.Info);
}
}

public void Verify(string[] files)
{
mrtb.Text = $@"Please wait. Parsing demos... 0/{files.Length}";
mrtb.Invalidate();
mrtb.Update();
mrtb.Refresh();
Application.DoEvents();
var curr = 0;
foreach (var dt in files.Where(file => File.Exists(file) && Path.GetExtension(file) == ".dem"))
{
DemopathList.Add(dt);
Df.Add(dt, CrossDemoParser.Parse(dt)); //If someone bothers me that its slow make it async.
mrtb.Text = $@"Please wait. Parsing demos... {curr++}/{files.Length}";
mrtb.Invalidate();
mrtb.Update();
mrtb.Refresh();
Application.DoEvents();
foreach (var dt in of.FileNames.Where(file => File.Exists(file) && Path.GetExtension(file) == ".dem"))
{
DemopathList.Add(dt);
Df.Add(dt, CrossDemoParser.Parse(dt)); //If someone bothers me that its slow make it async.
}
if (Df.Any(x => x.Value.Type != Parseresult.GoldSource))
MessageBox.Show(@"Only goldsource supported");
else
}
if (Df.Any(x => x.Value.Type != Parseresult.GoldSource))
MessageBox.Show(@"Only goldsource supported");
else
{
mrtb.Text = "";
mrtb.AppendText("" + "\n");
mrtb.AppendText("Parsed demos. Results:" + "\n");
mrtb.AppendText("General stats:" + "\n");
var frametimeMax = new List<float>();
var frametimeMin = new List<float>();
var frametimeSum = new List<double>();
var msecMin = new List<double>();
var msecMax = new List<double>();
var avgmsec = new List<double>();
foreach (var d in Df)
{
Task.WaitAll();
mrtb.Text = "";
mrtb.AppendText("" + "\n");
mrtb.AppendText("Parsed demos. Results:" + "\n");
mrtb.AppendText("General stats:" + "\n");
var frametimeMax = new List<float>();
var frametimeMin = new List<float>();
var frametimeSum = new List<double>();
var msecMin = new List<double>();
var msecMax = new List<double>();
var avgmsec = new List<double>();
foreach (var d in Df)
float ftm = 0f, ftmx = 0f;
var fts = 0.0;
var count = 0;
int mm = 0, mmx = 0;
long msecSum = 0;
var first = true;
foreach (var f in from entry in d.Value.GsDemoInfo.DirectoryEntries
from frame in entry.Frames
where (int)frame.Key.Type < 2 || (int)frame.Key.Type > 9
select (GoldSource.NetMsgFrame)frame.Value)
{
float ftm = 0f, ftmx = 0f;
var fts = 0.0;
var count = 0;
int mm = 0, mmx = 0;
long msecSum = 0;
var first = true;
foreach (var f in from entry in d.Value.GsDemoInfo.DirectoryEntries
from frame in entry.Frames
where (int) frame.Key.Type < 2 || (int) frame.Key.Type > 9
select (Demo_stuff.GoldSource.GoldSource.NetMsgFrame) frame.Value)
{
fts += f.RParms.Frametime;
msecSum += f.UCmd.Msec;
count++;
fts += f.RParms.Frametime;
msecSum += f.UCmd.Msec;
count++;

if (first)
{
first = false;
ftm = f.RParms.Frametime;
ftmx = f.RParms.Frametime;
mm = f.UCmd.Msec;
mmx = f.UCmd.Msec;
}
else
{
ftm = Math.Min(ftm, f.RParms.Frametime);
ftmx = Math.Max(ftmx, f.RParms.Frametime);
mm = Math.Min(mm, f.UCmd.Msec);
mmx = Math.Max(mmx, f.UCmd.Msec);
}
if (first)
{
first = false;
ftm = f.RParms.Frametime;
ftmx = f.RParms.Frametime;
mm = f.UCmd.Msec;
mmx = f.UCmd.Msec;
}
else
{
ftm = Math.Min(ftm, f.RParms.Frametime);
ftmx = Math.Max(ftmx, f.RParms.Frametime);
mm = Math.Min(mm, f.UCmd.Msec);
mmx = Math.Max(mmx, f.UCmd.Msec);
}
frametimeMax.Add(1/ftmx);
frametimeMin.Add(1/ftm);
frametimeSum.Add(count/fts);
msecMin.Add(1000.0/mm);
msecMax.Add(1000.0/mmx);
avgmsec.Add(1000.0/(msecSum/(double) count));
}
mrtb.AppendText(
$@"
frametimeMax.Add(1 / ftmx);
frametimeMin.Add(1 / ftm);
frametimeSum.Add(count / fts);
msecMin.Add(1000.0 / mm);
msecMax.Add(1000.0 / mmx);
avgmsec.Add(1000.0 / (msecSum / (double)count));
}
mrtb.AppendText($@"
Highest FPS: {(frametimeMin.Max()).ToString("N2")}
Lowest FPS: {(frametimeMin.Min()).ToString("N2")}
Average FPS: {frametimeSum.Average().ToString("N2")}
Expand All @@ -104,45 +151,41 @@ from frame in entry.Frames
Average msec: {avgmsec.Average().ToString("N2")} FPS
Total time of the demos: {Df.Sum(x => x.Value.GsDemoInfo.DirectoryEntries.Sum(y => y.TrackTime))}s" + "\n\n");
mrtb.AppendText("Demo cheat check:" + "\n");
foreach (var dem in Df)
{
mrtb.AppendText(Path.GetFileName(dem.Key) + " -> " + dem.Value.GsDemoInfo.Header.MapName + "\n");
foreach (var f in dem.Value.GsDemoInfo.DirectoryEntries.SelectMany(entry =>
(from frame in entry.Frames.Where(
x => x.Key.Type == Demo_stuff.GoldSource.GoldSource.DemoFrameType.ConsoleCommand)
select (Demo_stuff.GoldSource.GoldSource.ConsoleCommandFrame) frame.Value into f
let cheats = new List<string>
{
mrtb.AppendText("Demo cheat check:" + "\n");
foreach (var dem in Df)
{
mrtb.AppendText(Path.GetFileName(dem.Key) + " -> " + dem.Value.GsDemoInfo.Header.MapName + "\n");
foreach (var f in dem.Value.GsDemoInfo.DirectoryEntries.SelectMany(entry =>
(from frame in entry.Frames.Where(
x => x.Key.Type == GoldSource.DemoFrameType.ConsoleCommand)
select (GoldSource.ConsoleCommandFrame)frame.Value into f
let cheats = new List<string>
{
"+lookup",
"+lookdown",
"+left",
"+right" //TODO: When yalter is not lazy and adds the anticheat frames add them here.
} where cheats.Contains(f.Command) select f))) {mrtb.AppendText(f.Command + "\n");}
}
}
where cheats.Contains(f.Command)
select f))) { mrtb.AppendText(f.Command + "\n"); }
}
}
else
{
mrtb.Text = @"No file selected/bad file!";
}
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
private void Verification_DragEnter(object sender, DragEventArgs e)
{
this.Close();
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
}

private void demostartCommandToClipboardToolStripMenuItem_Click(object sender, EventArgs e)
private void Verification_DragDrop(object sender, DragEventArgs e)
{
var dropfiles = (string[])e.Data.GetData(DataFormats.FileDrop);
Verify(dropfiles);
}

Clipboard.SetText(DemopathList.Select(Path.GetFileNameWithoutExtension).ToList().Aggregate((c,n) =>c + " " + n));
using (var ni = new NotifyIcon())
{
ni.Icon = SystemIcons.Exclamation;
ni.Visible = true;
ni.ShowBalloonTip(5000, "VolvoWrench", "Demo names copied to clipboard", ToolTipIcon.Info);
}
private void Verification_DragLeave(object sender, EventArgs e)
{

}
}
}
60 changes: 60 additions & 0 deletions VolvoWrench/ExtensionMethods/MoreLinq/Acquire.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#region License and Terms
// MoreLINQ - Extensions to LINQ to Objects
// Copyright (c) 2012 Atif Aziz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace MoreLinq
{
using System;
using System.Collections.Generic;

static partial class MoreEnumerable
{
/// <summary>
/// Ensures that a source sequence of <see cref="IDisposable"/>
/// objects are all acquired successfully. If the acquisition of any
/// one <see cref="IDisposable"/> fails then those successfully
/// acquired till that point are disposed.
/// </summary>
/// <typeparam name="TSource">Type of elements in <paramref name="source"/> sequence.</typeparam>
/// <param name="source">Source sequence of <see cref="IDisposable"/> objects.</param>
/// <returns>
/// Returns an array of all the acquired <see cref="IDisposable"/>
/// object and in source order.
/// </returns>
/// <remarks>
/// This operator executes immediately.
/// </remarks>

public static TSource[] Acquire<TSource>(this IEnumerable<TSource> source)
where TSource : IDisposable
{
if (source == null) throw new ArgumentNullException("source");

var disposables = new List<TSource>();
try
{
disposables.AddRange(source);
return disposables.ToArray();
}
catch
{
foreach (var disposable in disposables)
disposable.Dispose();
throw;
}
}
}
}
Loading

0 comments on commit 1f2f788

Please sign in to comment.