//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.Text; using System.Net; using System.IO; using System.Xml; namespace DarkWynter.App { public partial class Episodes : UserControl { private static string contentFileName = "Content.contentproj"; private static string zipFileName = "G2L.zip"; private static string zipPassWord = "darkwynter"; private static string server_Zip = "http://darkwynter.com/_Episodes/G2L/"; private static string server_Files = "http://www.darkwynter.com/Beta2/Trunk/"; private static string userName = "darkwynter"; private static string password = "wynter1"; private static string localPath = ""; // Calced in CTOR private static ProgressBar progress; private static Label progressLabel; private static ListBox localEpisodes; public Episodes() { InitializeComponent(); // Calc local Content folder location localPath = GetSolutionDirectory(); progress = this.progressBarZipDownload; progressLabel = this.labelProgress; localEpisodes = this.localEposodes_listBox; LoadLevelIndex(); } /// /// Gets the Solution directory containing UserControl Dlls. /// /// public static String GetSolutionDirectory() { //// Get Parent Directory string curDir = Directory.GetCurrentDirectory(); return curDir + "\\"; // Get Working Directory //String workDir = curDir.Substring(0, curDir.IndexOf("SmallBusinessEngine\\bin\\Debug")); //// Get Parent Directory //DirectoryInfo parentDir = Directory.GetParent(curDir); //return parentDir.FullName + "\\"; } #region Download Episode private void downloadToolStripMenuItem_Click(object sender, EventArgs e) { progress.Minimum = 0; progress.Maximum = 100; progress.BackColor = Color.LightBlue; progress.Invalidate(); progressLabel.Text = "Contacting Server.."; progressLabel.Invalidate(); DownLoadFileInBackground( server_Zip + zipFileName, localPath + zipFileName ); } public static void DownLoadFileInBackground(string serverAddress, string localAddress) { WebClient client = new WebClient(); Uri uri = new Uri(serverAddress); // Specify that the DownloadFileCallback method gets called // when the download completes. client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback); // Specify a progress notification handler. client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback); try { client.DownloadFileAsync(uri, localAddress); } catch { progressLabel.Text = "Error Connecting to Server. Please Try Again..."; } } private static void DownloadProgressCallback(object sender, DownloadProgressChangedEventArgs e) { if (e.ProgressPercentage < 99) { progress.Value = e.ProgressPercentage; // Displays the operation identifier, and the transfer progress. progressLabel.Text = (string)e.UserState + " Downloaded " + e.BytesReceived + " of " + e.TotalBytesToReceive + " bytes. " + e.ProgressPercentage + " % complete... "; } else { progress.Value = 85; progressLabel.Text = "Unzipping Files"; } } private static void DownloadFileCallback(object sender, AsyncCompletedEventArgs e) { progress.BackColor = Color.LightGreen; // Displays the operation identifier, and the transfer progress. if (e.Error != null) { throw new Exception("Error Downloading File"); } progressLabel.Text = "Download Complete"; progress.Value = 85; progressLabel.Text = "Unzipping Files"; // Unzip the content DarkWynter.Engine.Utilities.ZipUtility.UnZipFiles( localPath + zipFileName, localPath, zipPassWord, true ); progressLabel.Text = "Installation Complete... Please Restart This Application."; progress.Value = 100; } #endregion #region Load Episode private static void LoadLevelIndex() { localEpisodes.Items.Clear(); if (DarkWynter.Engine.Globals.Statics_Engine.levelInfo != null) { // Get Xml Level Info Nodes for (int i = 0; i < DarkWynter.Engine.Globals.Statics_Engine.levelInfo.Count; i++) { localEpisodes.Items.Add(DarkWynter.Engine.Globals.Statics_Engine.levelInfo[i].name); } } } private void buttonLoadContent_Click(object sender, EventArgs e) { } private void loadToolStripMenuItem_Click(object sender, EventArgs e) { LoadLevelIndex(); } #endregion private void localEposodes_listBox_SelectedIndexChanged(object sender, EventArgs e) { DarkWynter.Engine.Globals.Statics_Engine.levelIndex = localEposodes_listBox.SelectedIndex; DarkWynter.Engine.Globals.Statics_Engine.GameSettings.LoadLevel = true; if (DarkWynter.Engine.Globals.Statics_Engine.levelIndex == 2) { DarkWynter.Engine.Globals.Statics_Engine.SystemSettings.gameState = DarkWynter.Engine.Globals.Enums_Engine.EngineState.FINALIZE_G2LSTUFF; } if (DarkWynter.Engine.Globals.Statics_Engine.levelIndex == 1 || DarkWynter.Engine.Globals.Statics_Engine.levelIndex == 0) { DarkWynter.Engine.Globals.Statics_Engine.SystemSettings.gameState = DarkWynter.Engine.Globals.Enums_Engine.EngineState.INSTRUCTION_SCREEN; } } private void buttonRemoveEpisode_Click(object sender, EventArgs e) { localEposodes_listBox.Items.RemoveAt(localEposodes_listBox.SelectedIndex); } } // End Class } // End Namespace