public static void LaunchSelfUpdate()
        {
            Process          process   = null;
            ProcessStartInfo startInfo = new ProcessStartInfo
            {
                FileName = FileIO.AddSlash(MyProject.Application.Info.DirectoryPath) + "MHDLoader.exe"
            };

            if (Environment.OSVersion.Version.Major >= 6)
            {
                startInfo.Verb = "runas";
            }
            startInfo.Arguments       = "";
            startInfo.WindowStyle     = ProcessWindowStyle.Normal;
            startInfo.UseShellExecute = true;
            try
            {
                process = Process.Start(startInfo);
            }
            catch (Exception ex)
            {
                Exception ex2 = ex;
                MessageBox.Show(ex2.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            finally
            {
                if (process != null)
                {
                    process.Dispose();
                }
            }
        }
        private void btnIcon_Click(object sender, EventArgs e)
        {
            if (Loading)
            {
                return;
            }
            ImagePicker.InitialDirectory = I9Gfx.GetPowersetsPath();
            ImagePicker.FileName         = myPS.ImageName;
            if (ImagePicker.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var str = FileIO.StripPath(ImagePicker.FileName);

            if (!File.Exists(FileIO.AddSlash(ImagePicker.InitialDirectory) + str))
            {
                MessageBox.Show(
                    $"You must select an image from the {I9Gfx.GetPowersetsPath()} folder!\r\n\r\nIf you are adding a new image, you should copy it the folder and then select it.",
                    "Ah...", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                myPS.ImageName = str;
                DisplayIcon();
            }
        }
Beispiel #3
0
    public static string StripFileName(string iFileName)
    {
        int    length = iFileName.LastIndexOf("\\", StringComparison.Ordinal);
        string result;

        if (length > -1)
        {
            result = iFileName.Substring(0, length);
        }
        else
        {
            result = FileIO.AddSlash(iFileName);
        }
        return(result);
    }
Beispiel #4
0
        private static void GetAccessCode()
        {
            try
            {
                var isCompleted = false;
                using var listener = new HttpListener();
                listener.Prefixes.Add("http://localhost:60403/");
                listener.Start();
                while (!isCompleted)
                {
                    byte[] page;
                    var    result   = listener.GetContext();
                    var    request  = result.Request;
                    var    response = result.Response;
                    if (request.Url.Query.Contains("access_denied"))
                    {
                        page = File.ReadAllBytes($"{FileIO.AddSlash(Application.StartupPath)}Web\\unauthorized.html");
                        response.ContentLength64 = page.Length;
                        var output = response.OutputStream;
                        output.Write(page, 0, page.Length);
                        isCompleted = true;
                    }
                    else if (request.Url.Query.Contains("?code="))
                    {
                        page = File.ReadAllBytes($"{FileIO.AddSlash(Application.StartupPath)}Web\\authorized.html");
                        response.ContentLength64 = page.Length;
                        var output = response.OutputStream;
                        output.Write(page, 0, page.Length);
                        var accessCode = request.Url.Query.Replace("?code=", "");
                        RequestToken(accessCode);
                        isCompleted = true;
                    }
                }

                listener.Stop();
            }
            catch (HttpListenerException)
            {
                //Nothing to see here
            }
        }
 void btnImage_Click(object sender, EventArgs e)
 {
     if (!this.Loading)
     {
         this.ImagePicker.InitialDirectory = I9Gfx.GetEnhancementsPath();
         this.ImagePicker.FileName         = this.mySet.Image;
         if (this.ImagePicker.ShowDialog() == DialogResult.OK)
         {
             string str = FileIO.StripPath(this.ImagePicker.FileName);
             if (!File.Exists(FileIO.AddSlash(this.ImagePicker.InitialDirectory) + str))
             {
                 Interaction.MsgBox("You must select an image from the " + I9Gfx.GetEnhancementsPath() + " folder!\r\n\r\nIf you are adding a new image, you should copy it to the folder and then select it.", MsgBoxStyle.Information, "Ah...");
             }
             else
             {
                 this.mySet.Image = str;
                 this.DisplayIcon();
             }
         }
     }
 }
Beispiel #6
0
    static bool FolderCopy(DirectoryInfo iDi, string dest)

    {
        DirectoryInfo[] directories = iDi.GetDirectories();
        FileInfo[]      files       = iDi.GetFiles();
        if (!Directory.Exists(dest))
        {
            try
            {
                Directory.CreateDirectory(dest);
            }
            catch (Exception ex)
            {
                int num = (int)MessageBox.Show("An error has occured when copying the folder. Error: " + ex.Message);
                return(false);
            }
        }
        for (int index = 0; index <= directories.Length - 1; ++index)
        {
            if (!FileIO.FolderCopy(directories[index], FileIO.AddSlash(dest) + directories[index].Name))
            {
                return(false);
            }
        }
        dest = FileIO.AddSlash(dest);
        for (int index = 0; index <= files.Length - 1; ++index)
        {
            try
            {
                files[index].CopyTo(dest + files[index].Name);
            }
            catch (Exception ex)
            {
                int num = (int)MessageBox.Show("An error has occured when copying the folder. Error: " + ex.Message);
                return(false);
            }
        }
        return(true);
    }
Beispiel #7
0
        void btnIcon_Click(object sender, EventArgs e)
        {
            if (Loading)
            {
                return;
            }
            ImagePicker.InitialDirectory = I9Gfx.GetPowersetsPath();
            ImagePicker.FileName         = myPS.ImageName;
            if (ImagePicker.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            string str = FileIO.StripPath(ImagePicker.FileName);

            if (!File.Exists(FileIO.AddSlash(ImagePicker.InitialDirectory) + str))
            {
                int num = (int)Interaction.MsgBox(("You must select an image from the " + I9Gfx.GetPowersetsPath() + " folder!\r\n\r\nIf you are adding a new image, you should copy it to the folder and then select it."), MsgBoxStyle.Information, "Ah...");
            }
            else
            {
                myPS.ImageName = str;
                DisplayIcon();
            }
        }
 public static string ImagePath()
 {
     return(FileIO.AddSlash(Application.StartupPath) + "Images\\");
 }
    public static string StripFileName(string iFileName)
    {
        int length = iFileName.LastIndexOf("\\", StringComparison.Ordinal);

        return(length <= -1 ? FileIO.AddSlash(iFileName) : iFileName.Substring(0, length));
    }
        bool RequestWithProgress(ref int updateId)
        {
            bool flag = false;

            byte[]       buffer       = new byte[16385];
            int          count        = 16384;
            FileStream   fileStream   = null;
            BinaryWriter binaryWriter = null;
            string       str          = FileIO.AddSlash(MyProject.Application.Info.DirectoryPath) + "Autoupdate.tmp";

            this.SetMessage("Requesting file: ", this.Updates[updateId].DisplayName);
            if (File.Exists(str))
            {
                File.Delete(str);
            }
            HttpWebResponse httpWebResponse = null;
            Stream          input           = null;
            BinaryReader    binaryReader    = null;

            try
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.Updates[updateId].SourceURI);
                httpWebRequest.Timeout      = 20000;
                httpWebResponse             = (HttpWebResponse)httpWebRequest.GetResponse();
                this.Updates[updateId].Size = (int)httpWebResponse.ContentLength;
                try
                {
                    fileStream   = new FileStream(str, FileMode.Create);
                    binaryWriter = new BinaryWriter(fileStream);
                }
                catch (Exception ex)
                {
                    Exception exception = ex;
                    if (httpWebResponse != null)
                    {
                        httpWebResponse.Close();
                    }
                    this.HideMessage();
                    if (!(!exception.Message.Contains("404") & !(exception.Message.ToLower().Contains("time") & exception.Message.ToLower().Contains("out")) & !exception.Message.Contains("resolved")))
                    {
                        string str2;
                        if (exception.Message.ToLower().Contains("time") & exception.Message.ToLower().Contains("out"))
                        {
                            str2 = "Unable to download update. The conenction timed out. The server may be busy. Please try again later.";
                        }
                        else if (exception.Message.Contains("404"))
                        {
                            str2 = "Unable to download update. The update package wasn't found on the server. If this problem persists, please submit a bug report from the Help menu.";
                        }
                        else
                        {
                            if (!exception.Message.Contains("resolved"))
                            {
                                Interaction.MsgBox(string.Concat(new string[]
                                {
                                    "Unable to download ",
                                    this.Updates[updateId].DisplayName,
                                    "\r\nError: ",
                                    exception.Message,
                                    OS.VistaUacErrorText(),
                                    "\r\n\r\nYou will now be directed to the bug report page. If this problem is a known issue, there will be instructions there for applying the update manually."
                                }), MsgBoxStyle.Exclamation, "Update Error");
                                clsXMLUpdate.BugReport("Request." + this.Updates[updateId].DisplayName + "." + exception.Message);
                                flag = false;
                                return(flag);
                            }
                            str2 = "Unable to download update. The conenction to the server could not be established. Please try again later.";
                        }
                        Interaction.MsgBox(str2, MsgBoxStyle.Exclamation, "Update Error");
                        flag = false;
                        return(flag);
                    }
                }
                try
                {
                    bool   flag2    = false;
                    string messageA = "Initiating Download...";
                    this.SetMessage(messageA, "");
                    int num = 0;
                    input        = httpWebResponse.GetResponseStream();
                    binaryReader = new BinaryReader(input);
                    if (num < this.Updates[updateId].Size)
                    {
                        flag2 = true;
                    }
                    while (flag2)
                    {
                        if (num + count > this.Updates[updateId].Size)
                        {
                            count = this.Updates[updateId].Size - num;
                        }
                        buffer = binaryReader.ReadBytes(count);
                        num   += count;
                        binaryWriter.Write(buffer);
                        flag2 = (num < this.Updates[updateId].Size);
                        this.SetMessage("Downloading: " + Strings.Format((double)num / (double)this.Updates[updateId].Size * 100.0, "##0") + "%", string.Concat(new string[]
                        {
                            "(",
                            Strings.Format((int)Math.Round((double)num / 1024.0), "###,##0"),
                            " of ",
                            Strings.Format((int)Math.Round((double)this.Updates[updateId].Size / 1024.0), "###,##0"),
                            "KB) Done."
                        }));
                        Application.DoEvents();
                    }
                    if (binaryReader != null)
                    {
                        binaryReader.Close();
                    }
                    if (input != null)
                    {
                        input.Close();
                    }
                    if (httpWebResponse != null)
                    {
                        httpWebResponse.Close();
                    }
                    if (input != null)
                    {
                        input.Close();
                    }
                    if (binaryWriter != null)
                    {
                        binaryWriter.Close();
                    }
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                    if (File.Exists(this.Updates[updateId].LocalDest))
                    {
                        File.Delete(this.Updates[updateId].LocalDest);
                    }
                    File.Move(str, this.Updates[updateId].LocalDest);
                    return(true);
                }
                catch (Exception ex2)
                {
                    Exception exception2 = ex2;
                    if (binaryReader != null)
                    {
                        binaryReader.Close();
                    }
                    if (input != null)
                    {
                        input.Close();
                    }
                    if (httpWebResponse != null)
                    {
                        httpWebResponse.Close();
                    }
                    if (input != null)
                    {
                        input.Close();
                    }
                    if (binaryWriter != null)
                    {
                        binaryWriter.Close();
                    }
                    if (fileStream != null)
                    {
                        fileStream.Close();
                    }
                    this.HideMessage();
                    if (exception2.Message.ToLower().Contains("time") & exception2.Message.ToLower().Contains("out"))
                    {
                        string str2 = "Unable to download update. The conenction timed out. The server may be busy. Please try again later.";
                        Interaction.MsgBox(str2, MsgBoxStyle.Exclamation, "Update Error");
                    }
                    else
                    {
                        Interaction.MsgBox(string.Concat(new string[]
                        {
                            "Unable to download ",
                            this.Updates[updateId].DisplayName,
                            "\r\nError: ",
                            exception2.Message,
                            OS.VistaUacErrorText(),
                            "\r\n\r\nYou will now be directed to the bug report page. If this problem is a known issue, there will be instructions there for applying the update manually."
                        }), MsgBoxStyle.Exclamation, "Update Error");
                        clsXMLUpdate.BugReport("RWP." + this.Updates[updateId].DisplayName + "." + exception2.Message);
                    }
                    flag = false;
                    return(flag);
                }
            }
            catch (Exception ex3)
            {
                Exception exception3 = ex3;
                if (binaryReader != null)
                {
                    binaryReader.Close();
                }
                if (input != null)
                {
                    input.Close();
                }
                if (httpWebResponse != null)
                {
                    httpWebResponse.Close();
                }
                if (input != null)
                {
                    input.Close();
                }
                if (binaryWriter != null)
                {
                    binaryWriter.Close();
                }
                if (fileStream != null)
                {
                    fileStream.Close();
                }
                this.HideMessage();
                if (exception3.Message.ToLower().Contains("time") & exception3.Message.ToLower().Contains("out"))
                {
                    string str2 = "Unable to download update. The conenction timed out. The server may be busy. Please try again later.";
                    Interaction.MsgBox(str2, MsgBoxStyle.Exclamation, "Update Error");
                }
                else if (exception3.Message.Contains("404"))
                {
                    string str2 = "Unable to download update. The update package wasn't found on the server. If this problem persists, please submit a bug report from the Help menu.";
                    Interaction.MsgBox(str2, MsgBoxStyle.Exclamation, "Update Error");
                }
                else if (exception3.Message.Contains("resolved"))
                {
                    string str2 = "Unable to download update. The conenction to the server could not be established. Please try again later.";
                    Interaction.MsgBox(str2, MsgBoxStyle.Exclamation, "Update Error");
                }
                else
                {
                    Interaction.MsgBox(string.Concat(new string[]
                    {
                        "Unable to download ",
                        this.Updates[updateId].DisplayName,
                        "\r\nError: ",
                        exception3.Message,
                        OS.VistaUacErrorText(),
                        "\r\n\r\nYou will now be directed to the bug report page. If this problem is a known issue, there will be instructions there for applying the update manually."
                    }), MsgBoxStyle.Exclamation, "Update Error");
                    clsXMLUpdate.BugReport("RWP." + this.Updates[updateId].DisplayName + "." + exception3.Message);
                }
                flag = false;
            }
            return(flag);
        }
        bool ReadXMLString(ref clsXMLUpdate.clsXMLItem item, string xmlString)
        {
            bool flag;

            try
            {
                StringReader  input         = new StringReader(xmlString);
                XmlTextReader xmlTextReader = new XmlTextReader(input);
                if (xmlTextReader.IsStartElement("Planner"))
                {
                    xmlTextReader.MoveToAttribute("Version");
                    if (xmlTextReader.ReadAttributeValue())
                    {
                        Conversion.Val(xmlTextReader.Value);
                    }
                }
                int num = 0;
                do
                {
                    xmlTextReader.Read();
                    if (!(xmlTextReader.Name != item.NodeName))
                    {
                        break;
                    }
                    num++;
                }while (num <= 50);
                xmlTextReader.ReadStartElement(item.NodeName);
                xmlTextReader.ReadStartElement("Name");
                item.DisplayName = xmlTextReader.ReadString();
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("URI");
                item.SourceURI = xmlTextReader.ReadString();
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("LocalDest");
                item.LocalDest = FileIO.AddSlash(MyProject.Application.Info.DirectoryPath) + xmlTextReader.ReadString();
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("Size");
                item.Size = (int)Math.Round(Conversion.Val(xmlTextReader.ReadString().Replace(",", "").Replace(".", "")));
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("Version");
                item.Version = (float)Conversion.Val(xmlTextReader.ReadString());
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("Date");
                string[] strArray = xmlTextReader.ReadString().Split("/".ToCharArray());
                if (strArray[2].Length == 2)
                {
                    strArray[2] = "20" + strArray[2];
                }
                item.VersionDate = new DateTime(Conversions.ToInteger(strArray[2]), Conversions.ToInteger(strArray[1]), Conversions.ToInteger(strArray[0]));
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("Restart");
                string str = xmlTextReader.ReadString();
                item.Restart = (str == "YES" | str == "1");
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("Manual");
                string str2 = xmlTextReader.ReadString();
                item.Manual = (str2 == "YES" | str2 == "1");
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadStartElement("Notes");
                item.Notes = xmlTextReader.ReadString().Replace("^", "\r\n");
                xmlTextReader.ReadEndElement();
                xmlTextReader.ReadEndElement();
                xmlTextReader.Close();
                flag = true;
            }
            catch (Exception ex)
            {
                flag = false;
            }
            return(flag);
        }