예제 #1
0
        public static bool initalize(App app)
        {
            GlobalAppData.patchInformation = null;
            GlobalAppData.app = app;
            settingsPath      = getUserProfilePath();
            if (settings == null)
            {
                String f = settingsFile;
                String d = settingsPath;

                if (!Directory.Exists(settingsPath))
                {
                    DirectoryInfo dInfo = Directory.CreateDirectory(settingsPath);
                    if (!dInfo.Exists)
                    {
                        MessageBox.Show("Failed to create profile directory: " + settingsPath);
                        return(false);
                    }
                }
                loadSettings();

                return(true);
            }
            return(true);
        }
예제 #2
0
        private static PatchInformation _deserializePatchInformation(String data)
        {
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream);

            writer.Write(data);
            writer.Flush();
            stream.Position = 0;

            PatchInformation pi = Serializer.loadFromStream <PatchInformation>(stream);

            stream.Close();
            return(pi);
        }
예제 #3
0
        public App() : base()
        {
            this.ShutdownMode          = ShutdownMode.OnLastWindowClose;
            this.CriticalFailureEvent += (reason) =>
            {
                MessageBox.Show("Critical failure. Shutting down. \n" + reason);
                doShutdown();
            };
            PatchInformation.PatchInformationLoadFailed += (reason) =>
            {
                MessageBox.Show("Downloading patch information failed: " + reason);
                doShutdown();
            };

            GlobalAppData.SettingsLoaded += (settings) =>
            {
                Task t = PatchInformation.downloadPatchInformation(settings.patcherURI);
            };

            GlobalAppData.initalize(this);
        }
예제 #4
0
 public Patcher(PatchInformation patchInformation, Settings settings)
 {
     this.patchInformation = patchInformation;
     this.settings         = settings;
 }
예제 #5
0
        public static async Task downloadPatchInformation(String uri)
        {
            if (uri == null)
            {
                throw new Exception("uri was null");
            }

            using (WebClient wc = new WebClient())
            {
                wc.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
                {
                    if (PatchInformationLoadProgress != null)
                    {
                        PatchInformationLoadProgress(e.ProgressPercentage);
                    }
                };
                wc.DownloadStringCompleted += (object sender, DownloadStringCompletedEventArgs e) =>
                {
                    if (e.Error != null)
                    {
                        if (PatchInformationLoadFailed != null)
                        {
                            PatchInformationLoadFailed(e.Error.ToString());
                        }
                        return;
                    }
                    String data      = e.Result;
                    String signature = Crypto.getSignature(data);
                    if (signature != null)
                    {
                    }
                    else if (signature == null && GlobalAppData.settings.enforceSignature == true)
                    {
                        if (PatchInformationLoadFailed != null)
                        {
                            PatchInformationLoadFailed("Couldn't find required signature.");
                        }
                        return;
                    }

                    PatchInformation pi = _deserializePatchInformation(e.Result);

                    if (PatchInformationLoaded != null)
                    {
                        PatchInformationLoaded(pi);
                    }
                };
                try
                {
                    try
                    {
                        wc.DownloadStringTaskAsync(uri);
                    }
                    catch (System.Net.WebException)
                    {
                        // this is being handeld in the event handler above already
                    }
                    catch (ArgumentException e)
                    {
                        if (PatchInformationLoadFailed != null)
                        {
                            PatchInformationLoadFailed("Uri is invalid: '" + uri + "'\n" + e.ToString());
                        }
                        return;
                    }
                }
                catch (Exception e)
                {
                    if (PatchInformationLoadFailed != null)
                    {
                        PatchInformationLoadFailed(e.ToString());
                    }
                }
            }
        }