Pages

Advertisement

Sunday, July 22, 2007

Got Bored with the same look of Indiagames player skin ! A simple trick to make ur own indiagames player skin ..

Well i can say that this is very simple to do and there is nothing much to do in this ..

so lets began with photoshop !

1-> open the folder C:\Program Files\Indiagames GoD\Skins\028000 where you will find a folder named pics then select all and drag the images in photoshop .

Step 1(select all files)

Step 2(Click and drag all the images to Photoshop)

2-> Now once you have all the images in the Photoshop its time to Proceed with Editing !

3-> Now U can make any changes in then but remember :

> Don't change the image size

> Don't Change the location of the play button but if you want a different look of the button also then make another button overlapping the button means at the same place of the play button because when you click on button the program takes the click from a particular x and y points so u should remember it while changing to a new play button ..

> In the same way u can change the complete background and the logos according to your choice .

4-> For demo i had change a little to show U how this works .

5->I had only Changed the HUE . You can access it by shortcut Ctrl+U to change only the color of the

image ..

6->>> So wanna like to see demo keep moving ...

Steps 1 & 2 are the same as above steps (drag n drop)

Step3 :Press Ctrl + U . A window will popup like this ..

Step 4 : Now you can set Your own colors according to Your choice ..

Step 5 : Once You had made the desired changes click ok and save it

Step 6 : Now you can gave a new look to one of the image .. In the same way make same changes to all the images Because if You make changes to only one then u will get an un balanced image preview in your skin . And also u can change the center image from the directory C:\Program Files\Indiagames GoD\Skins\028000\html\Promotion.gif in the same way.

Step 7 : That's all u had now created a new look for your Indiagames player . Here is the final Preview of the skin

Step 8 : Post a comment regarding this trick or if You have something More tricky .Click Here to post

Manipulate XML File Data Using C#

Nearly 95 percent of .NET applications use XML for various tasks. A main usage for Web developers is combining XML with HTML to display information on Web pages, which relieves them from having to spend a long time editing the content on their Web pages. A single change to an XML file will be reflected across the entire Web site, thus simplifying the development and also greatly reducing the development time.

With the advent of .NET, programming languages such as C#, Visual Basic .NET, and frameworks such as ASP.NET took advantage of XML's rich features. In fact, the configuration file (web.config), which is used in ASP.NET applications, is completely built upon XML tags.

This article demonstrates how to manipulate an XML file using C#. The manipulation includes displaying, adding, editing, and deleting data from a single XML file using C#. It also shows how to use the Stream class included in the System.IO namespace and various other XML classes included in the System.XML namespace.

Display Contents of XML File

Listing 1 shows a simple XML file for demonstration:

Listing 1
<?xml version="1.0"?>
<Books>
<Book ID="001">
<Author>Mark</Author>
<Publisher>Sams</Publisher>
</Book>

<Book ID="002">
<Author>Joe</Author>
<Publisher>AWL</Publisher>
</Book>
</Books>



To test the above XML file for errors, simply open it with your browser. If it has no errors, the file will be displayed as such.

The next step is to display all the data using a C# console application (see Listing 2).

Listing 2: DisplayCatalog.cs

XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Book");
   Console.WriteLine("Here is the list of catalogs\n\n");
 
   for(int i=0;i<xmlnode.Count;i++)
   {
   XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
 
   //XML Attribute Name and Value returned
   //Example: <Book id = "001">
 
   Console.Write(xmlattrc[0].Name);
   Console.WriteLine(":\t"+xmlattrc[0].Value);
 
   //First Child of the XML file - Catalog.xml - returned
   //Example: <Author>Mark</Author>
 
   Console.Write(xmlnode[i].FirstChild.Name);
   Console.WriteLine(":\t"+xmlnode[i].FirstChild.InnerText);
 
   //Last Child of the XML file - Catalog.xml - returned
   //Example: <Publisher>Sams</Publisher>
 
   Console.Write(xmlnode[i].LastChild.Name);
   Console.WriteLine(":\t"+xmlnode[i].LastChild.InnerText);
   Console.WriteLine();

Listing 2 is just an extract from the DisplayCatalog() method of the C# application. It displays the data from the XML file. It uses the XMLNodeList class to retrieve the relevant XML node and then iterates it with the help of the for loop and the Count property of the class. Inside the loop, it creates an instance of the XMLAttributeCollection class and displays the appropriate values using the properties of the class.


Inside the constructor, the code creates an instance of the FileStream class and sets the required permissions (see Listing 3). It then loads the XML document with the help of the XMLDocument class and loads the required instance of the FileStream class with the Load() method of the XMLDocument class.

Listing 3: DisplayCatalog.cs

FileStream fs = new FileStream(path,FileMode.Open,FileAccess.Read,
FileShare.ReadWrite);
xmldoc = new XmlDocument();
xmldoc.Load(fs);
DisplayCatalog();

You can download the complete source code for all the from the code download section at the end of this article.

The final output looks like the display in Figure 1.


Figure 1: Final Output from Listings 2 and 3

The above walkthrough showed how to display the contents of an XML file using a C# program. The next section demonstrates how to write data directly to the XML file using a C# console application.

Write Data Directly to XML File

Listing 4 appends a new catalog entry to the XML document using the various properties and methods of the XMLDocument class.

Listing 4: AddCatalog.cs

// New XML Element Created
XmlElement newcatalogentry = xmldoc.CreateElement("Book");
 
// New Attribute Created
XmlAttribute newcatalogattr = xmldoc.CreateAttribute("ID");
 
// Value given for the new attribute
newcatalogattr.Value = "005";
 
// Attach the attribute to the XML element
newcatalogentry.SetAttributeNode(newcatalogattr);
 
// First Element - Book - Created
XmlElement firstelement = xmldoc.CreateElement("Book");
 
// Value given for the first element
firstelement.InnerText = "Peter";
 
// Append the newly created element as a child element
newcatalogentry.AppendChild(firstelement);
 
 
// Second Element - Publisher - Created
XmlElement secondelement = xmldoc.CreateElement("Publisher");
 
// Value given for the second element
secondelement.InnerText = "Que Publishing";
 
// Append the newly created element as a child element
newcatalogentry.AppendChild(secondelement);
 
// New XML element inserted into the document
xmldoc.DocumentElement.InsertAfter(newcatalogentry,
                                   xmldoc.DocumentElement.LastChild);
 
// An instance of FileStream class created
// The first parameter is the path to the XML file - Catalog.xml
 
FileStream fsxml = new FileStream(path,FileMode.Truncate,
                                  FileAccess.Write,
                                  FileShare.ReadWrite);
 
// XML Document Saved
xmldoc.Save(fsxml);
 
 

Technorati Tags: ,

Compression Classes Enhance I/O in .NET 2.0

The System.IO.Compression namespace introduces a series of classes that provide compression and decompression capabilities. The classes exhibit similar behaviors and characteristics, but the compression classes operate against streams. To my knowledge, the .NET Framework 2.0 will include two algorithms for compression/decompression: Deflate and GZip.

Sample code to compress a file

The following sample code reads the contents of a file, compresses it, and then writes it to an output file. It should clearly demonstrate how easy it is to add compression capabilities into your applications:

FileStream inputFile = null;
GZipStream compressedZipStream = null;
try
{
   // Open and read the contents of the file
   inputFile = new FileStream("c:\\mylog.txt", FileMode.Open,
                              FileAccess.Read, FileShare.Read);
   byte[] buffer = new byte[inputFile.Length];
   int count = inputFile.Read(buffer, 0, buffer.Length);
   inputFile.Close();
 
   // Compress the file contents by writing them to a memory stream
   MemoryStream memoryBuffer = new MemoryStream();
   compressedZipStream = new GZipStream(memoryBuffer,
   CompressionMode.Compress, true);
   compressedZipStream.Write(buffer, 0, buffer.Length);
   compressedZipStream.Close();
   Console.WriteLine("Original Size: {0}, Compressed Size: {1}",
                     buffer.Length, memoryBuffer.Length);
 
   // Pause so we can see the output
   Console.ReadLine();
}
finally
{
   if (inputFile != null) inputFile.Close();
   if (compressedZipStream!= null) compressedZipStream.Close();
}



I created a file named mylog.txt. I then typed in the well known test phrase "The quick brown fox jumped over the slow lazy dog." into the file about thirty times. I use files for the examples, but you could just as easily use any other sort of stream.


(
Full Size Image)

Figure 1. File Compression

Note: The examples here are all with the GZipStream class, which you could just as easily swap out for the DeflateStream class.

Sample code to decompress a file

The following sample code reads the contents of a file, decompresses it, and then writes it to the console. It relies on the file created in the prior sample:

FileStream inputFile = null;
GZipStream compressedZipStream = null;
 
try
{
   // Determine the uncompressed size of the file;
   // we can't rely on the compressed size because
   // it's not the true size
   inputFile = new FileStream("c:\\mylogcompressed.txt",
                              FileMode.Open, FileAccess.Read,
                              FileShare.Read);
   compressedZipStream = new GZipStream(inputFile,
                                        CompressionMode.Decompress);
   int offset = 0;
   int totalBytes = 0;
   byte[] smallBuffer = new byte[100];
   while (true)
   {
      int bytesRead = compressedZipStream.Read(smallBuffer, 0, 100);
      if (bytesRead == 0)
      {
         break;
      }
      offset += bytesRead;
      totalBytes += bytesRead;
   }
   compressedZipStream.Close();
 
   // Open and read the contents of the file now that
   // we know the uncompressed size
   inputFile = new FileStream("c:\\mylogcompressed.txt",
                              FileMode.Open, FileAccess.Read,
                              FileShare.Read);
 
   // Decompress the file contents
   compressedZipStream = new GZipStream(inputFile,
                                        CompressionMode.Decompress);
   byte[] buffer = new byte[totalBytes];
   compressedZipStream.Read(buffer, 0, totalBytes);
 
   // Display the decompression information
   Console.WriteLine(System.Text.Encoding.UTF7.GetString(buffer));
   Console.WriteLine("Compressed Size: {0}, Decompressed Size: {1}",
                     inputFile.Length, buffer.Length);
   compressedZipStream.Close();
 
   // Pause so we can see the output
   Console.ReadLine();
}
finally
{
   if (inputFile != null) inputFile.Close();
   if (compressedZipStream != null) compressedZipStream.Close();
}
 
Decompression is more complex because of the way the Read method works. Because the file is compressed, there is no way to know how much data to read. You can approach this in a number of ways. For this sample code, I added code up front to determine the size of the file first. This results in the file being read twice, which is not ideal.



(
Full Size Image)

Figure 2. File Decompression

Compression and Decompression Classes

You have received a sneak preview of the compression and decompression classes that are coming in the .NET Framework 2.0, due out later in the year. The simplicity of the examples demonstrates how easy it will be for you to use the functionality within your applications.

 

Read and Write Open XML Files in MS Office 2007

With Office 2007, Microsoft decided to change default application formats from the old, proprietary, closed formats (DOC, XLS, and PPT) to new, open and, standardized XML formats (DOCX, XLSX, and PPTX). New formats share some similarities with old Office XML formats (WordML, SpreadsheetML) and some similarities with competing OpenOffice.org OpenDocument formats, but there are many differences. Because new formats will be the default in Office 2007, and Microsoft Office is the most predominant office suite, these formats are destined to be popular and you will probably have to deal with them sooner or later.

This article will explain the basics of the Open XML file format and specifically the XLSX format, the new format for Excel 2007. Presented is a demo application that reads and writes tabular data to and from XLSX files. The application is written in C# using Visual Studio 2005. The XLSX files it creates can be opened using Excel 2007.

The Microsoft Open XML Format

Every Open XML file is essentially a ZIP archive containing many other files. Office-specific data is stored in multiple XML files inside that archive. This is in direct contrast with old WordML and SpreadsheetML formats that were single, non-compressed XML files. Although they are more complex, the new approach offers several benefits:

In Microsoft's terminology, an Open XML ZIP file is called a package. Files inside that package are called parts. It is important to know that every part has a defined content type and there are no default type presumptions based on the file extension. Content type can describe anything: application XML, user XML, images, sounds, video, or any other binary objects. Every part must be connected to some other part using a relationship. Inside the package are special XML files with a ".rels" extension that defines the relationship between parts. There is also a start part (sometimes called "root," which is a bit misleading because a graph containing all parts doesn't have to be a tree structure), so the entire structure looks like Figure 1.


