Esempio n. 1
0
        public bool StartDownload(AsyncCompletedEventHandler dlFinishedCallback,
                                  DownloadProgressChangedEventHandler dlProgressCallback,
                                  string URL,
                                  string SavePath)
        {
            Uri uri;

            try
            {
                uri = new Uri(URL);
            }
            catch (Exception)
            {
                return(false);
            }
            m_client.DownloadFileCompleted   += dlFinishedCallback;
            m_client.DownloadProgressChanged += dlProgressCallback;

            int chrindex = SavePath.LastIndexOf(@"/");

            if (chrindex == -1)
            {
                chrindex = SavePath.LastIndexOf(@"\");
            }

            string Path = SavePath.Substring(0, chrindex);

            System.IO.Directory.CreateDirectory(Path);

            m_client.DownloadFileAsync(uri, MyToolkit.ValidPath(SavePath));

            return(true);
        }
Esempio n. 2
0
        private void Form_Load(object sender, EventArgs e)
        {
            MyToolkit.ActivityLog("Loading application.");
            try
            {
                // Attempt to kill any other version of the patcher //
                // that may be running                              //
                ProcessKiller();


                this.Text += " " + Application.ProductVersion;
                Skin();

                ScanParameters();

                LoadManifestList();

                timer1.Enabled = Setup();
            }
            catch (Exception ex)
            {
                MyToolkit.ErrorReporter(ex, this.Name + ".Form_Load");
            }

            loaded = true;

            MyToolkit.ActivityLog("Load application complete.");
        }
Esempio n. 3
0
        private long DirectoryCount(string sourceDirName)
        {
            long count = 0;

            try {
                DirectoryInfo   dir  = new DirectoryInfo(sourceDirName);
                DirectoryInfo[] dirs = dir.GetDirectories();

                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo file in files)
                {
                    if (Kill)
                    {
                        return(0);
                    }
                    try { count += file.Length; }
                    catch (Exception) { }
                }

                foreach (DirectoryInfo subdir in dirs)
                {
                    count += DirectoryCount(subdir.FullName);
                }
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, "DirCopy.DirectoryCopyStep");
            }
            return(count);
        }
Esempio n. 4
0
        private void ProcessKiller()
        {
            try
            {
                Process[] prs           = Process.GetProcessesByName("Bourbon");
                Process   me            = Process.GetCurrentProcess();
                int       killcount     = 0;
                int       killfailcount = 0;
                foreach (Process pr in prs)
                {
                    if (pr.Id != me.Id)
                    {
                        MyToolkit.ActivityLog("Shutting down previous instance of patcher...");
                        killcount++;
                        try
                        {
                            pr.Kill();
                        } catch (Exception ex) {
                            killfailcount++;
                        }
                    }
                }

                if (killcount > 0)
                {
                    Thread.Sleep(2000);
                }
                if (killfailcount > 0)
                {
                    MessageBox.Show(null, "Found a running instance of Bourbon but was not able to terminate it.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            } catch (Exception ex) { }
        }
Esempio n. 5
0
 private void cbManifest_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (loaded && Settings.LastManifest != cbManifest.SelectedItem.ToString())
     {
         MyToolkit.ActivityLog("Manifest changed to \"" + cbManifest.SelectedItem.ToString() + "\"");
         Settings.LastManifest = cbManifest.SelectedItem.ToString();
         ManifestURL           = Settings.LastManifest;
         ReValidate();
     }
 }
Esempio n. 6
0
        public static void SelfRelocate()
        {
            try {
                if (Application.StartupPath == Settings.GamePath)
                {
                    return;
                }
                if (!File.Exists(Application.ExecutablePath))
                {
                    return;
                }

                string ShortcutPath   = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                string ShortcutTarget = Path.Combine(Settings.GamePath, "CreamSoda.exe");

                MyToolkit.ActivityLog("Self Relocating CreamSoda to \"" + ShortcutTarget + "\"");

                if (!Directory.Exists(Settings.GamePath))
                {
                    Directory.CreateDirectory(Settings.GamePath);
                }

                try {
                    if (File.Exists(ShortcutTarget))
                    {
                        File.Delete(ShortcutTarget);
                    }
                    File.Move(Application.ExecutablePath, ShortcutTarget);
                } catch (Exception)
                {
                    File.Copy(Application.ExecutablePath, ShortcutTarget);
                    try { File.Move(Application.ExecutablePath, Path.Combine(Application.StartupPath, "deleteme.txt")); }
                    catch (Exception)
                    {
                        MyToolkit.ActivityLog("Failed to relocate CreamSoda to \"" + ShortcutTarget + "\"");
                    }
                }

                try {
                    using (ShellLink shortcut = new ShellLink()) {
                        shortcut.Target = ShortcutTarget;
                        //shortcut.WorkingDirectory = Path.GetDirectoryName(ShortcutTarget);
                        shortcut.Description = "Drink up!";
                        shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
                        shortcut.Save(Path.Combine(ShortcutPath, "CreamSoda.lnk"));
                    }
                } catch (Exception ex) {
                    MyToolkit.ActivityLog("Failed to create desktop shortcut \"" + ShortcutTarget + "\"");
                    MessageBox.Show(ex.Message);
                }
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, "Preferences.SelfRelocate");
            }
        }
Esempio n. 7
0
        public void Cancel()
        {
            if (myWorkThread != null)
            {
                if (myWorkThread.IsAlive)
                {
                    MyToolkit.ActivityLog("Patching process canceled.");

                    try { myWorkThread.Abort(); }
                    catch (Exception ex) { }
                }
            }
        }
Esempio n. 8
0
        private void DirectoryCopyStep(string sourceDirName, string destDirName, bool copySubDirs = true, bool replace = true)
        {
            try{
                DirectoryInfo   dir  = new DirectoryInfo(sourceDirName);
                DirectoryInfo[] dirs = dir.GetDirectories();

                if (!dir.Exists)
                {
                    throw new DirectoryNotFoundException(
                              "Source directory does not exist or could not be found: "
                              + sourceDirName);
                }

                if (!Directory.Exists(destDirName))
                {
                    Directory.CreateDirectory(destDirName);
                }

                FileInfo[] files = dir.GetFiles();
                foreach (FileInfo file in files)
                {
                    if (Kill)
                    {
                        return;
                    }
                    string temppath = Path.Combine(destDirName, file.Name);

                    if (File.Exists(temppath) && replace)
                    {
                        File.SetAttributes(temppath, File.GetAttributes(temppath) & ~FileAttributes.ReadOnly);
                        File.Delete(temppath);
                    }

                    try { file.CopyTo(temppath, true); }
                    catch (Exception) { }

                    m_FilesDone += file.Length;
                }

                if (copySubDirs)
                {
                    foreach (DirectoryInfo subdir in dirs)
                    {
                        string temppath = Path.Combine(destDirName, subdir.Name);
                        DirectoryCopyStep(subdir.FullName, temppath, copySubDirs);
                    }
                }
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, "DirCopy.DirectoryCopyStep");
            }
        }
