[C#] IMVU Data Converter - Source

DataMine
by DataMine · 16 posts
10 years ago in .Net (C#, VB, etc)
Posted 10 years ago · Author
Ťṓƴᶎ wrote:
On line 243 use Path.GetFileExtenstion in System.IO


It's Path.GetExtension(); but yeah, good idea. It's cleaner that way.
Code
string filetype = Path.GetExtension(filenames[0]);

if (filetype == ".txt" || filetype == ".py" || filetype == ".xml" || filetype == ".js" || filetype == ".bat" || filetype == ".html")
{
  Inbx.LoadFile(filenames[0], RichTextBoxStreamType.PlainText);
}
else if (filetype == ".rtf")
{
  Inbx.LoadFile(filenames[0], RichTextBoxStreamType.RichText);
}
else
{
  MessageBox.Show("Sorry, I cannot support this file type");
}
Posted 10 years ago
You can also do

Code
var filenames = (string[])e.Data.GetData(DataFormats.FileDrop);

                if (filenames != null)
                    foreach (var i in filenames)
                    {
                        string filetype = Path.GetExtension(i);

                        if (filetype.ToLower().Equals(".txt") || filetype.ToLower().Equals(".py")||
                            filetype.ToLower().Equals(".xml") || filetype.ToLower().Equals(".js") ||
                            filetype.ToLower().Equals(".bat"))
                        {
                            Inbx.LoadFile(i, RichTextBoxStreamType.PlainText);
                        }
                        else if (filetype.ToLower().Equals(".rtf"))
                        {
                            Inbx.LoadFile(i, RichTextBoxStreamType.RichText);
                        }
                        else
                        {
                            MessageBox.Show("Sorry, I cannot support this file type");
                        }
                    }


or
Code
 var filenames = (string[])e.Data.GetData(DataFormats.FileDrop);

                if (filenames != null)
                    foreach (var i in filenames)
                    {
                        string filetype = Path.GetExtension(i);

                        if (filetype != null)
                            switch(filetype.ToLower())
                            {
                                case ".txt":
                                case ".py":
                                case ".xml":
                                case ".js":
                                case ".bat":
                                    Inbx.LoadFile(i, RichTextBoxStreamType.PlainText);
                                    break;
                                case ".rtf":
                                    Inbx.LoadFile(i, RichTextBoxStreamType.RichText);
                                    break;
                                default:
                                    MessageBox.Show("Sorry, I cannot support this file type");
                                    break;
                            }
                    }
                       


//Note: Dont use break using continue since its a loop
Posted 10 years ago · Author
I am always a big fan of learning different ways to write the same logic structure, especially if it improves the code either visually or productively. So I have to ask, what are the benefits of re writing it these ways? Any speed increases or error preventive measures for example?
Posted 10 years ago
The for-each loop just lets you loop the multi files if someone drags say 5 instead of 1, also the switch loop helps prevent ram over head as it's disposing it's self every time unlike a if statement,

In the if statement I use tolower cause sometimes it is like TxT so it cannot equal txt adding tolower lets you make sure it equals always

There is the linq method you can do but not even I would use it as it's not memory efficiency
Posted 10 years ago · Author
Ťṓƴᶎ wrote:
The for-each loop just lets you loop the multi files if someone drags say 5 instead of 1, also the switch loop helps prevent ram over head as it's disposing it's self every time unlike a if statement,

In the if statement I use tolower cause sometimes it is like TxT so it cannot equal txt adding tolower lets you make sure it equals always

There is the linq method you can do but not even I would use it as it's not memory efficiency


That's very true, I didn't even think of those people who insist on using mixed case letters in the extensions. I wonder if there is a way to combine the functionality of the for-each loop with the memory overhead prevention of the switch. That is something I'd be very interested in.

Edit:
Code
string filetype = Path.GetExtension(filenames[0]).ToLower();
Will solve 1 problem.
Posted 10 years ago
You can force GC in the loop using GC.Collect();

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT
Select a forum Protection     Help & Support     Introductions     Mafia News     IMVU News General Discussion     IMVU Lounge        IMVU Series / Roleplaying        Social Games     Mafia Market     Mafia Tools        Premium IMVU Tools        Off Topic Tools     Off Topic     Contests Creator Corner     Graphics Design        Photoshop        GIMP     Basic Creator Help     Catalog And Product Showcase     3D Meshing        3Ds Max        Sketchup        Blender Gangsters with Connections     White Hat Activities        Google Hacking        Trackers Programming Corner     Coding        Python        .Net (C#, VB, etc)        Flash        JAVA        Autoit        Batch        HTML & CSS        Javascript        PHP        Other        IMVU Homepage Codes           General           About me Panel           Messages Panel           Special Someone Panel           Visitors Panel           New Products Panel           Rankings Panel           Wishlist Panel           My Badges Panel           Outfits Panel           Url Panel           Groups Panel           Slideshow Panel           My Room Panel           Sandbox panel           Layouts     Help & Requests Free Credits     Approved Methods     Submit Methods Free Money     Approved Methods     Submit Methods Adult Corner     Get Mafia AP Here     AP Lounge        AP Social Games        Casual Dating Tips     IMVU Slave Market & Escorts