(
Full Size Image)

Figure 1: Parts and relations inside an XLSX file

To make a long story short, to read the data from an Open XML file you need to:

  1. Open the package as a ZIP archive: Any standard ZIP library will do.
  2. Find the parts that contain data you want to read: You can navigate through the relationship graph (more complex), or you can presume that certain parts have a defined name and path (Microsoft can change that in the future).
  3. Read the parts you are interested in: Use the standard XML library (if they are XML) or some other method (if they are images, sounds, or some other type).

On the other hand, if you want to create a new Open XML file, you need to:

  1. Create/get all necessary parts: Use a standard XML library (if they are XML), copy them, or use some other method.
  2. Create all relationships: Create ".rels" files.
  3. Create content types: Create a "[Content_Types].xml" file.
  4. Package everything into a ZIP file with the appropriate extension (DOCX, XLSX, or PPTX): Any standard ZIP library will do.

The whole story about packages, parts, content types, and relations is the same for all Open XML documents (regardless of whether they originate in the application). Microsoft refers to this as Open Packaging Conventions.

Excel 2007 Open XML Specifics

Excel 2007 extends on the basis of Open Packaging Conventions by adding its own application-specific XML types. Reference schemas for all XML files used in Office can be downloaded from MSDN, but note that some things are still open to change until the final Excel 2007 release.