Esempio n. 9
0
        private void Form_FormClosing(object sender, FormClosingEventArgs e)
        {
            MyToolkit.ActivityLog("Application quitting");
            WorkThread.Kill = true;
            DirCopy.Kill    = true;

            if (myCopyDirThread != null)
            {
                if (myCopyDirThread.IsAlive)
                {
                    try { myCopyDirThread.Abort(); } catch (Exception ex) { }
                }
            }
        }
Esempio n. 10
0
        private void btnScreenshots_Click(object sender, EventArgs e)
        {
            try {
                MyToolkit.ActivityLog("User clicked to open screenshots directory");
                string screenshotDir = Path.Combine(Settings.GamePath, "screenshots");

                if (!Directory.Exists(screenshotDir))
                {
                    Directory.CreateDirectory(screenshotDir);
                }
                System.Diagnostics.Process.Start("explorer.exe", screenshotDir);
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, this.Name + ".btScreenshots_Click");
            }
        }
Esempio n. 11
0
    public Fingerprint(string RootPath, string FileName, string Checksum)
    {
        try{
            m_RootPath = RootPath;
            m_FileName = FileName.Replace(".EXE", ".exe");

            // Load size from the file info
            m_Size = (new FileInfo(FileName)).Length;

            // Make sure the checksum is lowercase
            m_Checksum = Checksum.ToLower();
        } catch (Exception ex) {
            MyToolkit.ErrorReporter(ex, "Fingerprint.Constructor2");
        }
    }
Esempio n. 12
0
        public void DownloadManifest()
        {
            if (DontDownloadManifest)
            {
                ManifestDownloadComplete(null, null);
            }

            MyToolkit.ActivityLog("Attempting to download Manifest file \"" + ManifestURL + "\"");
            m_Status      = "Fetching manifest";
            LocalManifest = MyToolkit.ValidPath(Path.Combine(PathRoot, "Bourbon.xml"));
            client.StartDownload(new AsyncCompletedEventHandler(ManifestDownloadComplete),
                                 new DownloadProgressChangedEventHandler(dlProgress),
                                 ManifestURL,
                                 LocalManifest);
        }
