Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dialogboxes_openfilebox.cs

(view source code of dialogboxes_openfilebox.cs as plain text)

  1. namespace RobvanderWoude
  2. {
  3. 	[System.Runtime.InteropServices.Guid( "766B494F-6F7D-41A6-A72B-0597D07D685E" )]
  4. 	public interface OpenFileBox_Interface
  5. 	{
  6. 		[System.Runtime.InteropServices.DispId( 1 )]
  7. 		void CheckUpdate( );
  8.  
  9. 		[System.Runtime.InteropServices.DispId( 2 )]
  10. 		string Credits( );
  11.  
  12. 		[System.Runtime.InteropServices.DispId( 3 )]
  13. 		string Help( int html = 0 );
  14.  
  15. 		[System.Runtime.InteropServices.DispId( 4 )]
  16. 		string ListProperties( );
  17.  
  18. 		[System.Runtime.InteropServices.DispId( 5 )]
  19. 		string SampleCode( );
  20.  
  21. 		[System.Runtime.InteropServices.DispId( 6 )]
  22. 		void Show( );
  23. 	}
  24.  
  25.  
  26. 	[System.Runtime.InteropServices.Guid( "383FD006-91A0-40CF-A42D-82FAC95BA4E5" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )]
  27. 	public interface OpenFileBox_Events
  28. 	{
  29. 	}
  30.  
  31.  
  32. 	[System.Runtime.InteropServices.Guid( "2DA001A3-8C65-4AAF-8EB6-B29C11C31EC7" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( OpenFileBox_Events ) )]
  33. 	public class OpenFileBox : OpenFileBox_Interface
  34. 	{
  35. 		#region Default Values
  36.  
  37. 		static string defaultdescription = ( _multiselect ? "Select one or more files" : "Select a file" );
  38. 		const string defaultfilter = "All files (*.*)|*.*";
  39. 		static readonly string defaultstartfolder = System.IO.Directory.GetCurrentDirectory( );
  40. 		static readonly string defaulttitle = string.Format( "{0},  Version {1}", Global.Common.ProgramInfo.FileName, Global.Common.ProgramInfo.FileVersion );
  41.  
  42. 		#endregion Default Values
  43.  
  44.  
  45. 		#region Methods
  46.  
  47. 		public void CheckUpdate( )
  48. 		{
  49. 			Global.Common.ProgramInfo.CheckUpdate( );
  50. 		}
  51.  
  52.  
  53. 		public string Credits( )
  54. 		{
  55. 			return Global.Common.Credits( );
  56. 		}
  57.  
  58.  
  59. 		public string Help( int html = 0 )
  60. 		{
  61. 			int col1width = 0;
  62. 			int col2width = 0;
  63. 			int col3width = 0;
  64. 			int col4width = 0;
  65. 			int col5width = 0;
  66. 			string help = string.Empty;
  67. 			string linetemplate = string.Empty;
  68. 			string separatorline = string.Empty;
  69.  
  70. 			if ( html == 1 )
  71. 			{
  72. 				help += "<h1>Help for OpenFileBox class</h1>\n\n";
  73. 				help += "<p>Present an Open File dialog, and return the selected file path</p>\n\n";
  74. 				help += "<h2>COM ProgID: RobvanderWoude.OpenFileBox</h2>\n\n";
  75. 			}
  76. 			else
  77. 			{
  78. 				help += "Help for OpenFileBox class\n";
  79. 				help += new string( '\u2500', help.Length ) + "\n\n";
  80. 				help += "Present an Open File dialog, and return the selected file path\n\n\n";
  81. 				help += "COM ProgID: RobvanderWoude.OpenFileBox\n\n\n";
  82. 			}
  83.  
  84.  
  85. 			#region Properties
  86.  
  87. 			if ( html == 1 )
  88. 			{
  89. 				separatorline = string.Empty;
  90. 				linetemplate = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n\t<td>{3}</td>\n\t<td>{4}</td>\n</tr>\n";
  91.  
  92. 				help += "<table>\n";
  93. 				help += "<tr>\n";
  94. 				help += "\t<th colspan=\"5\">Properties (Note that all properties are string or integer, no booleans, objects or arrays)</th>\n";
  95. 				help += "</tr>\n";
  96.  
  97. 				help += "<tr>\n";
  98. 				help += "\t<th>Property Name</th>\n";
  99. 				help += "\t<th>Description</th>\n";
  100. 				help += "\t<th>Mandatory</th>\n";
  101. 				help += "\t<th>Read-Only</th>\n";
  102. 				help += "\t<th>Default (Allowed) Values</th>\n";
  103. 				help += "</tr>\n";
  104. 			}
  105. 			else
  106. 			{
  107. 				col1width = 16;
  108. 				col2width = 50;
  109. 				col3width = 9;
  110. 				col4width = 9;
  111. 				col5width = 44;
  112.  
  113. 				separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u253C" + new string( '\u2500', 2 + col4width ) + "\u253C" + new string( '\u2500', 2 + col5width ) + "\u2524\n";
  114. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502 {3,-" + col4width.ToString( ) + "} \u2502 {4,-" + col5width.ToString( ) + "} \u2502\n";
  115.  
  116. 				help += "\u250C" + new string( '\u2500', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2510\n";
  117. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  118. 				help += string.Format( "\u2502 {0,-" + ( 12 + col1width + col2width + col3width + col4width + col5width ).ToString( ) + "} \u2502\n", "Properties        (Note that all properties are string or integer, no booleans, objects or arrays)" );
  119. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  120. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2564" + new string( '\u2550', 2 + col4width ) + "\u2564" + new string( '\u2550', 2 + col5width ) + "\u2561\n";
  121. 				help += string.Format( linetemplate, "Property Name", "Description", "Mandatory", "Read-Only", "Default (Allowed) Values" );
  122. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u256A" + new string( '\u2550', 2 + col4width ) + "\u256A" + new string( '\u2550', 2 + col5width ) + "\u2561\n";
  123. 			}
  124.  
  125. 			help += HelpTableRow( linetemplate, "addallfiles", "Add \"All files (*.*)\" to filter  (0=false; 1=true)", "no", "no", "1", html );
  126. 			help += separatorline;
  127.  
  128. 			help += HelpTableRow( linetemplate, "addextension", "Add extension if user forgot it  (0=false; 1=true)", "no", "no", "1", html );
  129. 			help += separatorline;
  130.  
  131. 			help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html );
  132. 			help += separatorline;
  133.  
  134. 			help += HelpTableRow( linetemplate, "defaultextension", "Default extension to be added", "no", "no", "", html );
  135. 			help += separatorline;
  136.  
  137. 			help += HelpTableRow( linetemplate, "errors", Global.Common.Help.errors, "N/A", "YES", "", html );
  138. 			help += separatorline;
  139.  
  140. 			help += HelpTableRow( linetemplate, "filter", "File filter", "no", "no", defaultfilter, html );
  141. 			help += separatorline;
  142.  
  143. 			help += HelpTableRow( linetemplate, "multidotted", "Allow multiple extensions        (0=false; 1=true)", "no", "no", "1", html );
  144. 			help += separatorline;
  145.  
  146. 			help += HelpTableRow( linetemplate, "multiselect", "Allow selecting multiple files   (0=false; 1=true)", "no", "no", "0", html );
  147. 			help += separatorline;
  148.  
  149. 			help += HelpTableRow( linetemplate, "readonlychecked", "Checkbox read-only is checked    (0=false; 1=true)", "no", "no", "0", html );
  150. 			help += separatorline;
  151.  
  152. 			help += HelpTableRow( linetemplate, "selectedfile", "The path of the selected file(s)", "N/A", "YES", "", html );
  153. 			help += separatorline;
  154.  
  155. 			help += HelpTableRow( linetemplate, "showreadonly", "Show checkbox to open read-only  (0=false; 1=true)", "no", "no", "0", html );
  156. 			help += separatorline;
  157.  
  158. 			help += HelpTableRow( linetemplate, "startfolder", "The initial folder for the dialog", "no", "no", "", html );
  159. 			help += separatorline;
  160.  
  161. 			help += HelpTableRow( linetemplate, "title", Global.Common.Help.title, "no", "no", defaulttitle, html );
  162.  
  163. 			if ( html == 1 )
  164. 			{
  165. 				help += "</table>\n\n\n";
  166. 			}
  167. 			else
  168. 			{
  169. 				help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2534" + new string( '\u2500', 2 + col4width ) + "\u2534" + new string( '\u2500', 2 + col5width ) + "\u2518\n\n\n";
  170. 			}
  171.  
  172. 			#endregion Properties
  173.  
  174.  
  175. 			#region Methods
  176.  
  177. 			if ( html == 1 )
  178. 			{
  179. 				separatorline = string.Empty;
  180. 				linetemplate = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n</tr>\n";
  181.  
  182. 				help += "<table>\n";
  183. 				help += "<tr>\n";
  184. 				help += "\t<th colspan=\"3\">Methods</th>\n";
  185. 				help += "</tr>\n";
  186.  
  187. 				help += "<tr>\n";
  188. 				help += "\t<th>Method Name</th>\n";
  189. 				help += "\t<th>Description</th>\n";
  190. 				help += "\t<th>Requirements</th>\n";
  191. 				help += "</tr>\n";
  192. 			}
  193. 			else
  194. 			{
  195. 				col1width = 18;
  196. 				col2width = 74;
  197. 				col3width = 42;
  198.  
  199. 				separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u2524\n";
  200. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502\n";
  201.  
  202. 				help += "\u250C" + new string( '\u2500', 8 + col1width + col2width + col3width ) + "\u2510\n";
  203. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  204. 				help += string.Format( "\u2502 {0,-" + ( 6 + col1width + col2width + col3width ).ToString( ) + "} \u2502\n", "Methods" );
  205. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  206. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  207. 				help += string.Format( linetemplate, "Method Name", "Description", "Requirements" );
  208. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  209. 			}
  210.  
  211. 			help += HelpTableRow( linetemplate, "CheckUpdate", Global.Common.Help._checkupdate, "", html );
  212. 			help += separatorline;
  213.  
  214. 			help += HelpTableRow( linetemplate, "Credits", Global.Common.Help._credits, "", html );
  215. 			help += separatorline;
  216.  
  217. 			help += HelpTableRow( linetemplate, "Help", Global.Common.Help._help, "", html );
  218. 			help += separatorline;
  219.  
  220. 			help += HelpTableRow( linetemplate, "ListProperties", Global.Common.Help._listproperties, "", html );
  221. 			help += separatorline;
  222.  
  223. 			help += HelpTableRow( linetemplate, "SampleCode", Global.Common.Help._samplecode, "", html );
  224. 			help += separatorline;
  225.  
  226. 			help += HelpTableRow( linetemplate, "Show", "Presents an Open File dialog based on the current property values, and if \"OK\"is clicked, saves the selected file path in the \"selectedfile\" property (if \"Cancel\" is clicked, \"selectedfile\" will be empty).", "", html );
  227.  
  228. 			if ( html == 1 )
  229. 			{
  230. 				help += "</table>\n\n\n";
  231. 			}
  232. 			else
  233. 			{
  234. 				help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2518\n\n\n";
  235. 			}
  236.  
  237. 			#endregion Methods
  238.  
  239.  
  240. 			#region Notes
  241.  
  242. 			if ( html == 1 )
  243. 			{
  244. 				help += "<table>\n<tr>\n\t<th>";
  245. 			}
  246.  
  247. 			help += "Notes:";
  248.  
  249. 			if ( html == 1 )
  250. 			{
  251. 				help += "</th>\n\t<td>";
  252. 			}
  253. 			else
  254. 			{
  255. 				help += "\n\t";
  256. 			}
  257.  
  258. 			help += "Though the name may suggest otherwise, this dialog does NOT actually open the selected file, it merely returns the selected file's path.";
  259.  
  260. 			if ( html == 1 )
  261. 			{
  262. 				help += "<br />\n";
  263. 			}
  264. 			else
  265. 			{
  266. 				help += "\n\t";
  267. 			}
  268.  
  269. 			help += "A similar warning goes for the read-only checkbox: it doesn't actually DO anything, but you can use it to allow the user a choice for the";
  270.  
  271. 			if ( html == 1 )
  272. 			{
  273. 				help += " ";
  274. 			}
  275. 			else
  276. 			{
  277. 				help += "\n\t";
  278. 			}
  279.  
  280. 			help += "actions based on this dialog's result.";
  281.  
  282. 			if ( html == 1 )
  283. 			{
  284. 				help += "</td>\n</tr>\n</table>";
  285. 			}
  286.  
  287. 			help += "\n\n\n";
  288.  
  289. 			#endregion Notes
  290.  
  291.  
  292. 			#region Example
  293.  
  294. 			if ( html == 1 )
  295. 			{
  296. 				help += "<h2>VBScript usage example:</h2>\n\n<pre>";
  297. 			}
  298. 			else
  299. 			{
  300. 				help += "VBScript usage example:\n";
  301. 				help += new string( '\u2500', 23 ) + "\n\n";
  302. 			}
  303.  
  304. 			help += SampleCode( );
  305.  
  306. 			if ( html == 1 )
  307. 			{
  308. 				help += "</pre>";
  309. 			}
  310.  
  311. 			help += "\n\n";
  312.  
  313. 			#endregion Example
  314.  
  315.  
  316. 			help = help.Replace( "\n", System.Environment.NewLine );
  317. 			return help;
  318. 		}
  319.  
  320.  
  321. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, int html )
  322. 		{
  323. 			if ( html == 1 )
  324. 			{
  325. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text );
  326. 			}
  327. 			else
  328. 			{
  329. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, "", "" );
  330. 			}
  331. 		}
  332.  
  333.  
  334. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, string col4text, string col5text, int html )
  335. 		{
  336. 			if ( html == 1 )
  337. 			{
  338. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text, col4text, col5text );
  339. 			}
  340. 			else
  341. 			{
  342. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, col4text, col5text );
  343. 			}
  344. 		}
  345.  
  346.  
  347. 		public string ListProperties( )
  348. 		{
  349. 			return Global.Common.Lists.Properties( this );
  350. 		}
  351.  
  352.  
  353. 		public string SampleCode( )
  354. 		{
  355. 			string code = "Set objOpenFileBox = CreateObject( \"RobvanderWoude.OpenFileBox\" )\n\n";
  356. 			code += "With objOpenFileBox\n";
  357. 			code += "\t.startfolder = \"D:\\\"\n";
  358. 			code += "\t.Show\n";
  359. 			code += "\tWScript.Echo \"Selected file: \" & .selectedfile\n";
  360. 			code += "\tWScript.Echo\n";
  361. 			code += "\tWScript.Echo .ListProperties( )\n";
  362. 			code += "End With\n\n";
  363. 			code += "Set objOpenFileBox = Nothing";
  364. 			return code;
  365. 		}
  366.  
  367.  
  368. 		[System.STAThread]
  369. 		public void Show( )
  370. 		{
  371. 			#region Apply Settings
  372.  
  373. 			string ext = System.Text.RegularExpressions.Regex.Match( filter, @"(\.[^.]+)$", System.Text.RegularExpressions.RegexOptions.IgnoreCase ).Groups[0].ToString( );
  374. 			if ( string.IsNullOrWhiteSpace( ext ) )
  375. 			{
  376. 				_errors.Add( Global.Common.TimeStamp( ) + "Invalid filetype specification" );
  377. 			}
  378. 			// If only "*.ext" is specified, use "ext files (*.ext)|*.ext" instead
  379. 			if ( System.Text.RegularExpressions.Regex.IsMatch( filter, @"^\*\.(\*|\w+)$" ) )
  380. 			{
  381. 				if ( ext == ".*" )
  382. 				{
  383. 					filter = string.Format( "All files (*.{0})|*.{0}", ext );
  384. 				}
  385. 				else
  386. 				{
  387. 					filter = string.Format( "{0} files (*.{0})|*.{0}", ext );
  388. 				}
  389. 			}
  390. 			// Use "All files" filter if not specified
  391. 			if ( string.IsNullOrWhiteSpace( filter ) )
  392. 			{
  393. 				filter = "All files (*.*)|*.*";
  394. 			}
  395.  
  396. 			#endregion Apply Settings
  397.  
  398.  
  399. 			try
  400. 			{
  401. 				using ( System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog( ) )
  402. 				{
  403. 					dialog.AutoUpgradeEnabled = true;
  404. 					dialog.AddExtension = _addextension;
  405. 					dialog.CheckFileExists = true;
  406. 					dialog.CheckPathExists = true;
  407. 					dialog.DefaultExt = _defaultextension;
  408. 					dialog.Filter = filter;
  409. 					dialog.FilterIndex = 1;
  410. 					dialog.InitialDirectory = startfolder;
  411. 					dialog.Multiselect = _multiselect;
  412. 					dialog.ReadOnlyChecked = _readonlychecked;
  413. 					dialog.RestoreDirectory = true;
  414. 					dialog.ShowReadOnly = _showreadonly;
  415. 					dialog.SupportMultiDottedExtensions = _multidotted;
  416. 					dialog.Title = title;
  417. 					dialog.ValidateNames = true;
  418. 					if ( dialog.ShowDialog( ) == System.Windows.Forms.DialogResult.OK )
  419. 					{
  420. 						_selectedfile = dialog.FileName;
  421. 					}
  422. 					else
  423. 					{
  424. 						_selectedfile = string.Empty;
  425. 					}
  426. 				}
  427. 			}
  428. 			catch ( System.Exception e )
  429. 			{
  430. 				_errors.Add( Global.Common.TimeStamp( ) + "Error while trying to show Open File dialog: " + e.Message );
  431. 			}
  432. 		}
  433.  
  434. 		#endregion Methods
  435.  
  436.  
  437. 		#region Properties
  438.  
  439. 		private bool _addallfiles = true;
  440. 		[System.Runtime.InteropServices.ComVisible( true )]
  441. 		public int addallfiles
  442. 		{
  443. 			get
  444. 			{
  445. 				return ( _addallfiles ? 1 : 0 );
  446. 			}
  447. 			set
  448. 			{
  449. 				_addallfiles = ( value == 1 );
  450. 			}
  451. 		}
  452.  
  453.  
  454. 		private bool _addextension = false;
  455. 		[System.Runtime.InteropServices.ComVisible( true )]
  456. 		public int addextension
  457. 		{
  458. 			get
  459. 			{
  460. 				return ( _addextension ? 1 : 0 );
  461. 			}
  462. 			set
  463. 			{
  464. 				_addextension = ( value == 1 );
  465. 			}
  466. 		}
  467.  
  468.  
  469. 		private System.Collections.Generic.List<string> _debuginfo = new System.Collections.Generic.List<string>( );
  470. 		[System.Runtime.InteropServices.ComVisible( true )]
  471. 		public string debuginfo
  472. 		{
  473. 			get
  474. 			{
  475. 				return string.Join( "\n", _debuginfo.ToArray( ) );
  476. 			}
  477. 		}
  478.  
  479.  
  480. 		private string _defaultextension = string.Empty;
  481. 		[System.Runtime.InteropServices.ComVisible( true )]
  482. 		public string defaultextension
  483. 		{
  484. 			get
  485. 			{
  486. 				return _defaultextension;
  487. 			}
  488. 			set
  489. 			{
  490. 				if ( value.StartsWith( "." ) )
  491. 				{
  492. 					_defaultextension = value.Trim( );
  493. 				}
  494. 				else
  495. 				{
  496. 					_debuginfo.Add( timestamp + "Invalid default extension, using \".*\" instead" );
  497. 					_defaultextension = ".*";
  498. 				}
  499. 			}
  500. 		}
  501.  
  502.  
  503. 		private string _description = defaultdescription;
  504. 		[System.Runtime.InteropServices.ComVisible( true )]
  505. 		public string description
  506. 		{
  507. 			get
  508. 			{
  509. 				return _description;
  510. 			}
  511. 			set
  512. 			{
  513. 				_description = value.Trim( );
  514. 			}
  515. 		}
  516.  
  517.  
  518. 		private System.Collections.Generic.List<string> _errors = new System.Collections.Generic.List<string>( );
  519. 		[System.Runtime.InteropServices.ComVisible( true )]
  520. 		public string errors
  521. 		{
  522. 			get
  523. 			{
  524. 				return string.Join( "\n", _errors.ToArray( ) );
  525. 			}
  526. 		}
  527.  
  528.  
  529. 		private string _filter = defaultfilter;
  530. 		[System.Runtime.InteropServices.ComVisible( true )]
  531. 		public string filter
  532. 		{
  533. 			get
  534. 			{
  535. 				return _filter;
  536. 			}
  537. 			set
  538. 			{
  539. 				// If only "*.ext" is specified, use "ext files (*.ext)|*.ext" instead
  540. 				if ( System.Text.RegularExpressions.Regex.IsMatch( value, @"^\*\.(\*|\w+)$" ) )
  541. 				{
  542. 					string ext = value.Substring( 2 ).ToLower( );
  543. 					if ( ext == ".*" )
  544. 					{
  545. 						_filter = string.Format( "All files (*.{0})|*.{0}", ext );
  546. 					}
  547. 					else
  548. 					{
  549. 						_filter = string.Format( "{0} files (*.{0})|*.{0}", ext );
  550. 					}
  551. 				}
  552. 				else
  553. 				{
  554. 					_filter = value;
  555. 				}
  556. 				if ( _addallfiles )
  557. 				{
  558. 					// Append "All files" filter if not specified
  559. 					if ( !System.Text.RegularExpressions.Regex.IsMatch( filter, @"All files\s+\(\*\.\*\)\|\*\.\*", System.Text.RegularExpressions.RegexOptions.IgnoreCase ) )
  560. 					{
  561. 						if ( string.IsNullOrWhiteSpace( _filter ) )
  562. 						{
  563. 							_filter = "All files (*.*)|*.*";
  564. 						}
  565. 						else
  566. 						{
  567. 							_filter += "|All files (*.*)|*.*";
  568. 						}
  569. 					}
  570. 				}
  571. 			}
  572. 		}
  573.  
  574.  
  575. 		private bool _multidotted = true;
  576. 		[System.Runtime.InteropServices.ComVisible( true )]
  577. 		public int multidotted
  578. 		{
  579. 			get
  580. 			{
  581. 				return ( _multidotted ? 1 : 0 );
  582. 			}
  583. 			set
  584. 			{
  585. 				_multidotted = ( value == 1 );
  586. 			}
  587. 		}
  588.  
  589.  
  590. 		private static bool _multiselect = false;
  591. 		[System.Runtime.InteropServices.ComVisible( true )]
  592. 		public int multiselect
  593. 		{
  594. 			get
  595. 			{
  596. 				return ( _multiselect ? 1 : 0 );
  597. 			}
  598. 			set
  599. 			{
  600. 				_multiselect = ( value == 1 );
  601. 			}
  602. 		}
  603.  
  604.  
  605. 		private bool _readonlychecked = false;
  606. 		[System.Runtime.InteropServices.ComVisible( true )]
  607. 		public int readonlychecked
  608. 		{
  609. 			get
  610. 			{
  611. 				return ( _readonlychecked ? 1 : 0 );
  612. 			}
  613. 			set
  614. 			{
  615. 				_readonlychecked = ( value == 1 );
  616. 			}
  617. 		}
  618.  
  619.  
  620. 		private string _selectedfile = string.Empty;
  621. 		[System.Runtime.InteropServices.ComVisible( true )]
  622. 		public string selectedfile
  623. 		{
  624. 			get
  625. 			{
  626. 				return _selectedfile;
  627. 			}
  628. 		}
  629.  
  630.  
  631. 		private bool _showreadonly = false;
  632. 		[System.Runtime.InteropServices.ComVisible( true )]
  633. 		public int showreadonly
  634. 		{
  635. 			get
  636. 			{
  637. 				return ( _showreadonly ? 1 : 0 );
  638. 			}
  639. 			set
  640. 			{
  641. 				_showreadonly = ( value == 1 );
  642. 			}
  643. 		}
  644.  
  645.  
  646. 		private string _startfolder = defaultstartfolder;
  647. 		[System.Runtime.InteropServices.ComVisible( true )]
  648. 		public string startfolder
  649. 		{
  650. 			get
  651. 			{
  652. 				return _startfolder;
  653. 			}
  654. 			set
  655. 			{
  656. 				if ( System.IO.Directory.Exists( value ) )
  657. 				{
  658. 					try
  659. 					{
  660. 						_startfolder = System.IO.Path.GetFullPath( value );
  661. 					}
  662. 					catch ( System.ArgumentException )
  663. 					{
  664. 						try
  665. 						{
  666. 							// Assuming the error is caused by a trailing backslash in doublequotes
  667. 							_startfolder = System.IO.Path.GetFullPath( value.Substring( 0, startfolder.IndexOf( '"' ) ) + "." );
  668. 						}
  669. 						catch ( System.Exception )
  670. 						{
  671. 							_debuginfo.Add( timestamp + "Invalid start directory, using current directory instead" );
  672. 							_startfolder = ".";
  673. 						}
  674. 					}
  675. 				}
  676. 				else
  677. 				{
  678. 					_debuginfo.Add( timestamp + "Invalid start directory, using current directory instead" );
  679. 					_startfolder = ".";
  680. 				}
  681. 				_selectedfile = _startfolder;
  682. 			}
  683. 		}
  684.  
  685.  
  686. 		public static string timestamp => Global.Common.TimeStamp( );
  687.  
  688.  
  689. 		private string _title = defaulttitle;
  690. 		[System.Runtime.InteropServices.ComVisible( true )]
  691. 		public string title
  692. 		{
  693. 			get
  694. 			{
  695. 				return _title;
  696. 			}
  697. 			set
  698. 			{
  699. 				_title = value.Trim( );
  700. 			}
  701. 		}
  702.  
  703.  
  704. 		[System.Runtime.InteropServices.ComVisible( true )]
  705. 		public string Version
  706. 		{
  707. 			get
  708. 			{
  709. 				return Global.Common.ProgramInfo.FileVersion;
  710. 			}
  711. 		}
  712.  
  713. 		#endregion Properties
  714. 	}
  715. }

page last modified: 2024-04-16; loaded in 0.0218 seconds