public MainWindow(List <LauncherData.LauncherVersion> theLastestVersions)
        {
            InitializeComponent();
            lblStatus.Text = "v " + ApplicationUpdates.CurrentVersion;

            lstLatestVersions = theLastestVersions;

            //sort out the prefs and langauges
            myUserPrefs      = new UserPreferences();
            myLocales        = new Locales(myUserPrefs.UserLocale);
            this.DataContext = myLocales.CurrentLocale;

            this.DataContextChanged += new DependencyPropertyChangedEventHandler(MainWindow_DataContextChanged);

            //ok, find our storyboards
            sbFadeOut = this.Resources["sbFadeOut"] as Storyboard;
            sbFadeIn  = this.Resources["sbFadeIn"] as Storyboard;

            //and make sure they notify us when they're finished animating
            sbFadeOut.Completed += new EventHandler(sbFadeOut_Completed);
            sbFadeIn.Completed  += new EventHandler(sbFadeIn_Completed);

            //have this fire when everythings been rendered and is ready for action
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }
        private void LoadPreferences()
        {
            BinaryFormatter bf = new BinaryFormatter();
            LauncherEncryption myEncryption = new LauncherEncryption();
            IsolatedStorageFile inFile = IsolatedStorageFile.GetUserStoreForAssembly();
            //do we have the desired locale?
            Locales myLocales = new Locales(CultureInfo.CurrentUICulture.Name);

            if (App.Current.Resources["UserPreferences"] == null)
            {
                bool blnSetDefaults = false;
                //here we will attempt to load the settings object from the user's profil
                //or make them up if nothing has been chosen yet (first run)
                using (IsolatedStorageFileStream inStream = new IsolatedStorageFileStream("settings.cfg", FileMode.OpenOrCreate, System.IO.FileAccess.Read, inFile))
                using (BinaryReader read = new BinaryReader(inStream))
                {

                    if (read.BaseStream.Length == 0)
                    {
                        blnSetDefaults = true;
                    }
                    else
                    {
                        try
                        {
                            //read in the saved bytes
                            byte[] arInBytes = read.ReadBytes((int)read.BaseStream.Length);

                            //decrypt
                            byte[] arDecrypted = myEncryption.Decrypt(arInBytes);

                            //deserialize
                            using (MemoryStream msIn = new MemoryStream(arDecrypted))
                            {
                                theSettings = bf.Deserialize(msIn) as UserSettings;
                            }

                            if (theSettings == null)
                            {
                                //make a default one
                                blnSetDefaults = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            string strYar = ex.Message;
                        }
                    }
                }

                if (blnSetDefaults)
                {
                    //make a new one
                    theSettings = new UserSettings
                    {
                        Locale = myLocales.CurrentLocale.Locale,
                        Skin = "SWG_DataPad",
                        Pallette = "Alpha Blue",
                        GhostFont = "Aurek-Besh"
                    };

                    //and save that into the file
                    using (MemoryStream msOut = new MemoryStream())
                    using (IsolatedStorageFileStream outStream = new IsolatedStorageFileStream("settings.cfg", FileMode.OpenOrCreate, System.IO.FileAccess.Write, inFile))
                    using (BinaryWriter bwOut = new BinaryWriter(outStream))
                    {
                        //serialize it
                        bf.Serialize(msOut, theSettings);

                        //encrypt it and write it out
                        bwOut.Write(myEncryption.Encrypt(msOut.ToArray()));
                    }

                }

                //and put it in the resources
                App.Current.Resources.Add("UserPreferences", theSettings);
            }
            else
            {
                //collect them from the Application Resources Collection
                theSettings = App.Current.Resources["UserPreferences"] as UserSettings;
            }
        }
示例#3
0
        private void InitiliseMyApp(Splash theSplashScreen)
        {
            //check for launcher updates first
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Launcher));
            }
            UserPreferences myPrefs        = new UserPreferences();
            ServiceMaker    myServiceMaker = new ServiceMaker();

            LauncherData.LauncherDataClient myClient = myServiceMaker.GetServiceClient();

            ApplicationUpdates myApplicationUpdates = new ApplicationUpdates(myClient);

            List <LauncherData.LauncherVersion> lstLatestVersions = myApplicationUpdates.UpdateAvailable(this.Dispatcher);

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Launcher, lstLatestVersions.Count, ""));
            }

            //and skins
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Skins));
            }
            UISettings mySettings = new UISettings();

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Skins, mySettings.GetAvailableSkins.Count, ""));
            }

            //and now the languages
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Languages));
            }

            Locales myLocale = new Locales();

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Languages, myLocale.NumberLoaded, ""));
            }

            //finally, load the servers
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Servers));
            }

            List <ServerInfo> lstServers = new List <ServerInfo>();


            try
            {
                List <LauncherData.ServerInfo> lstLiveServers = myClient.GetServers();



                var tmpServers = from ser in lstLiveServers
                                 select new ServerInfo
                {
                    Address      = ser.Address,
                    CharsCreated = ser.CharsCreated,
                    Description  = ser.Description,
                    LastUpdated  = ser.LastUpdated,
                    LauncherPort = ser.LauncherPort,
                    Population   = ser.Population,
                    Port         = ser.Port,
                    RSSFeedUrl   = ser.RSSFeedUrl,
                    ServerId     = ser.ServerId,
                    ServerName   = ser.ServerName
                };
                //update the preferecnes
                myPrefs.UpdateSettings(UserPreferences.SettingsType.CachedServers, tmpServers.ToList());
            }
            catch
            {
                //don't update the cached ones
            }

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Servers, lstServers.Count, ""));
            }

            //and get the list of standard TRE files
            try
            {
                List <LauncherData.StandardTre> lstLiveStandardTres = myClient.GetStandardTre();
                var tmpStandard = from stre in lstLiveStandardTres
                                  select new StandardTre
                {
                    Filename = stre.Filename,
                    MD5Hash  = stre.MD5Hash
                };

                myPrefs.UpdateSettings(UserPreferences.SettingsType.StandardTres, tmpStandard.ToList());
            }
            catch
            {
            }

            Dispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate()
            {
                MainWindow = new MainWindow(lstLatestVersions);
                MainWindow.Show();
            }), System.Windows.Threading.DispatcherPriority.Normal);
        }
        private void InitiliseMyApp(Splash theSplashScreen)
        {
            //check for launcher updates first
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Launcher));
            }
            UserPreferences myPrefs = new UserPreferences();
            ServiceMaker myServiceMaker = new ServiceMaker();
            LauncherData.LauncherDataClient myClient = myServiceMaker.GetServiceClient();

            ApplicationUpdates myApplicationUpdates = new ApplicationUpdates(myClient);

            List<LauncherData.LauncherVersion> lstLatestVersions = myApplicationUpdates.UpdateAvailable(this.Dispatcher);

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Launcher, lstLatestVersions.Count, ""));
            }

            //and skins
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Skins));
            }
            UISettings mySettings = new UISettings();

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Skins, mySettings.GetAvailableSkins.Count, ""));
            }

            //and now the languages
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Languages));
            }

            Locales myLocale = new Locales();

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Languages, myLocale.NumberLoaded, ""));
            }

            //finally, load the servers
            if (SectionStarted != null)
            {
                SectionStarted(this, new LoadingSectionStarted(LoadingType.Servers));
            }

            List<ServerInfo> lstServers = new List<ServerInfo>();

            try
            {
                List<LauncherData.ServerInfo> lstLiveServers = myClient.GetServers();

                var tmpServers = from ser in lstLiveServers
                                 select new ServerInfo
                                 {
                                     Address = ser.Address,
                                     CharsCreated = ser.CharsCreated,
                                     Description = ser.Description,
                                     LastUpdated = ser.LastUpdated,
                                     LauncherPort = ser.LauncherPort,
                                     Population = ser.Population,
                                     Port = ser.Port,
                                     RSSFeedUrl = ser.RSSFeedUrl,
                                     ServerId = ser.ServerId,
                                     ServerName = ser.ServerName
                                 };
                //update the preferecnes
                myPrefs.UpdateSettings(UserPreferences.SettingsType.CachedServers, tmpServers.ToList());
            }
            catch
            {
                //don't update the cached ones
            }

            if (SectionLoaded != null)
            {
                SectionLoaded(this, new LoadingSectionCompleted(LoadingType.Servers, lstServers.Count, ""));
            }

            //and get the list of standard TRE files
            try
            {

                List<LauncherData.StandardTre> lstLiveStandardTres = myClient.GetStandardTre();
                var tmpStandard = from stre in lstLiveStandardTres
                                  select new StandardTre
                                  {
                                      Filename = stre.Filename,
                                      MD5Hash = stre.MD5Hash
                                  };

                myPrefs.UpdateSettings(UserPreferences.SettingsType.StandardTres, tmpStandard.ToList());

            }
            catch
            {

            }

            Dispatcher.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate()
            {
                MainWindow = new MainWindow(lstLatestVersions);
                MainWindow.Show();
            }), System.Windows.Threading.DispatcherPriority.Normal);
        }