Esempio n. 13
0
        private void ReValidate()
        {
            try
            {
                pnlErrors.Visible   = false;
                webBrowser1.Visible = true;

                MyToolkit.ActivityLog("Revalidation process started");
                ListBox1.DataSource = null;
                File.Delete(Path.Combine(Settings.GamePath, "Bourbonlog.xml"));
                timer1.Enabled = Setup();
                StartUp();
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, this.Name + ".Form_Load");
            }
        }
Esempio n. 14
0
    public Fingerprint(string RootPath, string FileName, string Checksum, long Size)
    {
        try
        {
            m_RootPath = RootPath;
            m_FileName = FileName.Replace(".EXE", ".exe");

            // Make sure the checksum is lowercase
            m_Checksum = Checksum.ToLower();

            // ... yea... overcommenting!
            m_Size = Size;
        } catch (Exception ex) {
            MyToolkit.ErrorReporter(ex, "Fingerprint.Constructor2");
        }
    }
Esempio n. 15
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyToolkit.ActivityLog("User clicked to open Options window");
            Preferences prefs = new Preferences();

            prefs.btnRevalidate.Enabled = (myWorker.Status == "Done");
            prefs.ShowDialog(this);
            Skin();

            LoadManifestList();

            if (prefs.ReValidate)
            {
                ReValidate();
            }
        }
Esempio n. 16
0
    /**********************************************************************/

    public Fingerprint(string RootPath, string FileName)
    {
        try {
            m_RootPath = RootPath;
            m_FileName = FileName.Replace(".EXE", ".exe");
            if (File.Exists(FullName))
            {
                m_Size = (new FileInfo(FullName)).Length;
            }
            else
            {
                m_Size = 0;
            }
            m_Checksum = GenerateHash();
        } catch (Exception ex) {
            MyToolkit.ErrorReporter(ex, "Fingerprint.Constructor1");
        }
    }
Esempio n. 17
0
        private void FlagVerified(string file, long size, string md5)
        {
            try
            {
                FileInfo fi = new FileInfo(Path.Combine(Settings.GamePath, file));

                XElement e = new XElement("file");
                e.Add(new XAttribute("name", file));
                e.Add(new XAttribute("size", size));
                e.Add(new XAttribute("md5", md5));
                e.Add(new XAttribute("ModDate", fi.LastWriteTime.ToString(fi.LastWriteTime.ToString("yyyy.MM.dd.HH.mm.ss"))));

                LogNew.Add(e);

                // Sometimes we may run this through too fast and the file may be locked
                // we will retry a save attempt for up to 3 seconds, if we are not able
                // to save without errors by then we do one final save attempt and
                // report error.
                bool      saveSuccessful = false;
                Stopwatch sw             = new Stopwatch();
                sw.Start();

                while (sw.ElapsedMilliseconds < 3000 && !saveSuccessful)
                {
                    try
                    {
                        LogNew.Save(LogPath);
                        saveSuccessful = true;
                    } catch (Exception)
                    {
                        saveSuccessful = false;
                    }
                }

                // OK, if we did not save, here is our last attempt!
                if (!saveSuccessful)
                {
                    LogNew.Save(LogPath);
                }
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, "WorkThread.FlagVerified");
            }
        }
Esempio n. 18
0
        private void StartUp()
        {
            try
            {
                MyToolkit.ActivityLog("Started patching");
                string PathRoot      = Settings.GamePath;
                string LocalManifest = PathRoot + @"Bourbon.xml";

                btnPlay.Text       = "...";
                btnPlay.Enabled    = false;
                cbManifest.Enabled = false;

                myWorker = new WorkThread(ManifestURL);
                myWorker.LocalManifest = LocalManifest;
                myWorker.PathRoot      = PathRoot;
                myWorker.DownloadManifest();
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, this.Name + ".StartUp");
            }
        }
Esempio n. 19
0
        private void btnPlay_Click(object sender, EventArgs e)
        {
            try {
                MyToolkit.ActivityLog("User clicked play with the following profile: " + ((LaunchProfile)ListBox1.SelectedItem).Text);

                var startInfo = new ProcessStartInfo();
                startInfo.WorkingDirectory = Settings.GamePath;
                startInfo.FileName         = ((LaunchProfile)ListBox1.SelectedItem).Exec;
                startInfo.Arguments        = ((LaunchProfile)ListBox1.SelectedItem).Params;
                startInfo.Arguments       += " " + Settings.GameParams;

                Process.Start(startInfo);
                if (Settings.QuitOnLaunch)
                {
                    Application.Exit();
                }
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, this.Name + ".btnPlay_Click");
            }
        }
Esempio n. 20
0
        private bool Setup()
        {
            try {
                if (Settings.SetupNeeded)
                {
                    MyToolkit.ActivityLog("Setting up CreamSoda");
                    string myPath    = "";
                    bool   PathValid = false;
                    FolderBrowserDialog FileBox;

                    do
                    {
                        FileBox = new FolderBrowserDialog
                        {
                            Description  = "Select a location where you would like to install CreamSoda; preferably under My Documents or Application Data. Do not use a folder under Program Files.",
                            SelectedPath = Application.StartupPath
                        };

                        if (FileBox.ShowDialog(this) == System.Windows.Forms.DialogResult.Cancel)
                        {
                            MessageBox.Show("You must select a valid install directory to continue.\nCreamSoda will now quit. Restart CreamSoda once you have a valid installation path.");
                            Application.Exit();
                            return(false);
                        }

                        myPath    = FileBox.SelectedPath;
                        PathValid = true;
                    } while (!PathValid);

                    Settings.GamePath = myPath;

                    MyToolkit.ActivityLog("CreamSoda installed at \"" + myPath + "\"");
                }

                SelfRelocate();
                return(true);
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, this.Name + ".Setup");
                return(false);
            }
        }
Esempio n. 21
0
    /// <summary>
    /// Generates md5 checksum.
    /// </summary>
    /// <returns>MD5 checksum</returns>
    public string GenerateHash(string path)
    {
        try
        {
            MD5 md5Hash = MD5.Create();

            var buffer = md5Hash.ComputeHash(File.ReadAllBytes(path));

            var cs = new StringBuilder();

            for (int i = 0; i < buffer.Length; i++)
            {
                cs.Append(buffer[i].ToString("x2"));
            }

            // Return an uppercase version of the consolidated string.
            return(cs.ToString().ToLower());
        }
        catch (Exception ex)
        {
            MyToolkit.ErrorReporter(ex, "Fingerprint.GenerateHash");
            return("");
        }
    }
Esempio n. 22
0
        private void Finish()
        {
            try{
                MyToolkit.ActivityLog("Finished patching.");

                Progress.Value = 100;
                timer1.Enabled = false;

                if (myWorker.ErrorMessage != "")
                {
                    txtErrors.Text      = myWorker.ErrorMessage;
                    webBrowser1.Visible = false;
                    pnlErrors.Visible   = true;
                }
                else
                {
                    btnPlay.Enabled    = true;
                    cbManifest.Enabled = true;
                    btnPlay.Text       = "Play";
                }
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, this.Name + ".Finish");
            }
        }
