Exemplo n.º 1
0
 protected override void OnOpen(UvArgs args)
 {
     if (args.Successful)
     {
         if (_read.Status == FileStatus.Open)
         {
             _read.Read();
         }
         else if (_read.Status == FileStatus.Closed)
         {
             this.Close();
         }
     }
     else
     {
         _error = args;
         if (_read.Status == FileStatus.Open)
         {
             _read.Close();
         }
     }
 }
Exemplo n.º 2
0
        private void GenerateLang()
        {
            string s = "", st = "", we = "", FolderName = "";

            InfMessageLangBox.Text = "";
            ResourceManager rm         = new ResourceManager("LangpackSuite.myRes", typeof(MainForm).Assembly);
            string          LocaleText = rm.GetString("GenText", culture);

            if (VIURLTextBox.Text.Contains(":\\"))
            {
                vitype = true;
            }
            else
            {
                vitype = false;
            }

            InfMessageLangBox.Text = LocaleText + "\r\n";

            FolderName = Directory.GetParent(Directory.GetParent(exepath).ToString()).ToString() + "\\" + LangpacksComboBox.Text;
            if (!outfile)
            {
                if (LangpackNameEdit.Text.Contains(":\\") || LangpackNameEdit.Text.Contains(".\\"))
                {
                    output = LangpackNameEdit.Text;
                }
                else
                {
                    output = FolderName + "\\" + LangpackNameEdit.Text + ".txt";
                }
            }

            if (File.Exists(output))
            {
                File.Delete(output);
            }

            if (File.Exists(FolderName + "\\=HEAD=.txt"))
            {
                File.Copy(FolderName + "\\=HEAD=.txt", output);
            }
            else
            {
                LocaleText             = rm.GetString("WrongSelect", culture);
                InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                LocaleText             = rm.GetString("HeadNotFound", culture);
                InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                LocaleText             = rm.GetString("GenStop", culture);
                InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText;
                return;
            }

            StreamWriter LangPack = new StreamWriter(output, true);
            StreamReader ReadFile;

            if (GetVICheckBox.Checked && VIURLTextBox.Text != "" && !vitype)
            {
                string FullURL = VIURLTextBox.Text.ToUpper();
                if (!FullURL.StartsWith("HTTP"))
                {
                    FullURL = "HTTP://" + FullURL;
                }
                WebClient wc      = new WebClient();
                byte[]    data    = wc.DownloadData(FullURL.ToLower());
                byte[]    allfile = new byte[data.Length + 3];
                allfile[0] = 239; allfile[1] = 187; allfile[2] = 191;
                data.CopyTo(allfile, 3);
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                string str = Encoding.UTF8.GetString(allfile);
                doc.LoadHtml(str);
                str = doc.DocumentNode.SelectSingleNode("//body").InnerText.Trim();
                FileStream _FileStream = new System.IO.FileStream("VersionInfo.txt", System.IO.FileMode.Create, System.IO.FileAccess.Write);
                allfile = Encoding.UTF8.GetBytes(str);
                _FileStream.Write(allfile, 0, allfile.Length);
                _FileStream.Close();
            }

            string vipath = "";

            if (vitype)
            {
                vipath = VIURLTextBox.Text;
            }
            else
            {
                vipath = Directory.GetCurrentDirectory() + "\\VersionInfo.txt";
            }

            if (File.Exists(vipath))
            {
                LocaleText             = rm.GetString("VIGen", culture);
                InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                LangPack.WriteLine("");
                string     InclPlug = "Plugins-included: ";
                byte[]     buffer   = new byte[3];
                byte[]     bom      = { 239, 187, 191 };
                FileStream rf       = new FileStream(vipath, FileMode.Open, FileAccess.Read);
                rf.Read(buffer, 0, 3);
                rf.Close();
                if (buffer[0] == bom[0] && buffer[1] == bom[1] && buffer[2] == bom[2])
                {
                    ReadFile = new StreamReader(vipath);
                }
                else
                {
                    ReadFile = new StreamReader(vipath, Encoding.Default);
                }
                while ((s = ReadFile.ReadLine()) != null)
                {
                    if (s.StartsWith("Active Plugins"))
                    {
                        s = ReadFile.ReadLine().Trim();
                        while (s != "")
                        {
                            if (s.StartsWith(" ") || s.Contains(".dll"))
                            {
                                int l = s.IndexOf(".");
                                if (s.StartsWith(" "))
                                {
                                    s = s.Substring(2, l - 2);
                                }
                                else
                                {
                                    s = s.Substring(0, l);
                                }
                                if (InclPlug == "Plugins-included: ")
                                {
                                    InclPlug = InclPlug + s;
                                }
                                else
                                {
                                    InclPlug = InclPlug + ", " + s;
                                }
                            }
                            s = ReadFile.ReadLine().Trim();
                        }
                    }
                    if (s.StartsWith("Unloadable Plugins"))
                    {
                        s = ReadFile.ReadLine().Trim();
                        while (s != "")
                        {
                            if (s.StartsWith(" ") || s.Contains("DbChecker.dll"))
                            {
                                int l = s.IndexOf(".");
                                if (s.StartsWith(" "))
                                {
                                    s = s.Substring(2, l - 2);
                                }
                                else
                                {
                                    s = s.Substring(0, l);
                                }
                                if (InclPlug == "Plugins-included: ")
                                {
                                    InclPlug = InclPlug + s;
                                }
                                else
                                {
                                    InclPlug = InclPlug + ", " + s;
                                }
                            }
                            s = ReadFile.ReadLine().Trim();
                        }
                        break;
                    }
                }
                LangPack.WriteLine(InclPlug);
                ReadFile.Close();

                if (OwnFileCheckBox.Checked && OwnFileEdit.Text != "")
                {
                    if (File.Exists(OwnFileEdit.Text))
                    {
                        LangPack.WriteLine("");
                        ReadFile = new StreamReader(OwnFileEdit.Text);
                        while ((s = ReadFile.ReadLine()) != null)
                        {
                            LangPack.WriteLine(s);
                        }
                        ReadFile.Close();
                    }
                    else
                    {
                        int    f    = OwnFileEdit.Text.LastIndexOf('\\');
                        string file = OwnFileEdit.Text.Substring(f + 1);
                        LocaleText = rm.GetString("FileText", culture);
                        string LocaleText2 = rm.GetString("FileNotFound", culture);
                        InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + file + LocaleText2 + "\r\n";
                    }
                }

                LangPack.WriteLine("");
                if (File.Exists(FolderName + "\\=CORE=.txt"))
                {
                    ReadFile = new StreamReader(FolderName + "\\=CORE=.txt");
                    while ((s = ReadFile.ReadLine()) != null)
                    {
                        LangPack.WriteLine(s);
                    }
                    ReadFile.Close();
                }
                else
                {
                    LocaleText             = rm.GetString("CoreNotFound", culture);
                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                    LocaleText             = rm.GetString("GenStop", culture);
                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText;
                    LangPack.Close();
                    ReadFile.Close();
                    return;
                }

                rf = new FileStream(vipath, FileMode.Open, FileAccess.Read);
                rf.Read(buffer, 0, 3);
                rf.Close();
                if (buffer[0] == bom[0] && buffer[1] == bom[1] && buffer[2] == bom[2])
                {
                    ReadFile = new StreamReader(vipath);
                }
                else
                {
                    ReadFile = new StreamReader(vipath, Encoding.Default);
                }
                while ((s = ReadFile.ReadLine()) != null)
                {
                    if (s.StartsWith("Active Plugins"))
                    {
                        s = ReadFile.ReadLine().Trim();
                        while (s != "")
                        {
                            StreamReader plug_in;
                            if (s.StartsWith(" ") || s.Contains(".dll"))
                            {
                                string back_s = s;
                                int    l      = s.IndexOf(".");
                                if (s.StartsWith(" "))
                                {
                                    s = s.Substring(2, l - 2);
                                }
                                else
                                {
                                    s = s.Substring(0, l);
                                }
                                string stmp = s.ToUpper();
                                if (stmp == "IMPORT_SA")
                                {
                                    s = "Import";
                                }
                                if (stmp == "WEATHER")
                                {
                                    LangPack.WriteLine("");
                                    if (File.Exists(FolderName + "\\plugins\\" + s + ".txt"))
                                    {
                                        plug_in = new StreamReader(FolderName + "\\plugins\\" + s + ".txt");
                                        while ((st = plug_in.ReadLine()) != null)
                                        {
                                            LangPack.WriteLine(st);
                                        }
                                        plug_in.Close();
                                    }
                                    else
                                    {
                                        LocaleText = rm.GetString("FileText", culture);
                                        string LocaleText2 = rm.GetString("File2NotFound", culture);
                                        InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + s + LocaleText2 + "\r\n";
                                    }

                                    plug_in = new StreamReader(vipath);
                                    while ((st = plug_in.ReadLine()) != null)
                                    {
                                        if (st.StartsWith("Weather ini files:"))
                                        {
                                            st = plug_in.ReadLine();
                                            st = plug_in.ReadLine();
                                            if (st != "" && st != null)
                                            {
                                                st = st.Trim();
                                            }
                                            while (st != "" && st != null)
                                            {
                                                int w = st.IndexOf(".");
                                                st = st.Substring(0, w);
                                                LangPack.WriteLine("");
                                                if (File.Exists(FolderName + "\\weather\\" + st + ".txt"))
                                                {
                                                    StreamReader weather = new StreamReader(FolderName + "\\weather\\" + st + ".txt");
                                                    while ((we = weather.ReadLine()) != null)
                                                    {
                                                        LangPack.WriteLine(we);
                                                    }
                                                    weather.Close();
                                                }
                                                else
                                                {
                                                    LocaleText = rm.GetString("FileText", culture);
                                                    string LocaleText2 = rm.GetString("File2NotFound", culture);
                                                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + st + LocaleText2 + "\r\n";
                                                }
                                                st = plug_in.ReadLine();
                                            }
                                        }
                                    }
                                    plug_in.Close();
                                    continue;
                                }
                                LangPack.WriteLine("");
                                if (File.Exists(FolderName + "\\plugins\\" + s + ".txt"))
                                {
                                    plug_in = new StreamReader(FolderName + "\\plugins\\" + s + ".txt");
                                    while ((st = plug_in.ReadLine()) != null)
                                    {
                                        LangPack.WriteLine(st);
                                    }
                                    plug_in.Close();
                                }
                                else
                                {
                                    LocaleText = rm.GetString("FileText", culture);
                                    string LocaleText2 = rm.GetString("File2NotFound", culture);
                                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + s + LocaleText2 + "\r\n";
                                }
                            }
                            s = ReadFile.ReadLine().Trim();
                        }
                    }
                    if (s.StartsWith("Unloadable Plugins"))
                    {
                        s = ReadFile.ReadLine().Trim();
                        while (s != "")
                        {
                            StreamReader plug_in;
                            if (s.StartsWith(" ") || s.Contains(".dll"))
                            {
                                string back_s = s;
                                int    l      = s.IndexOf(".");
                                if (s.StartsWith(" "))
                                {
                                    s = s.Substring(2, l - 2);
                                }
                                else
                                {
                                    s = s.Substring(0, l);
                                }
                                LangPack.WriteLine("");
                                if (File.Exists(FolderName + "\\plugins\\" + s + ".txt"))
                                {
                                    plug_in = new StreamReader(FolderName + "\\plugins\\" + s + ".txt");
                                    while ((st = plug_in.ReadLine()) != null)
                                    {
                                        LangPack.WriteLine(st);
                                    }
                                    plug_in.Close();
                                }
                                else
                                {
                                    LocaleText = rm.GetString("FileText", culture);
                                    string LocaleText2 = rm.GetString("File2NotFound", culture);
                                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + s + LocaleText2 + "\r\n";
                                }
                            }
                            s = ReadFile.ReadLine().Trim();
                        }
                        break;
                    }
                }
                ReadFile.Close();
                LangPack.Close();
            }
            else
            {
                LocaleText             = rm.GetString("WOVIGen", culture);
                InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                LangPack.WriteLine("");
                if (File.Exists(FolderName + "\\=VERSION=.txt"))
                {
                    ReadFile = new StreamReader(FolderName + "\\=VERSION=.txt");
                    while ((s = ReadFile.ReadLine()) != null)
                    {
                        LangPack.WriteLine(s);
                    }
                    ReadFile.Close();
                }
                else
                {
                    LocaleText             = rm.GetString("VersionNotFound", culture);
                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                }

                if (OwnFileCheckBox.Checked && OwnFileEdit.Text != "")
                {
                    if (File.Exists(OwnFileEdit.Text))
                    {
                        LangPack.WriteLine("");
                        ReadFile = new StreamReader(OwnFileEdit.Text);
                        while ((s = ReadFile.ReadLine()) != null)
                        {
                            LangPack.WriteLine(s);
                        }
                        ReadFile.Close();
                    }
                    else
                    {
                        int    f    = OwnFileEdit.Text.LastIndexOf('\\');
                        string file = OwnFileEdit.Text.Substring(f + 1);
                        LocaleText = rm.GetString("FileText", culture);
                        string LocaleText2 = rm.GetString("FileNotFound", culture);
                        InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + file + LocaleText2 + "\r\n";
                    }
                }

                LangPack.WriteLine("");
                if (File.Exists(FolderName + "\\=CORE=.txt"))
                {
                    ReadFile = new StreamReader(FolderName + "\\=CORE=.txt");
                    while ((s = ReadFile.ReadLine()) != null)
                    {
                        LangPack.WriteLine(s);
                    }
                    ReadFile.Close();
                }
                else
                {
                    LocaleText             = rm.GetString("CoreNotFound", culture);
                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                    LocaleText             = rm.GetString("GenStop", culture);
                    InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText;
                    LangPack.Close();
                    return;
                }

                DirectoryInfo PluginsDir = new DirectoryInfo(FolderName + "\\Plugins");
                foreach (FileInfo fi in PluginsDir.GetFiles())
                {
                    string stmp = fi.Name.ToUpper();
                    if (stmp == "WEATHER.TXT")
                    {
                        LangPack.WriteLine("");
                        ReadFile = new StreamReader(fi.FullName);
                        while ((s = ReadFile.ReadLine()) != null)
                        {
                            LangPack.WriteLine(s);
                        }
                        ReadFile.Close();

                        DirectoryInfo WeatherDir = new DirectoryInfo(FolderName + "\\Weather");
                        if (Directory.Exists(WeatherDir.ToString()))
                        {
                            foreach (FileInfo wi in WeatherDir.GetFiles())
                            {
                                LangPack.WriteLine("");
                                ReadFile = new StreamReader(wi.FullName);
                                while ((s = ReadFile.ReadLine()) != null)
                                {
                                    LangPack.WriteLine(s);
                                }
                                ReadFile.Close();
                            }
                        }
                        else
                        {
                            LocaleText             = rm.GetString("WeatherLinkNotFound", culture);
                            InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText + "\r\n";
                        }
                        continue;
                    }
                    LangPack.WriteLine("");
                    ReadFile = new StreamReader(fi.FullName);
                    while ((s = ReadFile.ReadLine()) != null)
                    {
                        LangPack.WriteLine(s);
                    }
                    ReadFile.Close();
                }
                LangPack.Close();
            }

            if (!quiet)
            {
                LocaleText             = rm.GetString("Done", culture);
                InfMessageLangBox.Text = InfMessageLangBox.Text + LocaleText;
                string LocaleText3 = rm.GetString("Inf", culture);
                MessageBox.Show(LocaleText, LocaleText3, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }