You will be Redirected to my new website (Under-Development) I'll update it soon to include old posts Here ..
Sunday, January 23, 2011
Thursday, May 21, 2009
m3u PlayList Copier
I Made this program as i really very lazy :D
Actually it is really hard to catch each song from a different partition and Folder to copy it .
So with this Program You can Select items from any playlist and copy them to any Destination Like My Mobile Or mp3 any device
as You can See it can read English and Non-English (like Arabic) song names from one playlist
Download Here
Note : You will Find the .exe file with another file with .cs extension (if you are NOT programer ,just Delete it) it just contain the Program Source Code
Code :
First we have a public array ,So we can use it in all program controls (to be accessed by open dialog and save dialog)
public string[] Final_Adresses=new string[0];
After That We need to treat with the playlist language if it is non-English language
//Read all bytes to an array To convert it to unicode ,so a Non-english characters will be shown properly
byte[] all_bytes = File.ReadAllBytes(openFileDialog1.FileName);
// Perform the conversion from one encoding to the other.
byte[] new_encoded = Encoding.Convert(Encoding.Default, Encoding.Unicode, all_bytes);
//Convert the new encoded array (of bytes) to a normal string
string uniString = Encoding.Unicode.GetString(new_encoded);
//Split the string to array by lines
string[] final_encoded = uniString.Split('\n');
in the code above we read all playlist file as a byte array then we converted it to Unicode(utf-8) then we converted the Unicode byte array to a string the we spitted the new string to get the original names with a unicode characters so it will NOT be displayed like (??????) or any undefined characters
Then We will Make an array with the address ,but the problem with the m3u playlists is ,it depend on the song location from the playlist itself so if the song
For Example :
if the Songs in the Same Directory , the playlist will Contain the song name only
if the Songs in Subdirectory in the same directory of the playlist ,it will contain the “ directory name\song name “
else it will contain the full address
So we will make an array to contain all addresses in unified format
//String Array To Save all addresses as it vary with Some conditions in M3U PlayList
//We Will use an Array List as it doesn't has an initial length
System.Collections.ArrayList address = new System.Collections.ArrayList();
//Read the M3u File from this array
for (int x = 2; x < final_encoded.Length; x = x + 2)
{
//the song is in other Directory
if (final_encoded[x].Contains(":"))
{
//removing the last character "\r" to get the exact path
address.Add(final_encoded[x].Remove(final_encoded[x].Length - 1));
checkedListBox1.Items.Add(final_encoded[x].Remove(0, final_encoded[x].LastIndexOf('\\') + 1));
}
//if (final_encoded[x].Contains("\\"))
else
{
string tmpadrs = openFileDialog1.FileName;
tmpadrs = tmpadrs.Remove(tmpadrs.LastIndexOf('\\'));
tmpadrs = tmpadrs + "\\" + final_encoded[x];
address.Add(tmpadrs);
checkedListBox1.Items.Add(final_encoded[x].Remove(0, final_encoded[x].LastIndexOf('\\') + 1));
}
}
//Converting the array list to a normal array of strings to the public array
Final_Adresses = (string[])address.ToArray(typeof(string));
Above we make some checks to determine if the song in the same directory of the playlist or in another place
Save or Copy Button
we check if the user checked any songs or NOT then we copy them
if (checkedListBox1.CheckedItems.Count > 0)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
ProgressBar1.Maximum = checkedListBox1.CheckedItems.Count;
for (int i = 0; i < Final_Adresses.Length; i++)
{
if (checkedListBox1.GetItemCheckState(i) == CheckState.Checked)
{
File.Copy(Final_Adresses[i], folderBrowserDialog1.SelectedPath + Final_Adresses[i].Remove(0, Final_Adresses[i].LastIndexOf('\\')));
ProgressBar1.PerformStep();
}
}
MessageBox.Show("Copying Selected Items Completed");
}
}
else
{
MessageBox.Show("No Items Selected To Copy");
}
Download the full code file from the link above or if you are lazy like me :D its Here again
You can Deal with any playlist with the same way science other formats is easier to get the song path as they store the full path with NO conditions for its location
التسميات: Simple Programs
Thursday, May 7, 2009
Bilingual Dictionary – CSV Based Dictionary
Note : All Programs on this site Need .Net Framework 2
I made this program as usual for my own needs for a simple dictionary
This Dictionary is very Simple to use and based on a CSV File
How To Use :
- Just open the Notepad.exe and write the words and meaning in this way … (word,meaning) without the brackets with no spaces in words
- Save the file as Unicode (preferred for Non-English languages)
- Open the dictionary and set the path in the first text box , then choose to search (by word OR by meaning) from the two radio buttons
- It is very recommended to save the words and the meanings with lower case format
Code :
As usual in my simple programs i depend on one or more simple code piece
The main idea here is to save the data as records in the file and the values is separated with commas
Then we (split) the records by the separator and return the values to an array , so we can search
Please read the code and comment for any not cleared part
You can download the program and the source from Here
التسميات: Simple Programs
Thursday, March 26, 2009
PPTX extractor -- pptx to text
Note : All Programs on this site Need .Net Framework 2
Many times we need to extract all text from power point files and add some basic decoration to it . unfortunately the power point just support exporting the outlines only as .rtf NOT all text In other situations we need to extract media files from the presentation , to add some modifications or reuse them I made this simple pptx file extractor (pptx 2 text) ,which extracts text and ( media if exists ! ) from power point 2007 files to *.rtf( rich text format ) text file and allow you to add some basic decoration to the extracted text such as changing the fonts and colors . I provide the explained source code , So you can easily edit it to fit your needs For visual basic users , You can use this converter http://www.developerfusion.com/tools/convert/csharp-to-vb/ or you can write your wishes and I'll try to edit it for you This is version 1 , may be there some other versions and may be not . So Keep track with the blog to know the latest news and programs Note : in case of tables the extracted text will be as this photoالتسميات: Simple Programs
PPTX extractor code
Summary :
The main idea behind our simple program is that the ( pptx ) extension is simply a zipped file ( you can try to unzip it )
In this zipped file there are a lot of XML files , So we need to find the files that contain the text
Note : You can use SharpZipLibrary to unzip files in your project
From http://icsharpcode.net/OpenSource/SharpZipLib
I found the text is in %file%ppt/slides
The XML tag that contain the text data is " a:t " so we need an XML reader to read this data and write it to our rich text box
Then I added some dialoges to be a real program
The Main code :
1: try
2: { 3: //instance for fastzip library
4: FastZip unzip = new FastZip();
5: //unzip to the temp folder in windows
6: string tmploc = Path.GetTempPath();
7: //we just need to unzip this folder NOT all files for slow computers
8: unzip.ExtractZip(openFileDialog1.FileName, tmploc, "ppt/slides");
9: //for loop to extract data from XML files
10: //the ( Directory.GetFiles(tmploc + "ppt\\slides", "*.xml") ) is used to stop the loop
11: //after reaching the last XML File
12: for (int i = 1; i <= Directory.GetFiles(tmploc + "ppt\\slides", "*.xml").Length; i++)
13: { 14: //creating a reader to read XML data from this location which change after every loop
15: //to get the next file name
16: XmlReader rdr = XmlReader.Create(tmploc + "ppt\\slides\\slide" + i + ".xml");
17: while (rdr.Read())
18: { 19: //specify that we need to read a node of type "element"
20: if (rdr.NodeType == XmlNodeType.Element)
21: { 22: //if the reader reaches an element with the tag ( a:t )
23: if (rdr.Name == "a:t")
24: { 25: //will read the element contents as string and add it to rich text box
26: textdata.Text += rdr.ReadElementContentAsString() + "\n";
27: } 28: } 29: } 30: //close the reader as the file location will change the next loop
31: rdr.Close(); 32: } 33: } 34: //catch any error and show a message to the user instead of terminating the program
35: catch (Exception err) { MessageBox.Show(err.Message); }
التسميات: Simple Programs