Esempio n. 23
0
        void SelfPatch()
        {
            try
            {
                Fingerprint myFingerprint = new Fingerprint(Settings.GamePath, "Bourbon.exe");

                if (DontSelfUpdate)
                {
                    return;
                }
                MyToolkit.ActivityLog("Starting self-patch process.");

                // Before we go far... lets see if there are any old temp files hanging around and get rid of them

                string[] oldFiles = Directory.GetFiles(Settings.GamePath, "*.old");
                foreach (string oldFile in oldFiles)
                {
                    try { File.Delete(oldFile); }
                    catch (Exception ex) { }
                }

                // OK now thats out of the way, lets determine if we need to self patch or not!!
                IEnumerable <XElement> launchers = m_manifest.Descendants("launcher");
                m_Status = "Self patching";
                foreach (XElement launcher in launchers)
                {
                    if (launcher.Attribute("id").Value == "Bourbon")
                    {
                        long size = 0;
                        long.TryParse(launcher.Attribute("size").Value.ToString(), out size);
                        string md5 = launcher.Attribute("md5").Value;

                        Fingerprint remoteLauncher = new Fingerprint(Settings.GamePath, "Bourbon.exe", md5, size);

                        if (!myFingerprint.Equals(remoteLauncher))
                        {
                            MyToolkit.ActivityLog("Patcher out of date...");

                            // We need to update!!! yay...
                            IEnumerable <XElement> urls = launcher.Descendants("url");

                            // Get every possible download URL into the remoteLauncher fingerprint
                            foreach (XElement url in urls)
                            {
                                remoteLauncher.AddDownloadURL(url.Value);
                            }


                            // Start the download process
                            HTTP selfPatcherClient = new HTTP();

                            m_DownloadSize = remoteLauncher.Size;
                            string downloadURL = remoteLauncher.DownloadURL;
                            MyToolkit.ActivityLog("Downloading new version from \"" + downloadURL + "\"");
                            if (selfPatcherClient.StartDownload(new AsyncCompletedEventHandler(DownloadFileComplete),
                                                                new DownloadProgressChangedEventHandler(dlProgress),
                                                                downloadURL,
                                                                remoteLauncher.FullName + ".download"))
                            {
                                m_Status         = "Downloading";
                                m_DownloadActive = true;
                            }

                            m_current = remoteLauncher.FullName;

                            // Wait until download is complete

                            MyToolkit.ActivityLog("Waiting for patcher download to complete...");
                            while (selfPatcherClient.Active)
                            {
                                if (Kill)
                                {
                                    selfPatcherClient.CancelDownload();
                                    return;
                                }
                                System.Threading.Thread.Sleep(10);
                            }
                            m_DownloadActive = false;
                            MyToolkit.ActivityLog("New patcher version downloaded...");

                            // Make sure the downloaded file is not corrupted

                            Fingerprint downloadedFile = new Fingerprint(remoteLauncher.RootPath, remoteLauncher.FileName + ".download");

                            if (!downloadedFile.Equals(remoteLauncher))
                            {
                                string error = "Was unable to self patch. Downloaded file did not match expected checksum.";
                                error += "\r\n" + remoteLauncher.FileName
                                         + "\r\n md5: " + remoteLauncher.Checksum + " vs " + downloadedFile.Checksum
                                         + "\r\n size: " + remoteLauncher.Size + " vs " + downloadedFile.Size;

                                MyToolkit.ActivityLog(error);

                                File.Delete(downloadedFile.FullName + ".download");
                                m_ErrorLog.Add(error);
                                m_Status = "Done";
                                return;
                            }
                            else
                            {
                                // Find an available _#.old file name
                                long   i         = 0;
                                string TrashName = myFingerprint.FullName + "_";
                                while (File.Exists(TrashName + i.ToString() + ".old"))
                                {
                                    i++;
                                }

                                TrashName = TrashName + i.ToString() + ".old";
                                File.Move(myFingerprint.FullName, TrashName);
                                File.Move(myFingerprint.FullName + ".download", myFingerprint.FullName);

                                var startInfo = new ProcessStartInfo();
                                startInfo.FileName  = myFingerprint.FullName;
                                startInfo.Arguments = MyToolkit.AllArgs();

                                MyToolkit.ActivityLog("Bourbon has been patched successfuly. Restarting.");

                                Process.Start(startInfo);

                                Application.Exit();
                                return;
                            }
                        }
                    }
                }

                MyToolkit.ActivityLog("Self patching process complete.");
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "WorkThread.SelfPatch()");
            }
        }
Esempio n. 24
0
        public void Validate()
        {
            long i = 0;

            m_Status = "Validating";

            LoadLog();

            foreach (Fingerprint ManifestFingerprint in m_ManifestFileList)
            {
                if (Kill)
                {
                    return;
                }

                i++;
                m_current = ManifestFingerprint.FullName;

                ProgressEventArgs e = new ProgressEventArgs(i, m_ManifestFileList.Count);

                Fingerprint LocalFingerprint;
                if (!ManifestFingerprint.PathIsSafe)
                {
                    // This manifest entry sets off our path traversal detection!
                    // 1. Don't attempt to download it, delete it, etc.
                    // 2. Write a log entry about it.
                    MyToolkit.ActivityLog("Manifest contains path traversal! File named '" + ManifestFingerprint.FileName +
                                          "' would be written to '" + ManifestFingerprint.AbsolutePath + "'. Skipping.");
                }
                else if (ManifestFingerprint.Size == 0)
                {
                    // File is to be deleted
                    if (System.IO.File.Exists(ManifestFingerprint.FullName))
                    {
                        System.IO.File.Delete(ManifestFingerprint.FullName);
                    }
                }
                else if (System.IO.File.Exists(ManifestFingerprint.FullName))
                {
                    // File exists locally, lets start verifying it. First check if
                    // the checksum matches the one in our last run log, if so there
                    // is no need to download the file nor do a checksum
                    if (AlreadyVerified(ManifestFingerprint.FileName,
                                        ManifestFingerprint.Size,
                                        ManifestFingerprint.Checksum))
                    {
                        FlagVerified(ManifestFingerprint.FileName, ManifestFingerprint.Size, ManifestFingerprint.Checksum);
                    }
                    else
                    {
                        // Get an md5 checksum for the local copy of the file
                        LocalFingerprint = new Fingerprint(ManifestFingerprint.RootPath, ManifestFingerprint.FileName);

                        if (LocalFingerprint.Equals(ManifestFingerprint))
                        {
                            FlagVerified(ManifestFingerprint.FileName, ManifestFingerprint.Size, ManifestFingerprint.Checksum);
                        }
                        else
                        {
                            // There was no match, lets add the file to our download queue
                            AddToDownloadQueue(ManifestFingerprint);
                        }
                    }
                }
                else
                {
                    // File does not exist locally, we must download it. Add to our download queue.
                    AddToDownloadQueue(ManifestFingerprint);
                }
                m_progress = (int)(Math.Round((i / 100.0f) * 100.0f));
            }

            DownloadFiles();
        }
