@@ -14,12 +14,12 @@ namespace ReClassNET.Forms
1414{
1515 public partial class ProcessInfoForm : IconForm
1616 {
17- private readonly RemoteProcess process ;
17+ private readonly IProcessReader process ;
1818
1919 /// <summary>The context menu of the sections grid view.</summary>
2020 public ContextMenuStrip GridContextMenu => contextMenuStrip ;
2121
22- public ProcessInfoForm ( RemoteProcess process )
22+ public ProcessInfoForm ( IProcessReader process )
2323 {
2424 Contract . Requires ( process != null ) ;
2525
@@ -61,11 +61,6 @@ protected override void OnFormClosed(FormClosedEventArgs e)
6161
6262 private async void ProcessInfoForm_Load ( object sender , EventArgs e )
6363 {
64- if ( ! process . IsValid )
65- {
66- return ;
67- }
68-
6964 var sectionsTable = new DataTable ( ) ;
7065 sectionsTable . Columns . Add ( "address" , typeof ( string ) ) ;
7166 sectionsTable . Columns . Add ( "size" , typeof ( string ) ) ;
@@ -146,11 +141,8 @@ private void createClassAtAddressToolStripMenuItem_Click(object sender, EventArg
146141
147142 private void dumpToolStripMenuItem_Click ( object sender , EventArgs e )
148143 {
149- bool isModule ;
150- string fileName ;
151- var initialDirectory = string . Empty ;
152- IntPtr address ;
153- int size ;
144+ Func < SaveFileDialog > createDialogFn ;
145+ Action < Dumper , Stream > dumpFn ;
154146
155147 if ( GetToolStripSourceControl ( sender ) == modulesDataGridView )
156148 {
@@ -160,11 +152,18 @@ private void dumpToolStripMenuItem_Click(object sender, EventArgs e)
160152 return ;
161153 }
162154
163- isModule = true ;
164- fileName = $ "{ Path . GetFileNameWithoutExtension ( module . Name ) } _Dumped{ Path . GetExtension ( module . Name ) } ";
165- initialDirectory = Path . GetDirectoryName ( module . Path ) ;
166- address = module . Start ;
167- size = module . Size . ToInt32 ( ) ;
155+ createDialogFn = ( ) => new SaveFileDialog
156+ {
157+ FileName = $ "{ Path . GetFileNameWithoutExtension ( module . Name ) } _Dumped{ Path . GetExtension ( module . Name ) } ",
158+ InitialDirectory = Path . GetDirectoryName ( module . Path )
159+ } ;
160+
161+ dumpFn = ( d , s ) =>
162+ {
163+ d . DumpModule ( module , s ) ;
164+
165+ MessageBox . Show ( "Module successfully dumped." , Constants . ApplicationName , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
166+ } ;
168167 }
169168 else
170169 {
@@ -174,43 +173,41 @@ private void dumpToolStripMenuItem_Click(object sender, EventArgs e)
174173 return ;
175174 }
176175
177- isModule = false ;
178- fileName = $ "Section_{ section . Start . ToString ( "X" ) } _{ section . End . ToString ( "X" ) } .dat";
179- address = section . Start ;
180- size = section . Size . ToInt32 ( ) ;
176+ createDialogFn = ( ) => new SaveFileDialog
177+ {
178+ FileName = $ "Section_{ section . Start . ToString ( "X" ) } _{ section . End . ToString ( "X" ) } .dat"
179+ } ;
180+
181+ dumpFn = ( d , s ) =>
182+ {
183+ d . DumpSection ( section , s ) ;
184+
185+ MessageBox . Show ( "Section successfully dumped." , Constants . ApplicationName , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
186+ } ;
181187 }
182188
183- using ( var sfd = new SaveFileDialog ( ) )
189+ using ( var sfd = createDialogFn ( ) )
184190 {
185- sfd . FileName = fileName ;
186191 sfd . Filter = "All|*.*" ;
187- sfd . InitialDirectory = initialDirectory ;
188192
189- if ( sfd . ShowDialog ( ) = = DialogResult . OK )
193+ if ( sfd . ShowDialog ( ) ! = DialogResult . OK )
190194 {
191- var dumper = new Dumper ( process ) ;
195+ return ;
196+ }
192197
193- try
194- {
195- using ( var stream = sfd . OpenFile ( ) )
196- {
197- if ( isModule )
198- {
199- dumper . DumpModule ( address , size , stream ) ;
200- }
201- else
202- {
203- dumper . DumpSection ( address , size , stream ) ;
204- }
205-
206- MessageBox . Show ( "Module successfully dumped." , Constants . ApplicationName , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
207- }
208- }
209- catch ( Exception ex )
198+ var dumper = new Dumper ( process ) ;
199+
200+ try
201+ {
202+ using ( var stream = sfd . OpenFile ( ) )
210203 {
211- Program . ShowException ( ex ) ;
204+ dumpFn ( dumper , stream ) ;
212205 }
213206 }
207+ catch ( Exception ex )
208+ {
209+ Program . ShowException ( ex ) ;
210+ }
214211 }
215212 }
216213
@@ -235,7 +232,7 @@ private IntPtr GetSelectedAddress(object sender)
235232 }
236233 }
237234
238- private Control GetToolStripSourceControl ( object sender )
235+ private static Control GetToolStripSourceControl ( object sender )
239236 {
240237 return ( ( sender as ToolStripMenuItem ) ? . GetCurrentParent ( ) as ContextMenuStrip ) ? . SourceControl ;
241238 }
0 commit comments