示例#5
0
        private void LoadPreferences()
        {
            BinaryFormatter     bf           = new BinaryFormatter();
            LauncherEncryption  myEncryption = new LauncherEncryption();
            IsolatedStorageFile inFile       = IsolatedStorageFile.GetUserStoreForAssembly();
            //do we have the desired locale?
            Locales myLocales = new Locales(CultureInfo.CurrentUICulture.Name);

            if (App.Current.Resources["UserPreferences"] == null)
            {
                bool blnSetDefaults = false;
                //here we will attempt to load the settings object from the user's profil
                //or make them up if nothing has been chosen yet (first run)
                using (IsolatedStorageFileStream inStream = new IsolatedStorageFileStream("settings.cfg", FileMode.OpenOrCreate, System.IO.FileAccess.Read, inFile))
                    using (BinaryReader read = new BinaryReader(inStream))
                    {
                        if (read.BaseStream.Length == 0)
                        {
                            blnSetDefaults = true;
                        }
                        else
                        {
                            try
                            {
                                //read in the saved bytes
                                byte[] arInBytes = read.ReadBytes((int)read.BaseStream.Length);

                                //decrypt
                                byte[] arDecrypted = myEncryption.Decrypt(arInBytes);

                                //deserialize
                                using (MemoryStream msIn = new MemoryStream(arDecrypted))
                                {
                                    theSettings = bf.Deserialize(msIn) as UserSettings;
                                }

                                if (theSettings == null)
                                {
                                    //make a default one
                                    blnSetDefaults = true;
                                }
                            }
                            catch (Exception ex)
                            {
                                string strYar = ex.Message;
                            }
                        }
                    }

                if (blnSetDefaults)
                {
                    //make a new one
                    theSettings = new UserSettings
                    {
                        Locale    = myLocales.CurrentLocale.Locale,
                        Skin      = "SWG_DataPad",
                        Pallette  = "Alpha Blue",
                        GhostFont = "Aurek-Besh"
                    };

                    //and save that into the file
                    using (MemoryStream msOut = new MemoryStream())
                        using (IsolatedStorageFileStream outStream = new IsolatedStorageFileStream("settings.cfg", FileMode.OpenOrCreate, System.IO.FileAccess.Write, inFile))
                            using (BinaryWriter bwOut = new BinaryWriter(outStream))
                            {
                                //serialize it
                                bf.Serialize(msOut, theSettings);

                                //encrypt it and write it out
                                bwOut.Write(myEncryption.Encrypt(msOut.ToArray()));
                            }
                }

                //and put it in the resources
                App.Current.Resources.Add("UserPreferences", theSettings);
            }
            else
            {
                //collect them from the Application Resources Collection
                theSettings = App.Current.Resources["UserPreferences"] as UserSettings;
            }
        }