Esempio n. 25
0
        void ManifestDownloadComplete(object sender, AsyncCompletedEventArgs e)
        {
            // Check if we had any HTTP download errors
            if (e != null)
            {
                if (e.Error != null)
                {
                    MyToolkit.ActivityLog("Manifest download error for " + ManifestURL + "\r\n" + e.Error.Message);
                    m_ErrorLog.Add("Manifest download error for " + ManifestURL + "\r\n" + e.Error.Message);
                    m_Status = "Done";
                    return;
                }
            }

            // Check if the downloaded file is where it should be
            if (!File.Exists(LocalManifest))
            {
                MyToolkit.ActivityLog("Error downloading manifest, download complete but no file found locally.");
                m_ErrorLog.Add("Error downloading manifest");
                m_Status = "Done";
                return;
            }

            // Make certain the downloaded manifest and the one we
            // requested match in size
            FileInfo dlInfo = new FileInfo(LocalManifest);

            if (dlInfo.Length != client.Length)
            {
                MyToolkit.ActivityLog("Error downloading manifest, downloaded file not the right size. Expected: " + dlInfo.Length + " received: " + client.Length);
                m_ErrorLog.Add("Error downloading manifest");
                m_Status = "Done";
                return;
            }

            // We got a manifest, lets start reading through it
            m_current = "";


            MyToolkit.ActivityLog("Manifest downloaded successfully, starting to process it.");

            m_ManifestFileList = new ArrayList();
            try
            {
                m_manifest = XElement.Load(LocalManifest);


                // try to get the forum URL

                IEnumerable <XElement> forumLinks = m_manifest.Descendants("webpage");

                foreach (XElement forumLink in forumLinks)
                {
                    ForumURL = forumLink.Value;
                    break;
                }


                SelfPatch();

                m_Status = "Reading manifest";
                IEnumerable <XElement> files = m_manifest.Descendants("file");

                foreach (XElement file in files)
                {
                    if (Kill)
                    {
                        return;
                    }

                    // Lets get this file's manifest information
                    long size;
                    bool parseSucceed = long.TryParse(file.Attribute("size").Value.ToString(), out size);
                    bool Warn         = true;
                    if (file.Attribute("warn") != null)
                    {
                        if (file.Attribute("warn").Value == "no")
                        {
                            Warn = false;
                        }
                    }
                    string md5      = file.Attribute("md5").Value;
                    string fileName = file.Attribute("name").Value;

                    if (fileName.Trim() != "")
                    {
                        Fingerprint ManifestFingerprint = new Fingerprint(PathRoot, fileName, md5, size);
                        ManifestFingerprint.Warn = Warn;

                        IEnumerable <XElement> URLs = file.Descendants("url");

                        foreach (XElement URL in URLs)
                        {
                            ManifestFingerprint.AddDownloadURL(URL.Value.ToString().Trim());
                        }

                        m_ManifestFileList.Add(ManifestFingerprint);
                    }
                }

                m_progress   = 0;
                m_Status     = "Verifying";
                myWorkThread = new Thread(new ThreadStart(Validate));
                myWorkThread.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "WorkThread.ManifestDownloadComplete()");
                string a = ex.Message;
            }
        }
 public override void OnNavigatedTo(MyToolkit.Paging.NavigationEventArgs e)
 {
   base.OnNavigatedTo(e);
   WebViewControl.Navigate(HomeUri);
 }
