Пример #1
0
        public ModInfo(Mod mod)
        {
            InitializeComponent();

            WebClient c = new WebClient();

            receivedMod = mod;
            string modName = mod.modName.Replace("&&", "&");

            this.Text     = "Мод " + modName;
            textBox1.Font = Vars.MAINFONT;

            #region description file
            try
            {
                string filename         = Vars.ParseModFileName(modName) + "-dscr.txt";
                string str              = "mods\\" + filename;
                bool   isModsfileExists = true;

                if (!File.Exists(str))
                {
                    isModsfileExists = false;
                    FileStream f = File.Create(str);
                    f.Close();
                }

                if (isModsfileExists || Vars.updateCache)
                {
                    c.DownloadFile("https://theminemods.000webhostapp.com/mods/" + filename, str);
                }

                modDescription = File.ReadAllLines(str);
            }
            catch (PathTooLongException)
            {
                _ = MessageBox.Show("Слишком длинный путь до файла описания!\n" +
                                    "Запустите программу в каталоге выше.",
                                    "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                Close();
            }
            catch (FileNotFoundException)
            {
                _ = MessageBox.Show("Не найден файл описания!\n\n" +
                                    "Попробуйте перезапустить программу.\n" +
                                    "Если это не поможет, передайте разработчику код ошибки:\n" +
                                    "MINEMODS_FILENOTFOUNDEXCEPTION",
                                    "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
            }
            catch (DirectoryNotFoundException)
            {
                _ = Directory.CreateDirectory("mods");
                _ = MessageBox.Show("Не найден каталог с файлами описания!\n\n" +
                                    "Проблема должна быть уже решена автоматически.\n" +
                                    "Перезапустите программу.\n" +
                                    "Если это не поможет, передайте разработчику код ошибки:\n" +
                                    "MINEMODS_DIRNOTFOUNDEXCEPTION",
                                    "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                Close();
            }
            catch (WebException)
            {
                _ = MessageBox.Show("Ошибка получения файла описания с удалённого сервера!\n\n" +
                                    "Проверьте своё интернет-соединение и перезапустите программу.\n" +
                                    "Также возможно, что файла описания для этого мода ещё нет.\n\n" +
                                    "Если Вам нужно описание, напишите разработчику письмо\n" +
                                    "с темой кода проблемы:\n" +
                                    "MINEMODS_FILEONSERVERNOTFOUND <название мода>",
                                    "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
            }
            catch (System.Security.SecurityException)
            {
                _ = MessageBox.Show("Ошибка безопасности!\n\n" +
                                    "Попробуйте перезапустить программу.\n" +
                                    "Если это не поможет, передайте разработчику код ошибки:\n" +
                                    "MINEMODS_SECURITYEXCEPTION",
                                    "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
            }
            catch (IOException)
            {
                _ = MessageBox.Show("Не удалось прочитать файл описания!\n\n" +
                                    "Попробуйте перезапустить программу.\n" +
                                    "Если это не поможет, передайте разработчику код ошибки:\n" +
                                    "MINEMODS_UNKNOWNIOEXCEPTION",
                                    "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                _ = MessageBox.Show("Критическая ошибка!\n\n" +
                                    "Попробуйте перезапустить программу.\n" +
                                    "Если это не поможет, передайте разработчику код ошибки:\n" +
                                    "MINEMODS_CRITUNKNOWNEXCEPTION",
                                    "Ошибка", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
            }
            #endregion

            #region picture
            if (modDescription != null)
            {
                textBox1.Lines = modDescription;
                string filename = Vars.ParseModFileName(modName) + "-icon";
                string str      = "mods\\" + filename;

                int           i        = 0;
                List <string> pictexts = new List <string>()
                {
                    ".png", ".jpg", ".gif", ".bmp"
                };
                foreach (String ext in pictexts)
                {
                    if (File.Exists(str + ext) && !(Vars.updateCache))
                    {
                        pictureBox1.Load(str + ext);
                        break;
                    }
                    else
                    {
                        try
                        {
                            FileStream f = File.Create(str + ext);
                            f.Close();

                            c.DownloadFile("https://theminemods.000webhostapp.com/mods/" + filename + ext, str + ext);
                            pictureBox1.Load(str + ext);

                            break;
                        }
                        catch (WebException)
                        {
                            if (i == (pictexts.Count - 1))
                            {
                                _ = MessageBox.Show("Ошибка получения картинки с удалённого сервера!\n\n" +
                                                    "Проверьте своё интернет-соединение.\n" +
                                                    "Также возможно, картинки для этого мода пока что нет.\n\n" +
                                                    "Если Вам нужна картинка, напишите разработчику письмо\n" +
                                                    "с темой кода проблемы:\n" +
                                                    "MINEMODS_PICTURENOTFOUND <название мода>",
                                                    "Ошибка", MessageBoxButtons.OK,
                                                    MessageBoxIcon.Warning);
                            }
                        }
                    }

                    i++;
                }
            }
            #endregion

            if (mod.dlLink != null)
            {
                скачатьToolStripMenuItem.Click += new EventHandler(DownloadMod);
                скачатьВОбычномФорматеjarToolStripMenuItem.Click += new EventHandler(DownloadMod);
                скачатьВZipархивеzipToolStripMenuItem.Click      += new EventHandler(DownloadModInZip);
            }
        }
Пример #2
0
        private void button10_Click(object sender, EventArgs e)
        {
            string dscrFilepath = "";
            string pictFilepath = "";
            string dscrFilename = "";
            string pictFilename = "";

            string strToWrite = "";

            FtpAuthForm ftpauth = new FtpAuthForm();

            ftpauth.ShowDialog();

            #region checking options - is empty?
            if (textBox7.Text == "")
            {
                _ = MessageBox.Show("Введите название мода!", "Ошибка",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (comboBox1.Text == "" && comboBox2.Text == "")
            {
                _ = MessageBox.Show("Выберите категорию мода!", "Ошибка",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                strToWrite = textBox7.Text + ";" + comboBox1.Text + "," + comboBox2.Text;
            }

            if (textBox8.Text == "")
            {
                string warnboxres = MessageBox.Show("Вы не указали ссылку для скачивания этой модификации.\nПродолжить?",
                                                    "Предупреждение",
                                                    MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Warning).ToString();
                if (warnboxres == "No")
                {
                    return;
                }
            }
            else
            {
                strToWrite += ";" + textBox8.Text;
            }
            #endregion

            #region saving description and picture
            dscrFilename = Vars.ParseModFileName(textBox7.Text) + "-dscr.txt";
            dscrFilepath = "mods\\" + dscrFilename;
            File.WriteAllLines(dscrFilepath, textBox9.Lines);
            if (modImagePath != "")
            {
                string[] imgpathSubstrs = modImagePath.Split('.');
                pictFilename = Vars.ParseModFileName(textBox7.Text) + "-icon." +
                               imgpathSubstrs[imgpathSubstrs.Length - 1];
                pictFilepath = "mods\\" + pictFilename;
                File.Copy(modImagePath, pictFilepath);
            }
            #endregion

            if (comboBox1.Text != "" || comboBox2.Text != "")
            {
                File.AppendAllText("mods.txt", strToWrite + "\r\n");
            }

            #region uploading files to ftp-server
            try
            {
                //modsfile
                FtpWebRequest reqModsfile = (FtpWebRequest)WebRequest.Create(
                    "ftp://files.000webhost.com:21/public_html/mods/mods.txt");
                reqModsfile.Method      = WebRequestMethods.Ftp.UploadFile;
                reqModsfile.Credentials = new NetworkCredential(login, password);

                FileStream fsMods       = new FileStream("mods.txt", FileMode.Open);
                byte[]     fileContents = new byte[fsMods.Length];
                fsMods.Read(fileContents, 0, fileContents.Length);
                fsMods.Close();
                reqModsfile.ContentLength = fileContents.Length;

                Stream reqModsfileStream = reqModsfile.GetRequestStream();
                reqModsfileStream.Write(fileContents, 0, fileContents.Length);
                reqModsfileStream.Close();

                //description
                FtpWebRequest reqDscr = (FtpWebRequest)WebRequest.Create(
                    "ftp://files.000webhost.com:21/public_html/mods/" + dscrFilename);
                reqDscr.Method      = WebRequestMethods.Ftp.UploadFile;
                reqDscr.Credentials = new NetworkCredential(login, password);

                FileStream fsDscr = new FileStream(dscrFilepath, FileMode.Open);
                fileContents = new byte[fsDscr.Length];
                fsDscr.Read(fileContents, 0, fileContents.Length);
                fsDscr.Close();
                reqDscr.ContentLength = fileContents.Length;

                Stream reqDscrFileStream = reqDscr.GetRequestStream();
                reqDscrFileStream.Write(fileContents, 0, fileContents.Length);
                reqDscrFileStream.Close();

                //picture
                FtpWebRequest reqPict = (FtpWebRequest)WebRequest.Create(
                    "ftp://files.000webhost.com:21/public_html/mods/" + pictFilename);
                reqPict.Method      = WebRequestMethods.Ftp.UploadFile;
                reqPict.Credentials = new NetworkCredential(login, password);

                FileStream fsPict = new FileStream(pictFilepath, FileMode.Open);
                fileContents = new byte[fsPict.Length];
                fsPict.Read(fileContents, 0, fileContents.Length);
                fsPict.Close();
                reqPict.ContentLength = fileContents.Length;

                Stream reqPictFileStream = reqPict.GetRequestStream();
                reqPictFileStream.Write(fileContents, 0, fileContents.Length);
                reqPictFileStream.Close();
            }
            catch (Exception ex)
            {
                _ = MessageBox.Show(ex.ToString(), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            #endregion

            _ = MessageBox.Show("Готово!");
        }