forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cs
More file actions
2042 lines (1655 loc) · 72.2 KB
/
MainWindow.cs
File metadata and controls
2042 lines (1655 loc) · 72.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2015-2017 Baldur Karlsson
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Diagnostics;
using System.Net;
using System.Text;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using WeifenLuo.WinFormsUI.Docking;
using renderdocui.Code;
using renderdoc;
namespace renderdocui.Windows
{
public partial class MainWindow : Form, ILogViewerForm, ILogLoadProgressListener, IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == (int)Win32PInvoke.Win32Message.WM_MOUSEWHEEL)
{
int pos = m.LParam.ToInt32();
short x = (short)((pos >> 0) & 0xffff);
short y = (short)((pos >> 16) & 0xffff);
Win32PInvoke.POINT pt = new Win32PInvoke.POINT((int)x, (int)y);
IntPtr wnd = Win32PInvoke.WindowFromPoint(pt);
if (wnd != IntPtr.Zero && wnd != m.HWnd && Control.FromHandle(wnd) != null)
{
Win32PInvoke.SendMessage(wnd, m.Msg, m.WParam, m.LParam);
return true;
}
return false;
}
return false;
}
private Core m_Core;
private string m_InitFilename;
private string m_InitRemoteHost;
private uint m_InitRemoteIdent;
private List<LiveCapture> m_LiveCaptures = new List<LiveCapture>();
private string InformationalVersion
{
get
{
var assembly = Assembly.GetExecutingAssembly();
var attrs = assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
if (attrs != null && attrs.Length > 0)
{
AssemblyInformationalVersionAttribute attribute = (AssemblyInformationalVersionAttribute)attrs[0];
if (attribute != null)
return attribute.InformationalVersion;
}
return "";
}
}
private string GitCommitHash
{
get
{
return InformationalVersion.Replace("-official", "").Replace("-beta", "");
}
}
private bool BetaVersion
{
get
{
return InformationalVersion.Contains("-beta");
}
}
private bool OfficialVersion
{
get
{
return InformationalVersion.Contains("-official");
}
}
private string BareVersionString
{
get
{
return Assembly.GetEntryAssembly().GetName().Version.ToString(2);
}
}
private string VersionString
{
get
{
return "v" + Assembly.GetEntryAssembly().GetName().Version.ToString(2);
}
}
public MainWindow(Core core, string initFilename, string remoteHost, uint remoteIdent, bool temp)
{
InitializeComponent();
if (SystemInformation.HighContrast)
dockPanel.Skin = Helpers.MakeHighContrastDockPanelSkin();
Icon = global::renderdocui.Properties.Resources.icon;
renderdocplugin.PluginHelpers.GetPlugins();
statusIcon.Text = "";
statusIcon.Image = null;
statusText.Text = "";
SetTitle();
Application.AddMessageFilter(this);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
m_Core = core;
m_InitFilename = initFilename;
m_InitRemoteHost = remoteHost;
m_InitRemoteIdent = remoteIdent;
OwnTemporaryLog = temp;
resolveSymbolsToolStripMenuItem.Enabled = false;
resolveSymbolsToolStripMenuItem.Text = "Resolve Symbols";
m_Core.CaptureDialog = new Dialogs.CaptureDialog(m_Core, OnCaptureTrigger, OnInjectTrigger);
m_Core.AddLogViewer(this);
m_Core.AddLogProgressListener(this);
m_MessageTick = new System.Threading.Timer(MessageCheck, this as object, 500, 500);
m_RemoteProbe = new System.Threading.Timer(RemoteProbe, this as object, 7500, 7500);
}
private void MainWindow_Load(object sender, EventArgs e)
{
bool loaded = LoadLayout(0);
if (Win32PInvoke.GetModuleHandle("rdocself.dll") != IntPtr.Zero)
{
ToolStripMenuItem beginSelfCap = new ToolStripMenuItem();
beginSelfCap.Text = "Start Self-hosted Capture";
beginSelfCap.Click += new EventHandler((object o, EventArgs a) => { StaticExports.StartSelfHostCapture("rdocself.dll"); });
ToolStripMenuItem endSelfCap = new ToolStripMenuItem();
endSelfCap.Text = "End Self-hosted Capture";
endSelfCap.Click += new EventHandler((object o, EventArgs a) => { StaticExports.EndSelfHostCapture("rdocself.dll"); });
toolsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] {
new System.Windows.Forms.ToolStripSeparator(),
beginSelfCap,
endSelfCap,
});
}
CheckUpdates();
Thread remoteStatusThread = Helpers.NewThread(new ThreadStart(() =>
{
m_Core.Config.AddAndroidHosts();
for (int i = 0; i < m_Core.Config.RemoteHosts.Count; i++)
m_Core.Config.RemoteHosts[i].CheckStatus();
}));
remoteStatusThread.Start();
sendErrorReportToolStripMenuItem.Enabled = OfficialVersion || BetaVersion;
// create default layout if layout failed to load
if (!loaded)
{
m_Core.GetAPIInspector().Show(dockPanel);
m_Core.GetEventBrowser().Show(m_Core.GetAPIInspector().Pane, DockAlignment.Top, 0.5);
m_Core.GetPipelineStateViewer().Show(dockPanel);
var bv = m_Core.GetMeshViewer();
bv.InitFromPersistString("");
bv.Show(dockPanel);
var tv = m_Core.GetTextureViewer();
tv.InitFromPersistString("");
tv.Show(dockPanel);
m_Core.GetTimelineBar().Show(dockPanel);
if (m_Core.CaptureDialog == null)
m_Core.CaptureDialog = new Dialogs.CaptureDialog(m_Core, OnCaptureTrigger, OnInjectTrigger);
m_Core.CaptureDialog.InjectMode = false;
m_Core.CaptureDialog.Show(dockPanel);
}
PopulateRecentFiles();
PopulateRecentCaptures();
if (m_InitRemoteIdent != 0)
{
var live = new LiveCapture(m_Core, m_InitRemoteHost, m_InitRemoteIdent, this);
ShowLiveCapture(live);
}
if (m_InitFilename.Length > 0)
{
LoadFromFilename(m_InitFilename);
m_InitFilename = "";
}
}
#region ILogLoadProgressListener
public void LogfileProgressBegin()
{
BeginInvoke(new Action(() =>
{
statusProgress.Visible = true;
}));
}
public void LogfileProgress(float f)
{
BeginInvoke(new Action(() =>
{
if (statusProgress.Visible)
{
if (f <= 0.0f || f >= 0.999f)
{
statusProgress.Visible = false;
statusText.Text = "";
statusIcon.Image = null;
}
else
{
statusProgress.Value = (int)(statusProgress.Maximum * f);
}
}
}));
}
#endregion
#region ILogViewerForm
public void OnLogfileClosed()
{
contextChooser.Enabled = true;
statusText.Text = "";
statusIcon.Image = null;
statusProgress.Visible = false;
resolveSymbolsToolStripMenuItem.Enabled = false;
resolveSymbolsToolStripMenuItem.Text = "Resolve Symbols";
SetTitle();
// if the remote sever disconnected during log replay, resort back to a 'disconnected' state
if (m_Core.Renderer.Remote != null && !m_Core.Renderer.Remote.ServerRunning)
{
statusText.Text = "Remote server disconnected. To attempt to reconnect please select it again.";
contextChooser.Text = "Replay Context: Local";
m_Core.Renderer.DisconnectFromRemoteServer();
}
}
private static void RemoteProbe(object m)
{
if (!(m is MainWindow)) return;
var me = (MainWindow)m;
if (!me.Created || me.IsDisposed)
return;
// perform a probe of known remote hosts to see if they're running or not
if (!me.m_Core.LogLoading && !me.m_Core.LogLoaded)
{
foreach (var host in me.m_Core.Config.RemoteHosts.ToArray())
{
// don't mess with a host we're connected to - this is handled anyway
if (host.Connected)
continue;
host.CheckStatus();
}
}
}
private static void MessageCheck(object m)
{
if (!(m is MainWindow)) return;
var me = (MainWindow)m;
if (me.m_Core.LogLoaded)
{
me.m_Core.Renderer.BeginInvoke((ReplayRenderer r) =>
{
DebugMessage[] msgs = r.GetDebugMessages();
bool disconnected = false;
if(me.m_Core.Renderer.Remote != null)
{
bool prev = me.m_Core.Renderer.Remote.ServerRunning;
me.m_Core.Renderer.PingRemote();
if(prev != me.m_Core.Renderer.Remote.ServerRunning)
disconnected = true;
}
me.BeginInvoke(new Action(() =>
{
// if we just got disconnected while replaying a log, alert the user.
if (disconnected)
{
MessageBox.Show("Remote server disconnected during replaying of this capture.\n" +
"The replay will now be non-functional. To restore you will have to close the capture, allow " +
"RenderDoc to reconnect and load the capture again",
"Remote server disconnected",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (me.m_Core.Renderer.Remote != null && !me.m_Core.Renderer.Remote.ServerRunning)
me.contextChooser.Image = global::renderdocui.Properties.Resources.cross;
if (msgs.Length > 0)
{
me.m_Core.AddMessages(msgs);
me.m_Core.GetDebugMessages().RefreshMessageList();
}
if (me.m_Core.UnreadMessageCount > 0)
{
me.m_MessageAlternate = !me.m_MessageAlternate;
}
else
{
me.m_MessageAlternate = false;
}
me.LogHasErrors = (me.m_Core.DebugMessages.Count > 0);
}));
});
}
else if(!me.m_Core.LogLoaded && !me.m_Core.LogLoading)
{
if (me.m_Core.Renderer.Remote != null)
me.m_Core.Renderer.PingRemote();
if(!me.Created || me.IsDisposed)
return;
me.BeginInvoke(new Action(() =>
{
if (!me.Created || me.IsDisposed)
return;
if (me.m_Core.Renderer.Remote != null && !me.m_Core.Renderer.Remote.ServerRunning)
{
me.contextChooser.Image = global::renderdocui.Properties.Resources.cross;
me.contextChooser.Text = "Replay Context: Local";
me.statusText.Text = "Remote server disconnected. To attempt to reconnect please select it again.";
me.m_Core.Renderer.DisconnectFromRemoteServer();
}
}));
}
}
private System.Threading.Timer m_MessageTick = null;
private System.Threading.Timer m_RemoteProbe = null;
private bool m_MessageAlternate = false;
private bool LogHasErrors
{
set
{
if (value == true)
{
statusIcon.Image = m_MessageAlternate
? null
: global::renderdocui.Properties.Resources.delete;
statusText.Text = String.Format("{0} loaded. Log has {1} errors, warnings or performance notes. " +
"See the 'Log Errors and Warnings' window.", Path.GetFileName(m_Core.LogFileName), m_Core.DebugMessages.Count);
if (m_Core.UnreadMessageCount > 0)
{
statusText.Text += String.Format(" {0} Unread.", m_Core.UnreadMessageCount);
}
}
else
{
statusIcon.Image = global::renderdocui.Properties.Resources.tick;
statusText.Text = String.Format("{0} loaded. No problems detected.", Path.GetFileName(m_Core.LogFileName));
}
}
}
private void status_DoubleClick(object sender, EventArgs e)
{
m_Core.GetDebugMessages().Show(dockPanel);
}
public void OnLogfileLoaded()
{
// don't allow changing context while log is open
contextChooser.Enabled = false;
LogHasErrors = (m_Core.DebugMessages.Count > 0);
statusProgress.Visible = false;
m_Core.Renderer.BeginInvoke((ReplayRenderer r) => {
bool hasResolver = r.HasCallstacks();
this.BeginInvoke(new Action(() =>
{
resolveSymbolsToolStripMenuItem.Enabled = hasResolver;
resolveSymbolsToolStripMenuItem.Text = hasResolver ? "Resolve Symbols" : "Resolve Symbols - None in log";
}));
});
saveLogToolStripMenuItem.Enabled = true;
SetTitle();
PopulateRecentFiles();
m_Core.GetEventBrowser().Focus();
}
public void OnEventSelected(UInt32 eventID)
{
}
#endregion
#region Layout & Dock Container
private void LoadCustomString(string persistString)
{
string[] parsedStrings = persistString.Split(new char[] { ',' });
if (parsedStrings.Length == 6 && parsedStrings[0] == "WinSize")
{
bool maximised = Convert.ToBoolean(parsedStrings[5]);
Point location = new Point(Convert.ToInt32(parsedStrings[1]), Convert.ToInt32(parsedStrings[2]));
Rectangle bounds = Screen.FromPoint(location).Bounds;
if (location.X <= bounds.Left)
location.X = bounds.Left + 100;
if (location.X >= bounds.Right)
location.X = bounds.Right - 100;
if (location.Y <= bounds.Top)
location.Y = bounds.Top + 100;
if (location.Y >= bounds.Bottom)
location.Y = bounds.Bottom - 100;
Size winsize = new Size(Convert.ToInt32(parsedStrings[3]), Convert.ToInt32(parsedStrings[4]));
winsize.Width = Math.Max(200, winsize.Width);
winsize.Height = Math.Max(200, winsize.Height);
SetBounds(location.X, location.Y, winsize.Width, winsize.Height);
var desired = FormWindowState.Normal;
if (maximised)
desired = FormWindowState.Maximized;
if(WindowState != desired)
WindowState = desired;
}
}
private string SaveCustomString()
{
var r = this.WindowState == FormWindowState.Maximized ? RestoreBounds : Bounds;
return "WinSize," + r.X + "," + r.Y + "," + r.Width + "," + r.Height + "," + (this.WindowState == FormWindowState.Maximized);
}
private bool IsPersist(string persiststring, string typestring)
{
if (persiststring.Length < typestring.Length) return false;
return persiststring.Substring(0, typestring.Length) == typestring;
}
private IDockContent GetContentFromPersistString(string persistString)
{
if (IsPersist(persistString, typeof(EventBrowser).ToString()))
{
var ret = m_Core.GetEventBrowser();
ret.InitFromPersistString(persistString);
return ret;
}
else if (IsPersist(persistString, typeof(TextureViewer).ToString()))
{
var ret = m_Core.GetTextureViewer();
ret.InitFromPersistString(persistString);
return ret;
}
else if (IsPersist(persistString, typeof(BufferViewer).ToString()))
{
var ret = m_Core.GetMeshViewer();
ret.InitFromPersistString(persistString);
return ret;
}
else if (IsPersist(persistString, typeof(APIInspector).ToString()))
return m_Core.GetAPIInspector();
else if (IsPersist(persistString, typeof(PipelineState.PipelineStateViewer).ToString()))
{
var ret = m_Core.GetPipelineStateViewer();
ret.InitFromPersistString(persistString);
return ret;
}
else if (IsPersist(persistString, typeof(DebugMessages).ToString()))
return m_Core.GetDebugMessages();
else if (IsPersist(persistString, typeof(TimelineBar).ToString()))
return m_Core.GetTimelineBar();
else if (IsPersist(persistString, typeof(StatisticsViewer).ToString()))
return m_Core.GetStatisticsViewer();
else if (IsPersist(persistString, typeof(Dialogs.PythonShell).ToString()))
{
return new Dialogs.PythonShell(m_Core);
}
else if (IsPersist(persistString, typeof(Dialogs.CaptureDialog).ToString()))
{
if (m_Core.CaptureDialog == null)
m_Core.CaptureDialog = new Dialogs.CaptureDialog(m_Core, OnCaptureTrigger, OnInjectTrigger);
return m_Core.CaptureDialog;
}
else if (persistString != null && persistString.Length > 0)
LoadCustomString(persistString);
return null;
}
private string GetConfigPath(int layout)
{
string dir = Core.ConfigDirectory;
string filename = "DefaultLayout.config";
if (layout > 0)
{
filename = "Layout" + layout.ToString() + ".config";
}
return Path.Combine(dir, filename);
}
private bool LoadLayout(int layout)
{
string configFile = GetConfigPath(layout);
if (File.Exists(configFile))
{
int cnt = dockPanel.Contents.Count;
for (int i = 0; i < cnt; i++)
if(dockPanel.Contents.Count > 0)
(dockPanel.Contents[0] as Form).Close();
try
{
dockPanel.LoadFromXml(configFile, new DeserializeDockContent(GetContentFromPersistString));
}
catch (System.Xml.XmlException)
{
// file is invalid
return false;
}
catch (InvalidOperationException)
{
// file is invalid
return false;
}
catch (Exception)
{
MessageBox.Show("Something went seriously wrong trying to load the window layout.\n" +
"Trying to recover now, but you might have to delete the layout file in %APPDATA%/renderdoc.\n",
"Error loading window layout",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
return true;
}
return false;
}
private void SaveLayout(int layout)
{
string path = GetConfigPath(layout);
try
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
dockPanel.SaveAsXml(path, SaveCustomString());
}
catch (System.Exception)
{
MessageBox.Show(String.Format("Error saving config file\n{0}\nNo config will be saved out.", path));
}
}
private void LoadSaveLayout(ToolStripItem c, bool save)
{
if (c.Tag is string)
{
int i = 0;
if (int.TryParse((string)c.Tag, out i))
{
if (save)
SaveLayout(i);
else
LoadLayout(i);
}
}
}
private void saveLayout_Click(object sender, EventArgs e)
{
if (sender is ToolStripItem)
LoadSaveLayout((ToolStripItem)sender, true);
}
private void loadLayout_Click(object sender, EventArgs e)
{
if (sender is ToolStripItem)
LoadSaveLayout((ToolStripItem)sender, false);
}
private void SetTitle(string filename)
{
string prefix = "";
if (m_Core != null && m_Core.LogLoaded)
{
prefix = Path.GetFileName(filename);
if (m_Core.APIProps.degraded)
prefix += " !DEGRADED PERFORMANCE!";
prefix += " - ";
}
if (m_Core != null && m_Core.Renderer.Remote != null)
prefix += String.Format("Remote: {0} - ", m_Core.Renderer.Remote.Hostname);
Text = prefix + "RenderDoc ";
if(OfficialVersion)
Text += VersionString;
else if(BetaVersion)
Text += String.Format("{0}-beta - {1}", VersionString, GitCommitHash);
else
Text += String.Format("Unofficial release ({0} - {1})", VersionString, GitCommitHash);
if (IsVersionMismatched())
Text += " - !! VERSION MISMATCH DETECTED !!";
}
private void SetTitle()
{
SetTitle(m_Core != null ? m_Core.LogFileName : "");
}
#endregion
#region Capture & Log Loading
public void LoadLogfile(string filename, bool temporary, bool local)
{
if (PromptCloseLog())
{
if (m_Core.LogLoading) return;
string driver = "";
string machineIdent = "";
ReplaySupport support = ReplaySupport.Unsupported;
bool remoteReplay = !local || (m_Core.Renderer.Remote != null && m_Core.Renderer.Remote.Connected);
if (local)
{
support = StaticExports.SupportLocalReplay(filename, out driver, out machineIdent);
// if the return value suggests remote replay, and it's not already selected, AND the user hasn't
// previously chosen to always replay locally without being prompted, ask if they'd prefer to
// switch to a remote context for replaying.
if (support == ReplaySupport.SuggestRemote && !remoteReplay && !m_Core.Config.AlwaysReplayLocally)
{
var dialog = new Dialogs.SuggestRemoteDialog(driver, machineIdent);
FillRemotesToolStrip(dialog.RemoteItems, false);
dialog.ShowDialog();
if (dialog.Result == Dialogs.SuggestRemoteDialog.SuggestRemoteResult.Cancel)
{
return;
}
else if (dialog.Result == Dialogs.SuggestRemoteDialog.SuggestRemoteResult.Remote)
{
// we only get back here from the dialog once the context switch has begun,
// so contextChooser will have been disabled.
// Check once to see if it's enabled before even popping up the dialog in case
// it has finished already. Otherwise pop up a waiting dialog until it completes
// one way or another, then process the result.
if (!contextChooser.Enabled)
{
ProgressPopup modal = new ProgressPopup((ModalCloseCallback)delegate
{
return contextChooser.Enabled;
}, false);
modal.SetModalText("Please Wait - Checking remote connection...");
modal.ShowDialog();
}
remoteReplay = (m_Core.Renderer.Remote != null && m_Core.Renderer.Remote.Connected);
if (!remoteReplay)
{
string remoteMessage = "Failed to make a connection to the remote server.\n\n";
remoteMessage += "More information may be available in the status bar.";
MessageBox.Show(remoteMessage, "Couldn't connect to remote server", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else
{
// nothing to do - we just continue replaying locally
// however we need to check if the user selected 'always replay locally' and
// set that bit as sticky in the config
if (dialog.AlwaysReplayLocally)
{
m_Core.Config.AlwaysReplayLocally = true;
m_Core.Config.Serialize(Core.ConfigFilename);
}
}
}
if (remoteReplay)
{
support = ReplaySupport.Unsupported;
string[] remoteDrivers = m_Core.Renderer.GetRemoteSupport();
for (int i = 0; i < remoteDrivers.Length; i++)
{
if (driver == remoteDrivers[i])
support = ReplaySupport.Supported;
}
}
}
Thread thread = null;
string origFilename = filename;
// if driver is empty something went wrong loading the log, let it be handled as usual
// below. Otherwise indicate that support is missing.
if (driver.Length > 0 && support == ReplaySupport.Unsupported)
{
if (remoteReplay)
{
string remoteMessage = String.Format("This log was captured with {0} and cannot be replayed on {1}.\n\n", driver, m_Core.Renderer.Remote.Hostname);
remoteMessage += "Try selecting a different remote context in the status bar.";
MessageBox.Show(remoteMessage, "Unsupported logfile type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
else
{
string remoteMessage = String.Format("This log was captured with {0} and cannot be replayed locally.\n\n", driver);
remoteMessage += "Try selecting a remote context in the status bar.";
MessageBox.Show(remoteMessage, "Unsupported logfile type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
}
else
{
if (remoteReplay && local)
{
try
{
filename = m_Core.Renderer.CopyCaptureToRemote(filename, this);
// deliberately leave local as true so that we keep referring to the locally saved log
// some error
if (filename == "")
throw new ApplicationException();
}
catch (Exception)
{
MessageBox.Show("Couldn't copy " + origFilename + " to remote host for replaying", "Error copying to remote",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
thread = Helpers.NewThread(new ThreadStart(() => m_Core.LoadLogfile(filename, origFilename, temporary, local)));
}
thread.Start();
if(!remoteReplay)
m_Core.Config.LastLogPath = Path.GetDirectoryName(filename);
statusText.Text = "Loading " + origFilename + "...";
}
}
public void PopulateRecentFiles()
{
while (recentFilesToolStripMenuItem.DropDownItems.Count > 0)
{
if (recentFilesToolStripMenuItem.DropDownItems[0] is ToolStripSeparator)
break;
recentFilesToolStripMenuItem.DropDownItems.RemoveAt(0);
}
recentFilesToolStripMenuItem.Enabled = false;
int i = m_Core.Config.RecentLogFiles.Count;
int idx = 0;
foreach (var recentLog in m_Core.Config.RecentLogFiles)
{
var item = new ToolStripMenuItem("&" + i.ToString() + " " + recentLog, null, recentLogMenuItem_Click);
item.Tag = idx;
recentFilesToolStripMenuItem.DropDownItems.Insert(0, item);
i--;
idx++;
recentFilesToolStripMenuItem.Enabled = true;
}
}
private void PopulateRecentCaptures()
{
while (recentCapturesToolStripMenuItem.DropDownItems.Count > 0)
{
if (recentCapturesToolStripMenuItem.DropDownItems[0] is ToolStripSeparator)
break;
recentCapturesToolStripMenuItem.DropDownItems.RemoveAt(0);
}
recentCapturesToolStripMenuItem.Enabled = false;
int i = m_Core.Config.RecentCaptureSettings.Count;
int idx = 0;
foreach (var recentCapture in m_Core.Config.RecentCaptureSettings)
{
var item = new ToolStripMenuItem("&" + i.ToString() + " " + recentCapture, null, recentCaptureMenuItem_Click);
item.Tag = idx;
recentCapturesToolStripMenuItem.DropDownItems.Insert(0, item);
i--;
idx++;
recentCapturesToolStripMenuItem.Enabled = true;
}
}
public bool OwnTemporaryLog = false;
private bool SavedTemporaryLog = false;
public void ShowLiveCapture(LiveCapture live)
{
m_LiveCaptures.Add(live);
live.Show(dockPanel);
}
public void LiveCaptureClosed(LiveCapture live)
{
m_LiveCaptures.Remove(live);
}
private void OpenCaptureConfigFile(String filename, bool exe)
{
if (m_Core.CaptureDialog == null)
m_Core.CaptureDialog = new Dialogs.CaptureDialog(m_Core, OnCaptureTrigger, OnInjectTrigger);
if(exe)
m_Core.CaptureDialog.SetExecutableFilename(filename);
else
m_Core.CaptureDialog.LoadSettings(filename);
m_Core.CaptureDialog.Show(dockPanel);
// workaround for Show() not doing this
if (m_Core.CaptureDialog.DockState == DockState.DockBottomAutoHide ||
m_Core.CaptureDialog.DockState == DockState.DockLeftAutoHide ||
m_Core.CaptureDialog.DockState == DockState.DockRightAutoHide ||
m_Core.CaptureDialog.DockState == DockState.DockTopAutoHide)
{
dockPanel.ActiveAutoHideContent = m_Core.CaptureDialog;
}
}
private void LoadFromFilename(string filename)
{
if (Path.GetExtension(filename) == ".rdc")
{
LoadLogfile(filename, false, true);
}
else if (Path.GetExtension(filename) == ".cap")
{
OpenCaptureConfigFile(filename, false);
}
else if (Path.GetExtension(filename) == ".exe")
{
OpenCaptureConfigFile(filename, true);
}
else
{
// not a recognised filetype, see if we can load it anyway
LoadLogfile(filename, false, true);
}
}
public void CloseLogfile()
{
m_Core.CloseLogfile();
saveLogToolStripMenuItem.Enabled = false;
}
private string lastSaveCapturePath = "";
public string GetSavePath()
{
if(m_Core.Config.DefaultCaptureSaveDirectory != "")
{
try
{
if (lastSaveCapturePath == "")
saveDialog.InitialDirectory = m_Core.Config.DefaultCaptureSaveDirectory;
else
saveDialog.InitialDirectory = lastSaveCapturePath;
}
catch (Exception)
{
}
}
saveDialog.FileName = "";