Esempio n. 27
0
        public void DownloadFiles()
        {
            foreach (Fingerprint file in m_DownloadQueue)
            {
                if (Kill)
                {
                    return;
                }

                HTTP client = new HTTP();

                bool   keepTrying  = true;
                string DownloadURL = file.DownloadURL;;

                while (keepTrying)
                {
                    try
                    {
                        MyToolkit.ActivityLog("Downloading file \"" + file.FullName + "\" from \"" + DownloadURL + "\"");
                        if (client.StartDownload(new AsyncCompletedEventHandler(DownloadFileComplete),
                                                 new DownloadProgressChangedEventHandler(dlProgress),
                                                 DownloadURL,
                                                 file.FullName + ".download"))
                        {
                            m_Status         = "Downloading";
                            m_DownloadActive = true;
                        }
                    }
                    catch (Exception ex) {
                        string er = ex.Message;
                    }

                    m_current = file.FullName;

                    while (client.Active)
                    {
                        if (Kill)
                        {
                            client.CancelDownload();
                            return;
                        }
                        System.Threading.Thread.Sleep(10);
                    }

                    Fingerprint Downloaded = new Fingerprint(file.RootPath, file.FileName + ".download");

                    if (!Downloaded.Equals(file))
                    {
                        // OK this file is no good, delete it.
                        File.Delete(file.FullName + ".download");

                        // lets try a different url...
                        DownloadURL = file.DownloadURL;

                        // Did we get a blank URL?
                        if (DownloadURL == "")
                        {
                            MyToolkit.ActivityLog("Download failed, no more URL's to try from");

                            // OK stop trying and report error...
                            keepTrying = false;

                            string Msg = "Download error: " + file.FileName;
                            if (Downloaded.Size == 0)
                            {
                                Msg += "\r\nWas unable to download file";
                            }
                            else
                            {
                                if (Downloaded.Size != file.Size)
                                {
                                    Msg += "\r\nSize mismatch (" + Downloaded.Size + " vs " + file.Size + ")";
                                }
                                if (Downloaded.Checksum != file.Checksum)
                                {
                                    Msg += "\r\nChecksum Mismatch (" + Downloaded.Checksum + " vs " + file.Checksum + ")";
                                }
                            }
                            if (file.Warn)
                            {
                                m_ErrorLog.Add(Msg);
                            }
                            else
                            {
                                m_WarningLog.Add(Msg);
                            }
                        }
                        else
                        {
                            MyToolkit.ActivityLog("Download failed, trying from a different URL");
                        }
                    }
                    else
                    {
                        if (File.Exists(file.FullName))
                        {
                            File.SetAttributes(file.FullName, File.GetAttributes(file.FullName) & ~FileAttributes.ReadOnly);
                            File.Delete(file.FullName);
                        }

                        // We are done, we dont need to keep trying (infinite loop if we dont set this)
                        keepTrying = false;
                        File.Move(file.FullName + ".download", file.FullName);
                        FlagVerified(file.FullName, file.Size, file.Checksum);
                    }
                }

                m_Downloaded += file.Size;
            }

            m_Status  = "Done";
            m_current = "";
        }
Esempio n. 28
0
 protected override void PrepareViewFirst(MyToolkit.Paging.Frame rootFrame)
 {
     Container.RegisterNavigationService(rootFrame);
 }       
Esempio n. 29
0
        private void timer_Tick(object sender, EventArgs e)
        {
            try
            {
                if (myCopyObj != null)
                {
                    if (myCopyObj.Active)
                    {
                        Progress.Value = myCopyObj.Progress;
                        return;
                    }
                }

                if (myWorker == null)
                {
                    StartUp();
                    return;
                }

                if (myWorker.ForumURL != "" && myWorker.ForumURL != webBrowser1.Tag && myWorker.ForumURL != webBrowser1.Url.AbsoluteUri && !webBrowser1.IsBusy)
                {
                    MyToolkit.ActivityLog("Loading Web Browser URL to: \"" + myWorker.ForumURL + "\"");
                    webBrowser1.Tag = myWorker.ForumURL;
                    webBrowser1.Navigate(myWorker.ForumURL);
                }

                if (myWorker.Manifest != null)
                {
                    if (ListBox1.Items.Count <= 1)
                    {
                        IEnumerable <XElement> Profiles = myWorker.Manifest.Descendants("launch");
                        List <object>          items    = new List <object>();

                        foreach (XElement profile in Profiles)
                        {
                            var landingPage    = profile.Attribute("landingPage");
                            var landingPageUri = new Uri(landingPage?.Value ?? "about:blank");
                            items.Add(new LaunchProfile(profile.Value.ToString().Replace("My App: ", "").Trim(),
                                                        profile.Attribute("exec").Value,
                                                        profile.Attribute("params").Value,
                                                        landingPageUri));
                        }

                        if (DevMode)
                        {
                            Profiles = myWorker.Manifest.Descendants("devlaunch");

                            foreach (XElement profile in Profiles)
                            {
                                var landingPage    = profile.Attribute("landingPage");
                                var landingPageUri = new Uri(landingPage?.Value ?? "about:blank");
                                items.Add(new LaunchProfile(profile.Value.ToString().Replace("My App: ", "").Trim(),
                                                            profile.Attribute("exec").Value,
                                                            profile.Attribute("params").Value,
                                                            landingPageUri));
                            }
                        }

                        ListBox1.DisplayMember = "Text";
                        ListBox1.DataSource    = items;
                        ListBox1.SelectedIndex = 0;
                    }
                }

                Progress.Value = MyToolkit.MinMax(myWorker.CurProgress, 0, 100);
                lblStatus.Text = myWorker.Status + "... " + myWorker.CurFile;

                if (myWorker.Status == "Done")
                {
                    Finish();
                }
            } catch (Exception ex) {
                MyToolkit.ErrorReporter(ex, this.Name + ".Form_Load");
            }
        }
