Author: aolk Date: 2007-01-25 08:15:08 -0500 (Thu, 25 Jan 2007) New Revision: 71665
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.X11Internal/NOTES
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Mime.cs
Log:
2006-01-25 Alexander Olk <[EMAIL PROTECTED]>
* FileDialog.cs:
- Move to using System.ComponentModel.EventHandlerList
- Replace Refresh with Invalidate
- Clear the mime filecache on closing
- Some other memory reducing work. After beeing closed FD now uses
only about 300 KB for the fdo mime stuff plus the memory of the
cached icons.
* Mime.cs: Changed coding style and removed unnecessary commented
code. Some more memory memory reducing work.
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-01-25 12:46:00 UTC (rev 71664)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
2007-01-25 13:15:08 UTC (rev 71665)
@@ -1,3 +1,15 @@
+2006-01-25 Alexander Olk <[EMAIL PROTECTED]>
+
+ * FileDialog.cs:
+ - Move to using System.ComponentModel.EventHandlerList
+ - Replace Refresh with Invalidate
+ - Clear the mime filecache on closing
+ - Some other memory reducing work. After beeing closed FD now uses
+ only about 300 KB for the fdo mime stuff plus the memory of the
+ cached icons.
+ * Mime.cs: Changed coding style and removed unnecessary commented
+ code. Some more memory memory reducing work.
+
2007-01-25 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
* ComboBox.cs: Implemented FlatStyle and DropDownHeight, and added
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
2007-01-25 12:46:00 UTC (rev 71664)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/FileDialog.cs
2007-01-25 13:15:08 UTC (rev 71665)
@@ -367,6 +367,11 @@
popupButtonPanel.DirectoryChanged += new EventHandler
(OnDirectoryChangedPopupButtonPanel);
readonlyCheckBox.CheckedChanged += new EventHandler
(OnCheckCheckChanged);
+#if NET_2_0
+ form.FormClosed += new FormClosedEventHandler
(OnFileDialogFormClosed);
+#else
+ form.Closed += new EventHandler (OnClickCancelButton);
+#endif
}
[DefaultValue(true)]
@@ -647,6 +652,8 @@
CancelEventHandler fo = (CancelEventHandler) Events
[EventFileOk];
if (fo != null)
fo (this, e);
+
+ Mime.CleanFileCache ();
}
protected override bool RunDialog (IntPtr hWndOwner)
@@ -1016,6 +1023,13 @@
{
ReadOnlyChecked = readonlyCheckBox.Checked;
}
+
+#if NET_2_0
+ void OnFileDialogFormClosed (object sender, EventArgs e)
+ {
+ OnClickCancelButton (sender, EventArgs.Empty);
+ }
+#endif
private void UpdateFilters ()
{
@@ -1143,7 +1157,7 @@
public Image Image {
set {
image = value;
- Refresh ();
+ Invalidate ();
}
get {
@@ -1154,7 +1168,7 @@
public PopupButtonState ButtonState {
set {
popupButtonState = value;
- Refresh ();
+ Invalidate ();
}
get {
@@ -1217,7 +1231,7 @@
panel.focusButton.ButtonState =
PopupButtonState.Normal;
panel.focusButton = null;
}
- Refresh ();
+ Invalidate ();
base.OnMouseEnter (e);
}
@@ -1225,21 +1239,19 @@
{
if (popupButtonState == PopupButtonState.Up)
popupButtonState =
PopupButtonState.Normal;
- Refresh ();
+ Invalidate ();
base.OnMouseLeave (e);
}
protected override void OnClick (EventArgs e)
{
popupButtonState = PopupButtonState.Down;
- Refresh ();
+ Invalidate ();
base.OnClick (e);
}
}
#endregion
- private EventHandler on_directory_changed;
-
private PopupButton recentlyusedButton;
private PopupButton desktopButton;
private PopupButton personalButton;
@@ -1341,8 +1353,9 @@
currentPath = MWFVFS.MyNetworkPrefix;
}
- if (on_directory_changed != null)
- on_directory_changed (this, EventArgs.Empty);
+ EventHandler eh = (EventHandler)(Events
[PDirectoryChangedEvent]);
+ if (eh != null)
+ eh (this, EventArgs.Empty);
}
public string CurrentFolder {
@@ -1473,9 +1486,11 @@
e.Handled = true;
}
+ static object PDirectoryChangedEvent = new object ();
+
public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
+ add { Events.AddHandler (PDirectoryChangedEvent,
value); }
+ remove { Events.RemoveHandler (PDirectoryChangedEvent,
value); }
}
}
#endregion
@@ -1541,8 +1556,6 @@
private string currentPath;
- private EventHandler on_directory_changed;
-
private Stack folderStack = new Stack();
private static readonly int indent = 6;
@@ -1590,6 +1603,9 @@
myComputerItems.Add (new DirComboBoxItem
(MimeIconEngine.LargeIcons, fsEntry.IconIndex, fsEntry.Name, fsEntry.FullName,
indent * 2));
}
+ al.Clear ();
+ al = null;
+
mainParentDirComboBoxItem = myComputerDirComboboxItem;
ResumeLayout (false);
@@ -1781,13 +1797,16 @@
protected override void OnSelectionChangeCommitted (EventArgs e)
{
- if (on_directory_changed != null)
- on_directory_changed (this, EventArgs.Empty);
+ EventHandler eh = (EventHandler)(Events
[CDirectoryChangedEvent]);
+ if (eh != null)
+ eh (this, EventArgs.Empty);
}
+ static object CDirectoryChangedEvent = new object ();
+
public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
+ add { Events.AddHandler (CDirectoryChangedEvent,
value); }
+ remove { Events.RemoveHandler (CDirectoryChangedEvent,
value); }
}
}
#endregion
@@ -1895,11 +1914,6 @@
private bool showHiddenFiles = false;
- private EventHandler on_selected_file_changed;
- private EventHandler on_selected_files_changed;
- private EventHandler on_directory_changed;
- private EventHandler on_force_dialog_end;
-
private string selectedFilesString;
private int filterIndex = 1;
@@ -2326,6 +2340,12 @@
}
EndUpdate ();
+
+ collection.Clear ();
+ collection = null;
+
+ directoriesArrayList.Clear ();
+ fileArrayList.Clear ();
}
public void AddControlToEnableDisableByDirStack (object control)
@@ -2386,8 +2406,9 @@
if (fsEntry.FileType ==
FSEntry.FSEntryType.File) {
currentFSEntry = fsEntry;
- if (on_selected_file_changed !=
null)
-
on_selected_file_changed (this, EventArgs.Empty);
+ EventHandler eh =
(EventHandler)(Events [MSelectedFileChangedEvent]);
+ if (eh != null)
+ eh (this,
EventArgs.Empty);
}
}
}
@@ -2406,16 +2427,19 @@
ChangeDirectory (null,
fsEntry.FullName);
- if (on_directory_changed != null)
- on_directory_changed (this,
EventArgs.Empty);
+ EventHandler eh = (EventHandler)(Events
[MDirectoryChangedEvent]);
+ if (eh != null)
+ eh (this, EventArgs.Empty);
} else {
currentFSEntry = fsEntry;
- if (on_selected_file_changed != null)
- on_selected_file_changed (this,
EventArgs.Empty);
+ EventHandler eh = (EventHandler)(Events
[MSelectedFileChangedEvent]);
+ if (eh != null)
+ eh (this, EventArgs.Empty);
- if (on_force_dialog_end != null)
- on_force_dialog_end (this,
EventArgs.Empty);
+ eh = (EventHandler)(Events
[MForceDialogEndEvent]);
+ if (eh != null)
+ eh (this, EventArgs.Empty);
return;
}
@@ -2445,8 +2469,9 @@
}
}
- if (on_selected_files_changed != null)
- on_selected_files_changed (this,
EventArgs.Empty);
+ EventHandler eh = (EventHandler)(Events
[MSelectedFilesChangedEvent]);
+ if (eh != null)
+ eh (this, EventArgs.Empty);
}
base.OnSelectedIndexChanged (e);
@@ -2546,24 +2571,29 @@
CreateNewFolder ();
}
+ static object MSelectedFileChangedEvent = new object ();
+ static object MSelectedFilesChangedEvent = new object ();
+ static object MDirectoryChangedEvent = new object ();
+ static object MForceDialogEndEvent = new object ();
+
public event EventHandler SelectedFileChanged {
- add { on_selected_file_changed += value; }
- remove { on_selected_file_changed -= value; }
+ add { Events.AddHandler (MSelectedFileChangedEvent,
value); }
+ remove { Events.RemoveHandler
(MSelectedFileChangedEvent, value); }
}
public event EventHandler SelectedFilesChanged {
- add { on_selected_files_changed += value; }
- remove { on_selected_files_changed -= value; }
+ add { Events.AddHandler (MSelectedFilesChangedEvent,
value); }
+ remove { Events.RemoveHandler
(MSelectedFilesChangedEvent, value); }
}
public event EventHandler DirectoryChanged {
- add { on_directory_changed += value; }
- remove { on_directory_changed -= value; }
+ add { Events.AddHandler (MDirectoryChangedEvent,
value); }
+ remove { Events.RemoveHandler (MDirectoryChangedEvent,
value); }
}
public event EventHandler ForceDialogEnd {
- add { on_force_dialog_end += value; }
- remove { on_force_dialog_end -= value; }
+ add { Events.AddHandler (MForceDialogEndEvent, value); }
+ remove { Events.RemoveHandler (MForceDialogEndEvent,
value); }
}
}
#endregion
@@ -4205,10 +4235,7 @@
internal class MWFConfigInstance
{
Hashtable classes_hashtable = new Hashtable ();
- string path;
static string full_file_name;
- XmlTextReader xtr;
- XmlTextWriter xtw;
static string default_file_name;
readonly string configName = "MWFConfig";
static int platform = (int)
Environment.OSVersion.Platform;
@@ -4242,7 +4269,7 @@
// only for testing
public MWFConfigInstance (string filename)
{
- path = Path.GetDirectoryName (filename);
+ string path = Path.GetDirectoryName (filename);
if (path == null || path == String.Empty) {
path = Environment.GetFolderPath
(Environment.SpecialFolder.Personal);
@@ -4284,9 +4311,9 @@
private void Open (string filename)
{
try {
- xtr = new XmlTextReader (filename);
+ XmlTextReader xtr = new XmlTextReader
(filename);
- ReadConfig ();
+ ReadConfig (xtr);
xtr.Close ();
} catch (Exception) {
@@ -4296,10 +4323,10 @@
public void Flush ()
{
try {
- xtw = new XmlTextWriter
(full_file_name, null);
+ XmlTextWriter xtw = new XmlTextWriter
(full_file_name, null);
xtw.Formatting = Formatting.Indented;
- WriteConfig ();
+ WriteConfig (xtw);
xtw.Close ();
@@ -4338,9 +4365,9 @@
}
}
- private void ReadConfig ()
+ private void ReadConfig (XmlTextReader xtr)
{
- if (!CheckForMWFConfig ())
+ if (!CheckForMWFConfig (xtr))
return;
while (xtr.Read ()) {
@@ -4360,7 +4387,7 @@
}
}
- private bool CheckForMWFConfig ()
+ private bool CheckForMWFConfig (XmlTextReader xtr)
{
if (xtr.Read ()) {
if (xtr.NodeType ==
XmlNodeType.Element) {
@@ -4372,7 +4399,7 @@
return false;
}
- private void WriteConfig ()
+ private void WriteConfig (XmlTextWriter xtw)
{
if (classes_hashtable.Count == 0)
return;
Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Mime.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Mime.cs
2007-01-25 12:46:00 UTC (rev 71664)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Mime.cs
2007-01-25 13:15:08 UTC (rev 71665)
@@ -82,8 +82,6 @@
private static object lock_object = new Object();
-// private int platform = (int) Environment.OSVersion.Platform;
-
private bool is_zero_file = false;
private int bytes_read = 0;
@@ -101,7 +99,7 @@
public static ArrayList Matches80Plus;
public static ArrayList MatchesBelow80;
- private Mime( )
+ private Mime ()
{
#if NET_2_0
Aliases = new NameValueCollection
(StringComparer.CurrentCultureIgnoreCase);
@@ -126,83 +124,82 @@
int buffer_length = fmcr.Init ();
if (buffer_length != -1) {
- buffer = new byte[ buffer_length ];
+ buffer = new byte [buffer_length];
mime_available = true;
}
}
- public static bool MimeAvailable
- {
+ public static bool MimeAvailable {
get {
return Instance.mime_available;
}
}
- public static string GetMimeTypeForFile( string filename )
+ public static string GetMimeTypeForFile (string filename)
{
- lock ( lock_object )
- {
- Instance.StartByFileName( filename );
+ lock (lock_object) {
+ Instance.StartByFileName (filename);
}
return Instance.global_result;
}
// not tested
- public static string GetMimeTypeForData( byte[] data )
+ public static string GetMimeTypeForData (byte[] data)
{
- lock ( lock_object )
- {
- Instance.StartDataLookup( data );
+ lock (lock_object) {
+ Instance.StartDataLookup (data);
}
return Instance.global_result;
}
- public static string GetMimeTypeForString( string input )
+ public static string GetMimeTypeForString (string input)
{
- lock ( lock_object )
- {
- Instance.StartStringLookup( input );
+ lock (lock_object) {
+ Instance.StartStringLookup (input);
}
return Instance.global_result;
}
- public static string GetMimeAlias( string mimetype )
+ public static string GetMimeAlias (string mimetype)
{
- return Aliases[ mimetype ];
+ return Aliases [mimetype];
}
- public static string GetMimeSubClass( string mimetype )
+ public static string GetMimeSubClass (string mimetype)
{
- return SubClasses[ mimetype ];
+ return SubClasses [mimetype];
}
- private void StartByFileName( string filename )
+ public static void CleanFileCache ()
{
- if ( mime_file_cache.ContainsKey( filename ) )
- {
- global_result = mime_file_cache[ filename ];
+ lock (lock_object) {
+ Instance.mime_file_cache.Clear ();
+ }
+ }
+
+ private void StartByFileName (string filename)
+ {
+ if (mime_file_cache.ContainsKey (filename)) {
+ global_result = mime_file_cache [filename];
return;
}
current_file_name = filename;
is_zero_file = false;
-// if ( !CheckForInode( ) )
-// {
global_result = octet_stream;
- GoByFileName( );
-// }
+ GoByFileName ();
- mime_file_cache.Add( current_file_name, global_result );
+ mime_file_cache.Add (current_file_name, global_result);
if (mime_file_cache.Count > mime_file_cache_max_size) {
IEnumerator enumerator =
mime_file_cache.GetEnumerator ();
- int counter = mime_file_cache_max_size - 1000;
+ int counter = mime_file_cache_max_size - 500;
while (enumerator.MoveNext ()) {
mime_file_cache.Remove
(enumerator.Current.ToString ());
@@ -214,120 +211,50 @@
}
}
- private void StartDataLookup( byte[] data )
+ private void StartDataLookup (byte[] data)
{
global_result = octet_stream;
- System.Array.Clear( buffer, 0, buffer.Length );
+ System.Array.Clear (buffer, 0, buffer.Length);
- if ( data.Length > buffer.Length )
- {
- System.Array.Copy( data, buffer, buffer.Length
);
+ if (data.Length > buffer.Length) {
+ System.Array.Copy (data, buffer, buffer.Length);
+ } else {
+ System.Array.Copy (data, buffer, data.Length);
}
- else
- {
- System.Array.Copy( data, buffer, data.Length );
- }
- if ( CheckMatch80Plus( ) )
+ if (CheckMatch80Plus ())
return;
- if ( CheckMatchBelow80( ) )
+ if (CheckMatchBelow80 ())
return;
- CheckForBinaryOrText( );
+ CheckForBinaryOrText ();
}
- private void StartStringLookup( string input )
+ private void StartStringLookup (string input)
{
global_result = text_plain;
search_string = input;
- if ( CheckForContentTypeString( ) )
+ if (CheckForContentTypeString ())
return;
}
-// private bool CheckForInode( )
-// {
-// if ( ( platform == 4 ) || ( platform == 128 ) )
-// {
-//#if __MonoCS__
-// try
-// {
-// // *nix platform
-// Mono.Unix.UnixFileInfo ufi = new
Mono.Unix.UnixFileInfo( current_file_name );
-//
-// if ( ufi.IsFile )
-// {
-// return false;
-// }
-// else
-// if ( ufi.IsDirectory )
-// {
-// global_result =
"inode/directory";
-// return true;
-// }
-// else
-// if ( ufi.IsBlockDevice )
-// {
-// global_result =
"inode/blockdevice";
-// return true;
-// }
-// else
-// if ( ufi.IsSocket )
-// {
-// global_result = "inode/socket";
-// return true;
-// }
-// else
-// if ( ufi.IsSymbolicLink )
-// {
-// global_result = "inode/symlink";
-// return true;
-// }
-// else
-// if ( ufi.IsCharacterDevice )
-// {
-// global_result =
"inode/chardevice";
-// return true;
-// }
-// else
-// if ( ufi.IsFIFO )
-// {
-// global_result = "inode/fifo";
-// return true;
-// }
-// } catch( Exception e )
-// {
-// return false;
-// }
-//#endif
-// }
-// else
-// {
-// // TODO!!!!
-// // windows platform
-// }
-//
-// return false;
-// }
-
- private void GoByFileName( )
+ private void GoByFileName ()
{
// check if we can open the file
- if ( !OpenFile( ) )
- {
+ if (!OpenFile ()) {
// couldn't open the file, check globals only
- CheckGlobalPatterns( );
+ CheckGlobalPatterns ();
return;
}
- if ( !is_zero_file )
- {
+ if (!is_zero_file) {
// check for matches with a priority >= 80
- if ( CheckMatch80Plus( ) )
+ if (CheckMatch80Plus ())
return;
}
@@ -335,27 +262,25 @@
// this should be done for zero size files also,
// for example zero size file trash.ccc~ should return
// application/x-trash instead of application/x-zerosize
- if ( CheckGlobalPatterns( ) )
+ if (CheckGlobalPatterns ())
return;
// if file size is zero, no other checks are needed
- if ( is_zero_file )
+ if (is_zero_file)
return;
// ok, still nothing matches then try matches with a
priority < 80
- if ( CheckMatchBelow80( ) )
+ if (CheckMatchBelow80 ())
return;
// wow, still nothing... return
application/octet-stream for binary data, or text/plain for textual data
- CheckForBinaryOrText( );
+ CheckForBinaryOrText ();
}
- private bool CheckMatch80Plus( )
+ private bool CheckMatch80Plus ()
{
- foreach ( Match match in Matches80Plus )
- {
- if ( TestMatch( match ) )
- {
+ foreach (Match match in Matches80Plus) {
+ if (TestMatch (match)) {
global_result = match.MimeType;
return true;
@@ -366,7 +291,7 @@
}
// this little helper method gives us a real speed improvement
- private bool FastEndsWidth(string input, string value)
+ private bool FastEndsWidth (string input, string value)
{
if (value.Length > input.Length)
return false;
@@ -374,7 +299,7 @@
int z = input.Length - 1;
for (int i = value.Length - 1; i > -1; i--) {
- if (value[i] != input[z])
+ if (value [i] != input [z])
return false;
z--;
@@ -383,46 +308,46 @@
return true;
}
- private bool FastStartsWith(string input, string value)
+ private bool FastStartsWith (string input, string value)
{
if (value.Length > input.Length)
return false;
for (int i = 0; i < value.Length; i++)
- if (value[i] != input[i])
+ if (value [i] != input [i])
return false;
return true;
}
// start always with index = 0
- private int FastIndexOf(string input, char value)
+ private int FastIndexOf (string input, char value)
{
if (input.Length == 0)
return -1;
for (int i = 0; i < input.Length; i++)
- if (input[i] == value)
+ if (input [i] == value)
return i;
return -1;
}
- private int FastIndexOf(string input, string value)
+ private int FastIndexOf (string input, string value)
{
if (input.Length == 0)
return -1;
for (int i = 0; i < input.Length - value.Length; i++) {
- if (input[i] == value[0]) {
+ if (input [i] == value [0]) {
int counter = 0;
for (int z = 1; z < value.Length; z++) {
- if (input[i+z] != value[z])
+ if (input [i + z] != value [z])
break;
counter++;
}
- if (counter == value.Length -1) {
+ if (counter == value.Length - 1) {
return i;
}
}
@@ -431,115 +356,93 @@
return -1;
}
- private void CheckGlobalResult( )
+ private void CheckGlobalResult ()
{
- int comma_index = FastIndexOf(global_result, ',');
+ int comma_index = FastIndexOf (global_result, ',');
- if ( comma_index != -1 )
- {
- global_result = global_result.Substring( 0,
comma_index );
+ if (comma_index != -1) {
+ global_result = global_result.Substring (0,
comma_index);
}
}
- private bool CheckGlobalPatterns( )
+ private bool CheckGlobalPatterns ()
{
- string filename = Path.GetFileName( current_file_name );
+ string filename = Path.GetFileName (current_file_name);
// first check for literals
- for ( int i = 0; i < GlobalLiterals.Count; i++ )
- {
- string key = GlobalLiterals.GetKey(i);
+ for (int i = 0; i < GlobalLiterals.Count; i++) {
+ string key = GlobalLiterals.GetKey (i);
// no regex char
- if ( FastIndexOf(key, '[' ) == -1 )
- {
- if (FastIndexOf(filename, key) != -1)
- {
- global_result =
GlobalLiterals[i];
- CheckGlobalResult( );
+ if (FastIndexOf (key, '[') == -1) {
+ if (FastIndexOf (filename, key) != -1) {
+ global_result = GlobalLiterals
[i];
+ CheckGlobalResult ();
return true;
}
- }
- else // regex it ;)
- {
- if ( Regex.IsMatch( filename, key ) )
- {
- global_result = GlobalLiterals[
i ];
- CheckGlobalResult( );
+ } else {
+ if (Regex.IsMatch (filename, key)) {
+ global_result = GlobalLiterals
[i];
+ CheckGlobalResult ();
return true;
}
}
}
- if ( FastIndexOf(filename, '.' ) != -1 )
- {
+ if (FastIndexOf (filename, '.') != -1) {
// check for double extension like .tar.gz
- for ( int i = 0; i < GlobalPatternsLong.Count;
i++ )
- {
- string key = GlobalPatternsLong.GetKey(
i );
+ for (int i = 0; i < GlobalPatternsLong.Count;
i++) {
+ string key = GlobalPatternsLong.GetKey
(i);
- if (FastEndsWidth (filename, key))
- {
- global_result =
GlobalPatternsLong[ i ];
- CheckGlobalResult( );
+ if (FastEndsWidth (filename, key)) {
+ global_result =
GlobalPatternsLong [i];
+ CheckGlobalResult ();
return true;
- }
- else
- {
- if ( FastEndsWidth
(filename.ToLower( ), key ) )
- {
- global_result =
GlobalPatternsLong[ i ];
- CheckGlobalResult( );
+ } else {
+ if (FastEndsWidth
(filename.ToLower (), key)) {
+ global_result =
GlobalPatternsLong [i];
+ CheckGlobalResult ();
return true;
}
}
}
// check normal extensions...
- string extension = Path.GetExtension(
current_file_name );
+ string extension = Path.GetExtension
(current_file_name);
- if ( extension.Length != 0 )
- {
- string global_result_tmp =
GlobalPatternsShort[ extension ];
+ if (extension.Length != 0) {
+ string global_result_tmp =
GlobalPatternsShort [extension];
- if ( global_result_tmp != null )
- {
+ if (global_result_tmp != null) {
global_result =
global_result_tmp;
- CheckGlobalResult( );
+ CheckGlobalResult ();
return true;
}
- global_result_tmp =
GlobalPatternsShort[ extension.ToLower( ) ];
+ global_result_tmp = GlobalPatternsShort
[extension.ToLower ()];
- if ( global_result_tmp != null )
- {
+ if (global_result_tmp != null) {
global_result =
global_result_tmp;
- CheckGlobalResult( );
+ CheckGlobalResult ();
return true;
}
}
}
// finally check if a prefix or suffix matches
- for ( int i = 0; i < GlobalSufPref.Count; i++ )
- {
- string key = GlobalSufPref.GetKey( i );
+ for (int i = 0; i < GlobalSufPref.Count; i++) {
+ string key = GlobalSufPref.GetKey (i);
- if ( key[0] == '*' )
- {
- if (FastEndsWidth(filename,
key.Replace( "*", String.Empty )))
- {
- global_result = GlobalSufPref[
i ];
- CheckGlobalResult( );
+ if (key [0] == '*') {
+ if (FastEndsWidth (filename,
key.Replace ("*", String.Empty))) {
+ global_result = GlobalSufPref
[i];
+ CheckGlobalResult ();
return true;
}
- }
- else
- {
- if ( FastStartsWith(filename,
key.Replace( "*", String.Empty ) ) )
- {
- global_result = GlobalSufPref[
i ];
- CheckGlobalResult( );
+ } else {
+ if (FastStartsWith (filename,
key.Replace ("*", String.Empty))) {
+ global_result = GlobalSufPref
[i];
+ CheckGlobalResult ();
return true;
}
}
@@ -548,12 +451,10 @@
return false;
}
- private bool CheckMatchBelow80( )
+ private bool CheckMatchBelow80 ()
{
- foreach ( Match match in MatchesBelow80 )
- {
- if ( TestMatch( match ) )
- {
+ foreach (Match match in MatchesBelow80) {
+ if (TestMatch (match)) {
global_result = match.MimeType;
return true;
@@ -563,16 +464,14 @@
return false;
}
- private void CheckForBinaryOrText( )
+ private void CheckForBinaryOrText ()
{
// check the first 32 bytes
- for ( int i = 0; i < 32; i++ )
- {
- char c = System.Convert.ToChar( buffer[ i ] );
+ for (int i = 0; i < 32; i++) {
+ char c = System.Convert.ToChar (buffer [i]);
- if ( c != '\t' && c != '\n' && c != '\r' && c
!= 12 && c < 32 )
- {
+ if (c != '\t' && c != '\n' && c != '\r' && c
!= 12 && c < 32) {
global_result = octet_stream;
return;
}
@@ -590,7 +489,7 @@
return false;
}
- private bool TestMatchlet( Matchlet matchlet )
+ private bool TestMatchlet (Matchlet matchlet)
{
// using a simple brute force search algorithm
// compare each (masked) value from the buffer with the
(masked) value from the matchlet
@@ -599,72 +498,54 @@
if (matchlet.Offset + matchlet.ByteValue.Length >
bytes_read)
return false;
- for ( int offset_counter = 0; offset_counter <
matchlet.OffsetLength; offset_counter++ )
- {
+ for (int offset_counter = 0; offset_counter <
matchlet.OffsetLength; offset_counter++) {
if (matchlet.Offset + offset_counter +
matchlet.ByteValue.Length > bytes_read)
return false;
- if ( matchlet.Mask == null )
- {
- if ( buffer[ matchlet.Offset +
offset_counter ] == matchlet.ByteValue[ 0 ] )
- {
- if ( matchlet.ByteValue.Length
== 1 )
- {
- if (
matchlet.Matchlets.Count > 0 )
- {
- foreach (
Matchlet sub_matchlet in matchlet.Matchlets )
- {
- if (
TestMatchlet( sub_matchlet ) )
+ if (matchlet.Mask == null) {
+ if (buffer [matchlet.Offset +
offset_counter] == matchlet.ByteValue [0]) {
+ if (matchlet.ByteValue.Length
== 1) {
+ if
(matchlet.Matchlets.Count > 0) {
+ foreach
(Matchlet sub_matchlet in matchlet.Matchlets) {
+ if
(TestMatchlet (sub_matchlet))
return true;
}
- }
- else
+ } else
return true;
}
int minus = 0;
// check if the last matchlet
byte value is the same as the byte value in the buffer...
if (matchlet.ByteValue.Length >
2) {
- if (buffer[
matchlet.Offset + offset_counter + matchlet.ByteValue.Length - 1 ] !=
matchlet.ByteValue[ matchlet.ByteValue.Length - 1 ])
+ if (buffer
[matchlet.Offset + offset_counter + matchlet.ByteValue.Length - 1] !=
matchlet.ByteValue [matchlet.ByteValue.Length - 1])
return false;
minus = 1;
}
- for ( int i = 1; i <
matchlet.ByteValue.Length - minus; i++ )
- {
- if ( buffer[
matchlet.Offset + offset_counter + i ] != matchlet.ByteValue[ i ] )
+ for (int i = 1; i <
matchlet.ByteValue.Length - minus; i++) {
+ if (buffer
[matchlet.Offset + offset_counter + i] != matchlet.ByteValue [i])
return false;
}
- if ( matchlet.Matchlets.Count >
0 )
- {
- foreach ( Matchlet
sub_matchlets in matchlet.Matchlets )
- {
- if (
TestMatchlet( sub_matchlets ) )
+ if (matchlet.Matchlets.Count >
0) {
+ foreach (Matchlet
sub_matchlets in matchlet.Matchlets) {
+ if
(TestMatchlet (sub_matchlets))
return
true;
}
- }
- else
+ } else
return true;
}
- }
- else // with mask ( it's the same as above,
only AND the byte with the corresponding mask byte
- {
- if ( ( buffer[ matchlet.Offset +
offset_counter ] & matchlet.Mask[ 0 ] ) ==
- ( matchlet.ByteValue[ 0 ] &
matchlet.Mask[ 0 ] ) )
- {
- if ( matchlet.ByteValue.Length
== 1 )
- {
- if (
matchlet.Matchlets.Count > 0 )
- {
- foreach (
Matchlet sub_matchlets in matchlet.Matchlets )
- {
- if (
TestMatchlet( sub_matchlets ) )
+ } else {
+ if ((buffer [matchlet.Offset +
offset_counter] & matchlet.Mask [0]) ==
+ (matchlet.ByteValue [0] &
matchlet.Mask [0])) {
+ if (matchlet.ByteValue.Length
== 1) {
+ if
(matchlet.Matchlets.Count > 0) {
+ foreach
(Matchlet sub_matchlets in matchlet.Matchlets) {
+ if
(TestMatchlet (sub_matchlets))
return true;
}
- }
- else
+ } else
return true;
}
@@ -672,29 +553,25 @@
// check if the last matchlet
byte value is the same as the byte value in the buffer...
if (matchlet.ByteValue.Length >
2) {
- if ((buffer[
matchlet.Offset + offset_counter + matchlet.ByteValue.Length - 1 ] &
matchlet.Mask[ matchlet.ByteValue.Length - 1 ])
- !=
(matchlet.ByteValue[ matchlet.ByteValue.Length - 1 ] & matchlet.Mask[
matchlet.ByteValue.Length - 1 ]))
+ if ((buffer
[matchlet.Offset + offset_counter + matchlet.ByteValue.Length - 1] &
matchlet.Mask [matchlet.ByteValue.Length - 1])
+ !=
(matchlet.ByteValue [matchlet.ByteValue.Length - 1] & matchlet.Mask
[matchlet.ByteValue.Length - 1]))
return false;
minus = 1;
}
- for ( int i = 1; i <
matchlet.ByteValue.Length - minus; i++ )
- {
- if ( ( buffer[
matchlet.Offset + offset_counter + i ] & matchlet.Mask[ i ] ) !=
- (
matchlet.ByteValue[ i ] & matchlet.Mask[ i ] ) )
+ for (int i = 1; i <
matchlet.ByteValue.Length - minus; i++) {
+ if ((buffer
[matchlet.Offset + offset_counter + i] & matchlet.Mask [i]) !=
+ (matchlet.ByteValue
[i] & matchlet.Mask [i]))
return false;
}
- if ( matchlet.Matchlets.Count >
0 )
- {
- foreach ( Matchlet
sub_matchlets in matchlet.Matchlets )
- {
- if (
TestMatchlet( sub_matchlets ) )
+ if (matchlet.Matchlets.Count >
0) {
+ foreach (Matchlet
sub_matchlets in matchlet.Matchlets) {
+ if
(TestMatchlet (sub_matchlets))
return
true;
}
- }
- else
+ } else
return true;
}
}
@@ -703,82 +580,72 @@
return false;
}
- private bool OpenFile( )
+ private bool OpenFile ()
{
- try
- {
- file_stream = new FileStream(
current_file_name, FileMode.Open, FileAccess.Read ); // FileShare ??? use
BinaryReader ???
+ try {
+ file_stream = new FileStream
(current_file_name, FileMode.Open, FileAccess.Read); // FileShare ??? use
BinaryReader ???
- if ( file_stream.Length == 0 )
- {
+ if (file_stream.Length == 0) {
global_result = zero_file;
is_zero_file = true;
- }
- else
- {
- bytes_read = file_stream.Read( buffer,
0, buffer.Length );
+ } else {
+ bytes_read = file_stream.Read (buffer,
0, buffer.Length);
// do not clear the whole buffer
everytime; clear only what's needed
if (bytes_read < buffer.Length) {
- System.Array.Clear( buffer,
bytes_read, buffer.Length - bytes_read );
+ System.Array.Clear (buffer,
bytes_read, buffer.Length - bytes_read);
}
}
- file_stream.Close( );
- }
- catch (Exception)
- {
+ file_stream.Close ();
+ } catch (Exception) {
return false;
}
return true;
}
- private bool CheckForContentTypeString( )
+ private bool CheckForContentTypeString ()
{
- int index = search_string.IndexOf( "Content-type:" );
+ int index = search_string.IndexOf ("Content-type:");
- if ( index != -1 )
- {
+ if (index != -1) {
index += 13; // Length of string "Content-type:"
global_result = String.Empty;
- while ( search_string[ index ] != ';' )
- {
- global_result += search_string[ index++
];
+ while (search_string [index] != ';') {
+ global_result += search_string
[index++];
}
- global_result.Trim( );
+ global_result.Trim ();
return true;
}
// convert string to byte array
- byte[] string_byte = ( new ASCIIEncoding( ) ).GetBytes(
search_string );
+ byte[] string_byte = (new ASCIIEncoding ()).GetBytes
(search_string);
- System.Array.Clear( buffer, 0, buffer.Length );
+ System.Array.Clear (buffer, 0, buffer.Length);
- if ( string_byte.Length > buffer.Length )
- {
- System.Array.Copy( string_byte, buffer,
buffer.Length );
+ if (string_byte.Length > buffer.Length) {
+ System.Array.Copy (string_byte, buffer,
buffer.Length);
+ } else {
+ System.Array.Copy (string_byte, buffer,
string_byte.Length);
}
- else
- {
- System.Array.Copy( string_byte, buffer,
string_byte.Length );
- }
- if ( CheckMatch80Plus( ) )
+ if (CheckMatch80Plus ())
return true;
- if ( CheckMatchBelow80( ) )
+ if (CheckMatchBelow80 ())
return true;
return false;
}
}
- internal class FDOMimeConfigReader {
+ internal class FDOMimeConfigReader
+ {
bool fdo_mime_available = false;
StringCollection shared_mime_paths = new StringCollection ();
BinaryReader br;
@@ -862,15 +729,17 @@
// indent
char c;
if (br.PeekChar () != '>') {
- string indent_string =
String.Empty;
+ StringBuilder
indent_string = new StringBuilder ();
+ //string indent_string
= String.Empty;
while (true) {
if (br.PeekChar
() == '>')
break;
c = br.ReadChar
();
- indent_string
+= c;
+ //indent_string
+= c;
+
indent_string.Append (c);
}
- indent =
Convert.ToInt32 (indent_string);
+ indent =
Convert.ToInt32 (indent_string.ToString ());
}
int offset = 0;
@@ -1030,10 +899,10 @@
if (split2.Length > 2) {
// more than
one dot
-
Mime.GlobalPatternsLong.Add (split [1].Remove(0, 1), split [0]);
+
Mime.GlobalPatternsLong.Add (split [1].Remove (0, 1), split [0]);
} else {
// normal
-
Mime.GlobalPatternsShort.Add (split [1].Remove(0, 1), split [0]);
+
Mime.GlobalPatternsShort.Add (split [1].Remove (0, 1), split [0]);
}
}
}
@@ -1098,7 +967,7 @@
private int ReadValue ()
{
- string result_string = String.Empty;
+ StringBuilder result_string = new StringBuilder ();
int result = 0;
char c;
@@ -1107,10 +976,10 @@
break;
c = br.ReadChar ();
- result_string += c;
+ result_string.Append (c);
}
- result = Convert.ToInt32 (result_string);
+ result = Convert.ToInt32 (result_string.ToString ());
return result;
}
@@ -1118,27 +987,27 @@
private string ReadPriorityAndMimeType (ref int priority)
{
if (br.ReadChar () == '[') {
- string priority_string = String.Empty;
+ StringBuilder priority_string = new
StringBuilder ();
while (true) {
char c = br.ReadChar ();
if (c == ':')
break;
- priority_string += c;
+ priority_string.Append (c);
}
- priority = System.Convert.ToInt32
(priority_string);
+ priority = System.Convert.ToInt32
(priority_string.ToString ());
- string mime_type_result = String.Empty;
+ StringBuilder mime_type_result = new
StringBuilder ();
while (true) {
char c = br.ReadChar ();
if (c == ']')
break;
- mime_type_result += c;
+ mime_type_result.Append (c);
}
if (br.ReadChar () == '\n')
- return mime_type_result;
+ return mime_type_result.ToString ();
}
return null;
}
@@ -1160,7 +1029,8 @@
}
}
- internal class Match {
+ internal class Match
+ {
string mimeType;
int priority;
ArrayList matchlets = new ArrayList();
@@ -1192,7 +1062,8 @@
}
}
- internal class Matchlet {
+ internal class Matchlet
+ {
byte[] byteValue;
byte[] mask = null;
Modified:
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.X11Internal/NOTES
===================================================================
---
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.X11Internal/NOTES
2007-01-25 12:46:00 UTC (rev 71664)
+++
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms.X11Internal/NOTES
2007-01-25 13:15:08 UTC (rev 71665)
@@ -21,9 +21,8 @@
CheckedListBox: nothing done.
DataGridView*: nothing done.
-FileDialog: nothing done.
GridColumnStylesCollection: nothing done, no Component inheritance
GridTableStylesCollection: nothing done, no Component inheritance
MenuItem: what do we do about CloneMenu? we can't have assignment of events
like that (look for the #if notyet)
MonthCalendar: nothing done.
-Panel: nothing done. see whether the events should be "new" or now..
\ No newline at end of file
+Panel: nothing done. see whether the events should be "new" or now..
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