You just want to read/write worksheet data, so you need to look in the "\xl\worksheets" folder inside the XLSX file; this is where all the worksheets are located. For every worksheet, there is a separate XML file: "sheet1.xml," "sheet2.xml," and so on. When you open such a file, you will notice that all of the sheet data is inside a <sheetData> element. For every row, there is a <row> element; for every cell, there is a <c> element. Finally, the value of the cell is stored in a <v> element.

However, real-world XML is never simple as schoolbook XML. You will notice that numbers get encoded as numbers inside the <v> element:

<c r="A1">
<v>100</v>
</c>

However, a string value (like "John"), also gets encoded as a number:

<c r="B1" t="s">
<v>0</v>
</c>

That is because MS Excel uses an internal table of unique strings (for performance reasons). Zero is an index of that string in an internal table of strings and attribute t="s" tells you that the underlying type is a string, not a number. So, where is the table of unique strings located? It is in an "\xl\sharedStrings.xml" XML file, and contains all the strings used in the entire workbook, not just a specific worksheet.

This approach is used for many other things: cell styles, borders, charts, number formats, and so forth. In fact, that becomes the major programming problem when working with XLSX files—updating and maintaining various tables of some unique Excel objects. In this article, you will just read/write data values, but if you require some complex formatting you probably should use some commercial component that does all the tedious work for you.

Implementation

The demo is a Windows Forms application (see Figure 2), written in C# using Visual Studio 2005. Because there is no support for ZIP files in the .NET Framework 2.0 (only for the ZIP algorithm), the demo uses an open-source ZIP library called SharpZipLib. For demonstration purposes, you will extract entire ZIP files to a TEMP folder, so you can examine the contents of that folder and its files while debugging the demo application. In a real-world application, you may want to avoid extracting to a temporary folder and just read to/write from the ZIP file directly.

For XML processing, the choice is simple. To read XML files, you use the XmlTextReader class; to write, you use the XmlTextWriter class. Both come with the .NET Framework, but you also can use any other XML processing library.


Figure 2: Demo application in action

Data Reading

You want to read a simple "In.xlsx" file (in the "Input" folder) and copy its contents to the DataTable. That file contains a list of people with their first and last names (text values) and their IDs (number values). When the "Read input .xlsx file" button is clicked, the following code is executed:

private void buttonReadInput_Click(object sender, EventArgs e)
{
   // Get the input file name from the text box.
   string fileName = this.textBoxInput.Text;
 
   // Delete the contents of the temporary directory.
   ExcelRW.DeleteDirectoryContents(ExcelRWForm.tempDir);
 
   // Unzip the input XLSX file to the temporary directory.
   ExcelRW.UnzipFile(fileName, ExcelRWForm.tempDir);
 
   // Open the XML file with a table of all unique strings used
   // in the workbook...
   FileStream fs = new FileStream(ExcelRWForm.tempDir
                                  + @"\xl\sharedStrings.xml",
                                  FileMode.Open, FileAccess.Read);
   // ...and call a helper method that parses that XML and returns
   // an array of strings.
   ArrayList stringTable = ExcelRW.ReadStringTable(fs);
 
   // Open the XML file with worksheet data...
   fs = new FileStream(ExcelRWForm.tempDir +
                       @"\xl\worksheets\sheet1.xml",
                       FileMode.Open, FileAccess.Read);
   // ...and call the helper method that parses that XML and fills
   // DataTable with values.
   ExcelRW.ReadWorksheet(fs, stringTable, this.data);
}
 