Esempio n. 30
0
 public DownloadItem(ArrayList URL, string filePath)
 {
     m_urls     = URL;
     m_filePath = MyToolkit.ValidPath(filePath);
 }
 public AdMobPlugin(MyToolkit.Paging.Frame frame)
     : base(frame)
 {
 }
Esempio n. 32
0
 private void Form_FormClosing(object sender, FormClosingEventArgs e)
 {
     MyToolkit.ActivityLog("Application quitting");
     WorkThread.Kill = true;
     DirCopy.Kill    = true;
 }
Esempio n. 33
0
        private void ScanParameters()
        {
            if (MyToolkit.AllArgs().Trim() != "")
            {
                MyToolkit.ActivityLog("Launched with following parameters: " + MyToolkit.AllArgs());
            }

            for (int i = 0; i < MyToolkit.args.Length; i++)
            {
                // Check for parameters overriding the download of a new manifest
                if (MyToolkit.args[i].Trim() == "-o")
                {
                    WorkThread.DontDownloadManifest = true;
                }
                // Check for parameters overriding self patching
                else if (MyToolkit.args[i].Trim() == "-noselfpatch" ||
                         MyToolkit.args[i].Trim() == "-noselfupdate" ||
                         MyToolkit.args[i].Trim() == "-nodisassemblejohnny5")
                {
                    WorkThread.DontSelfUpdate = true;
                }
                // Check for parameters overriding self patching
                else if (MyToolkit.args[i].Trim() == "-md5")
                {
                    NoMove = true;
                    WorkThread.DontSelfUpdate = true;
                    //WorkThread.GenerageChecksumToClipboard = true;

                    Fingerprint myFingerprint = new Fingerprint(Application.StartupPath, Application.ExecutablePath.Replace(Application.StartupPath + "\\", ""));
                    Clipboard.SetText("md5=\"" + myFingerprint.Checksum + "\" size=\"" + myFingerprint.Size + "\"");
                }
                // Check for parameters disabling self relocate (this option also makes it not self patch)
                else if (MyToolkit.args[i].Trim() == "-nomove")
                {
                    NoMove = true;
                    WorkThread.DontSelfUpdate = true;
                }
                // Check for parameters disabling self relocate (this option also makes it not self patch)
                else if (MyToolkit.args[i].Trim() == "-devmode" ||
                         MyToolkit.args[i].Trim() == "-dev")
                {
                    DevMode = true;
                }
                // Pick up manifest download override
                else if (MyToolkit.args.Length > i + 1)
                {
                    if (MyToolkit.args[i].Trim() == "-m")
                    {
                        if (MyToolkit.args[i + 1].Trim() == "")
                        {
                            MessageBox.Show("No manifest specified in parameter -m, using default.");
                        }
                        else
                        {
                            ManifestURL = MyToolkit.args[i + 1];

                            // Get a list of currently registered manifests                                 //
                            List <string> Manifests = Settings.Manifests;

                            // Find out if this manifest is already in the list                             //
                            bool ManifestExists = false;
                            foreach (string Manifest in Manifests)
                            {
                                if (Manifest.Equals(ManifestURL, StringComparison.CurrentCultureIgnoreCase))
                                {
                                    ManifestExists = true;
                                    break;
                                }
                            }

                            // If manifest is not in the list, add it                                       //
                            if (!ManifestExists)
                            {
                                Manifests.Add(ManifestURL);
                                Settings.Manifests = Manifests;
                            }

                            // Make this the default manifest                                               //
                            Settings.LastManifest = ManifestURL;
                        }
                    }
                }
            }
        }
 public MusicPlayerPlugin(MyToolkit.Paging.Frame frame)
   : base(frame)
 {
   this.Mp3Player = null;
 }
    public GalleryFilesAction(MyToolkit.Paging.Page page, Windows.UI.Xaml.Controls.WebView webBrowser)
      : base(page, webBrowser)
    {

    }
 public ContactsPlugin(MyToolkit.Paging.Frame frame)
   : base(frame)
 {
 }
 public GalleryFilesPlugin(MyToolkit.Paging.Frame frame)
   : base(frame)
 {
 }