Nothing unusual happens here. The XLSX file is unzipped to the TEMP folder and the necessary XML parts (now files) are processed. The "sharedStrings.xml" file contains a global table of unique strings whereas the "sheet1.xml" file contains data for the first sheet. Helper methods are pretty straightforward XML reading code—you can download demo application code to examine them in more detail.

If everything is okay, after the button is clicked, all data will show up in the DataGridView.

Data Writing

Now, you want to write data from a DataTable to the "Out.xlsx" file in the "Output" folder. You can change some data or add some new rows in the DataGridView. When the "Write output .xlsx file" button is clicked, the following code is executed:

 

private void buttonWriteOutput_Click(object sender, EventArgs e)
{
   // Get the output file name from the text box.
   string fileName = this.textBoxOutput.Text;
 
   // Delete the contents of the temporary directory.
   ExcelRW.DeleteDirectoryContents(ExcelRWForm.tempDir);
 
   // Unzip the template XLSX file to the temporary directory.
   ExcelRW.UnzipFile(ExcelRWForm.templateFile, ExcelRWForm.tempDir);
 
   // You will need two string tables; a lookup Hashtable for fast
   // searching and an ordinary ArrayList where items are sorted
   // by their index.
   Hashtable lookupTable;
 
   // Call the helper methods that create both tables from input
   // data.
   ArrayList stringTable = ExcelRW.CreateStringTables(this.data,
      out lookupTable);
 
   // Create an XML file...
   FileStream fs = new FileStream(ExcelRWForm.tempDir
      + @"\xl\sharedStrings.xml", FileMode.Create);
 
   // ...and fill it with unique strings used in the workbook
   ExcelRW.WriteStringTable(fs, stringTable);
 
   // Create an XML file...
   new FileStream(ExcelRWForm.tempDir + @"\xl\worksheets\sheet1.xml",
                  FileMode.Create);
 
   // ..and fill it with rows and columns of the DataTable.
   ExcelRW.WriteWorksheet(fs, this.data, lookupTable);
 
   // ZIP the temporary directory to the XLSX file.
   ExcelRW.ZipDirectory(ExcelRWForm.tempDir, fileName);
 
   // If the checkbox is checked, show the XLSX file in Excel 2007.
   if (this.checkBoxOpenFile.Checked)
      System.Diagnostics.Process.Start(fileName);
}

This time, the code is a bit more complicated. So that you don't generate all necessary parts needed for XLSX file, you should decide to use a template file. You extract the template file to the temporary folder and then just change the XML parts containing a shared string table and worksheet data. All other parts, relationships, and content types stay the same, so you don't need to generate any of that. Note that you use two string tables: a lookup Hashtable for fast searching and an ordinary ArrayList where items are sorted by their index. You could pull it out only with ArrayList, but then you would need to search entire ArrayList every time you added a new string (to check whether it is already there). The CreateStringTables() helper method builds both string tables, the WriteStringTable() helper method writes the string table XML, and the WriteWorksheet() helper method writes worksheet data XML.

Again, download the demo application code to examine helper methods in more detail.

Alternative Ways

As always in programming, there is more than one method to achieve the same goal.

You could use Office automation to start an instance of Excel 2007 (or any other Office application) and then use interop calls to create a document and save it. However, using automation has some drawbacks that I have already written about (see these at http://www.gemboxsoftware.com/GBSpreadsheet.htm#Automation).

The mext version of the .NET Framework (codename WinFX) will have support for Open Packaging Conventions (package handling and navigating the relationships), but it seems there will be no support for accessing application-specific data, so you still will need to process XML parts manually.

As another option, you could use some third-party component that will come with support for the Open XML format. This will probably cost you some money but has the advantage that usually more than one format (for example, XLS, XLSX, and CSV) are supported within the same API, so your application will be able to use the same code to target different file formats