コード例 #1
0
        private void Start()
        {
            if (Prepare())
            {
                return;
            }
            AddedModStringBuilder.Clear();
            List<String> files = GetModFiles();
            StatusLabel.Text = "Finding Files";
            while (String.IsNullOrWhiteSpace(_modpackName))
            {
                _modpackName = Prompt.ShowDialog("What is the Modpack Name?", "Modpack Name");
            }
            while (String.IsNullOrWhiteSpace(_modpackVersion))
            {
                _modpackVersion = Prompt.ShowDialog("What Version is the modpack?", "Modpack Version");
            }
            if (String.IsNullOrWhiteSpace(_modpackArchive))
            {
                _modpackArchive = Path.Combine(_outputDirectory, String.Format("{0}-{1}.zip", _modpackName, _modpackVersion));
            }
            _ftbModpackArchive = Path.Combine(_outputDirectory, _modpackName + "-" + _modpackVersion + "-FTB" + ".zip");

            if (String.IsNullOrWhiteSpace(_currentMcVersion))
            {
                Mcselector selector = new Mcselector(this);
                selector.ShowDialog();
            }

            if (useSolder.Checked)
            {
                initializeSolderSqlHandler();
            }

            _processesUsingModID.Clear();

            List<Mcmod> modsList = new List<Mcmod>(_totalMods);
            toolStripProgressBar.Value = 0;
            toolStripProgressBar.Maximum = _totalMods;
            //Check if files have already been added
            foreach (String file in files)
            {
                Debug.WriteLine("");
                _currentMod++;
                toolStripProgressBar.Increment(1);
                if (IsWierdMod(file) == 0)
                {
                    continue;
                }
                // ReSharper disable once InconsistentNaming
                var FileName = file.Substring(file.LastIndexOf(Globalfunctions.PathSeperator) + 1);
                //Check for mcmod.info
                StatusLabel.Text = FileName;
                Directory.CreateDirectory(_outputDirectory);
                Mcmod tmpMod = _modsSqLhelper.GetModInfo(SqlHelper.CalculateMd5(file));
                if (tmpMod != null)
                {
                    if (missingInfoActionOnTheRun.Checked)
                    {
                        if (IsFullyInformed(tmpMod))
                        {
                            if (CreateTechnicPack.Checked)
                            {
                                CreateTechnicModZip(tmpMod, file);
                            }
                            if (CreateFTBPack.Checked)
                            {
                                CreateFtbPackZip(tmpMod, file);
                            }
                        }
                        else
                        {
                            RequireUserInfo(tmpMod, file);
                        }
                    }
                    else
                    {
                        tmpMod.Filename = FileName;
                        tmpMod.Path = file;
                        modsList.Add(tmpMod);
                    }
                    continue;
                }
                String arguments;
                if (Globalfunctions.IsUnix())
                {
                    _startInfo.FileName = "unzip";
                    arguments = string.Format("-o \"{0}\" \"*.info\" \"*.json\" -d \"{1}\"", file, _outputDirectory);
                }
                else
                {
                    arguments = string.Format("e -y -o\"{0}\" \"{1}\" *.info litemod.json", _outputDirectory, file);
                }
                _startInfo.Arguments = arguments;

                _process.StartInfo = _startInfo;
                _process.Start();
                _process.WaitForExit();
                String mcmodfile = Path.Combine(_outputDirectory, "mcmod.info");
                String litemodfile = Path.Combine(_outputDirectory, "litemod.json");
                if (File.Exists(litemodfile))
                {
                    if (File.Exists(mcmodfile))
                    {
                        File.Delete(mcmodfile);
                    }
                    File.Move(litemodfile, mcmodfile);
                }
                if (!File.Exists(mcmodfile))
                {
                    foreach (String modinfofile in Directory.GetFiles(_outputDirectory, "*.info"))
                    {
                        if (modinfofile.ToLower().Contains("dependancies") ||
                            modinfofile.ToLower().Contains("dependencies"))
                            File.Delete(modinfofile);
                        else
                        {
                            if (!File.Exists(mcmodfile))
                                File.Move(modinfofile, mcmodfile);
                            else
                            {
                                File.Delete(mcmodfile);
                                File.Move(modinfofile, mcmodfile);
                            }
                        }
                    }
                }

                if (File.Exists(mcmodfile))
                {

                    //If exist, then read info and make zip file
                    String json;
                    using (StreamReader r = new StreamReader(mcmodfile))
                    {
                        json = r.ReadToEnd();
                    }
                    try
                    {
                        try
                        {
                            Mcmod2 modinfo2;
                            try
                            {
                                modinfo2 = JsonConvert.DeserializeObject<Mcmod2>(json);
                            }
                            catch (JsonReaderException)
                            {
                                MessageBox.Show(string.Format("Something is wrong with the Json in {0}", FileName));
                                throw new JsonSerializationException("Invalid Json in file" + FileName);
                            }

                            Mcmod mod = new Mcmod();

                            if (modinfo2.Modinfoversion != 0 && modinfo2.Modinfoversion > 1 || modinfo2.ModListVersion != 0 && modinfo2.ModListVersion > 1)
                            {
                                mod.Mcversion = modinfo2.Modlist[0].Mcversion;
                                mod.Modid = modinfo2.Modlist[0].Modid;
                                mod.Name = modinfo2.Modlist[0].Name;
                                mod.Version = modinfo2.Modlist[0].Version;
                                mod.Authors = modinfo2.Modlist[0].Authors;
                                mod.Description = modinfo2.Modlist[0].Description;
                                mod.Url = modinfo2.Modlist[0].Url;
                                if (missingInfoActionOnTheRun.Checked)
                                {
                                    RequireUserInfo(mod, file);
                                }
                                else
                                {
                                    mod.Filename = FileName;
                                    mod.Path = file;
                                    modsList.Add(mod);
                                }
                            }
                            else
                            {
                                throw new JsonSerializationException();
                            }
                        }
                        catch (JsonSerializationException)
                        {
                            try
                            {
                                List<Mcmod> modinfo;
                                try
                                {
                                    modinfo = JsonConvert.DeserializeObject<List<Mcmod>>(json);
                                }
                                catch (JsonReaderException)
                                {
                                    MessageBox.Show(string.Format("Something is wrong with the Json in {0}", FileName));
                                    throw new JsonSerializationException("Invalid Json in file" + FileName);
                                }
                                var mod = modinfo[0];
                                if (!String.IsNullOrWhiteSpace(mod.Version))
                                {
                                    mod.Version = mod.Version.Replace(" ", "-");
                                }
                                if (missingInfoActionOnTheRun.Checked)
                                {
                                    if (IsFullyInformed(mod))
                                    {
                                        if (CreateTechnicPack.Checked)
                                        {
                                            CreateTechnicModZip(mod, file);
                                        }
                                        if (CreateFTBPack.Checked)
                                        {
                                            CreateFtbPackZip(mod, file);
                                        }
                                    }
                                    else
                                    {
                                        RequireUserInfo(mod, file);
                                    }
                                }
                                else
                                {
                                    mod.Filename = FileName;
                                    mod.Path = file;
                                    modsList.Add(mod);
                                }

                            }
                            catch (JsonSerializationException)
                            {
                                Litemod liteloadermod;

                                try
                                {
                                    liteloadermod = JsonConvert.DeserializeObject<Litemod>(json);
                                }
                                catch (JsonReaderException)
                                {
                                    MessageBox.Show(string.Format("Something is wrong with the Json in {0}", FileName));
                                    throw new JsonSerializationException("Invalid Json in file" + FileName);
                                }
                                //Convert into mcmod
                                Mcmod mod = new Mcmod
                                {
                                    Mcversion = liteloadermod.Mcversion,
                                    Modid = liteloadermod.Name.Replace(" ", ""),
                                    Name = liteloadermod.Name,
                                    Description = liteloadermod.Description,
                                    Authors = new List<string> { liteloadermod.Author }
                                };

                                if (String.IsNullOrEmpty(liteloadermod.Version) || String.IsNullOrEmpty(liteloadermod.Revision))
                                {
                                    if (!(String.IsNullOrEmpty(liteloadermod.Version)))
                                    {
                                        mod.Version = liteloadermod.Version;
                                    }
                                    else
                                    {
                                        if (!(String.IsNullOrEmpty(liteloadermod.Revision)))
                                        {
                                            mod.Version = liteloadermod.Revision;
                                        }
                                    }
                                }
                                else
                                {
                                    mod.Version = liteloadermod.Version + "-" + liteloadermod.Revision;
                                }
                                if (missingInfoActionOnTheRun.Checked)
                                {
                                    RequireUserInfo(mod, file);
                                }
                                else
                                {
                                    mod.Filename = FileName;
                                    mod.Path = file;
                                    modsList.Add(mod);
                                }

                            }
                        }

                    }
                    catch (JsonSerializationException)
                    {
                        RequireUserInfo(file);
                    }
                    File.Delete(mcmodfile);
                }
                else
                {

                    //Check the FTB permission sheet for info before doing anything else
                    String shortname = _ftbPermsSqLhelper.GetShortName(SqlHelper.CalculateMd5(file));
                    if (String.IsNullOrWhiteSpace(shortname))
                    {
                        int fixNr = IsWierdMod(FileName);
                        if (fixNr != Int32.MaxValue)
                        {
                            Mcmod mod;
                            switch (fixNr)
                            {
                                case 1:
                                    Liteloaderversion llversion = _liteloaderSqlHelper.GetInfo(SqlHelper.CalculateMd5(file));
                                    mod = new Mcmod
                                    {
                                        Mcversion = llversion.Mcversion,
                                        Name = "Liteloader",
                                        Modid = llversion.TweakClass
                                    };
                                    try
                                    {
                                        mod.Version = llversion.Version.Substring(llversion.Version.LastIndexOf("_", StringComparison.Ordinal) + 1);
                                    }
                                    catch (NullReferenceException)
                                    {
                                        mod.Version = 1.ToString();
                                    }
                                    if (missingInfoActionOnTheRun.Checked)
                                    {
                                        RequireUserInfo(mod, file);
                                    }
                                    else
                                    {
                                        mod.Filename = FileName;
                                        mod.Path = file;
                                        modsList.Add(mod);
                                    }
                                    break;
                            }
                        }
                        else
                        {
                            if (missingInfoActionOnTheRun.Checked)
                            {
                                RequireUserInfo(file);
                            }
                            else
                            {
                                modsList.Add(new Mcmod
                                {
                                    Path = file,
                                    Filename = FileName
                                });
                            }
                        }
                    }
                    else
                    {
                        Mcmod mod = new Mcmod();
                        if (shortname.Equals("ignore"))
                        {
                            mod.IsIgnore = true;
                        }
                        else
                        {
                            mod.IsIgnore = false;
                            mod.UseShortName = true;
                            mod.Modid = shortname;
                            mod.Name = _ftbPermsSqLhelper.GetPermissionFromModId(shortname).modName;
                            mod.Authors = new List<string>
                            {
                                _ftbPermsSqLhelper.GetPermissionFromModId(shortname).modAuthors
                            };
                            mod.AuthorList = mod.Authors;
                            mod.PrivatePerms = _ftbPermsSqLhelper.FindPermissionPolicy(shortname, false);
                            mod.PublicPerms = _ftbPermsSqLhelper.FindPermissionPolicy(shortname, true);
                        }

                        if (missingInfoActionOnTheRun.Checked)
                        {
                            if (CreateFTBPack.Checked && !CreateTechnicPack.Checked)
                                CreateFtbPackZip(mod, file);
                            else
                            {
                                if (CreateFTBPack.Checked || CreateTechnicPack.Checked)
                                    RequireUserInfo(mod, file);
                            }
                        }
                        else
                        {
                            mod.Filename = FileName;
                            mod.Path = file;
                            modsList.Add(mod);
                        }
                    }
                }
            }
            if (missingInfoActionCreateList.Checked)
            {
                StatusLabel.Text = "Showing modlistpane.";
                toolStripProgressBar.Value = toolStripProgressBar.Maximum;
                Form modinfo = new Modinfo(modsList, this);
                if (!modinfo.IsDisposed)
                {
                    modinfo.ShowDialog();
                }
            }

            Environment.CurrentDirectory = _inputDirectory;
            String[] directories = Directory.GetDirectories(_inputDirectory);
            const string minecraftVersionPattern = @"^[0-9]{1}\.[0-9]{1}\.[0-9]{1,2}$";
            foreach (String dir in directories)
            {
                StatusLabel.Text = "Packing additional folders";

                String dirName = dir.Substring(dir.LastIndexOf(Globalfunctions.PathSeperator) + 1);
                if (Regex.IsMatch(dirName, minecraftVersionPattern, RegexOptions.Multiline))
                {
                    continue;
                }
                String[] jarFiles = Directory.GetFiles(dir, "*.jar", SearchOption.AllDirectories);
                if (jarFiles.Length != 0)
                {
                    continue;
                }
                String levelOverInputDirectory = _inputDirectory.Remove(_inputDirectory.LastIndexOf(Globalfunctions.PathSeperator));

                DialogResult confirmInclude = MessageBox.Show(string.Format("Do you want to include {0}?", dirName),
                                                  @"Additional folder found", MessageBoxButtons.YesNo);
                if (confirmInclude == DialogResult.Yes)
                {
                    Environment.CurrentDirectory = levelOverInputDirectory;
                    if (CreateTechnicPack.Checked)
                    {
                        //Create Technic Pack
                        if (SolderPack.Checked)
                        {
                            List<String> md5Values = new List<string>();
                            List<String> oldmd5Values = new List<string>();
                            Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SolderHelper", "unarchievedFiles"));
                            String md5ValuesFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "SolderHelper", "unarchievedFiles", dirName + ".txt");
                            if (File.Exists(md5ValuesFile))
                            {
                                using (StreamReader reader = new StreamReader(md5ValuesFile))
                                {
                                    while (true)
                                    {
                                        String tmp = reader.ReadLine();
                                        if (String.IsNullOrWhiteSpace(tmp))
                                            break;
                                        oldmd5Values.Add(tmp);
                                    }
                                }
                            }

                            bool same = true;
                            foreach (String f in Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories))
                            {
                                if (!oldmd5Values.Contains(SqlHelper.CalculateMd5(f)))
                                {
                                    same = false;
                                }
                                md5Values.Add(SqlHelper.CalculateMd5(f));
                            }
                            if (same)
                            {
                                continue;
                            }
                            while (String.IsNullOrWhiteSpace(_modpackVersion))
                            {
                                _modpackVersion = Prompt.ShowDialog("What Version is the modpack?", "Modpack Version");
                            }
                            //So we need to include this folder
                            Environment.CurrentDirectory = levelOverInputDirectory;
                            String outputfile = Path.Combine(_outputDirectory, "mods", dirName.ToLower(), dirName.ToLower() + "-" + MakeUrlFriendly(_modpackName + "-" + _modpackVersion) + ".zip");
                            Directory.CreateDirectory(Path.Combine(_outputDirectory, "mods", dirName.ToLower()));
                            if (Globalfunctions.IsUnix())
                            {
                                _startInfo.FileName = "zip";
                                _startInfo.Arguments = String.Format("-r \"{0}\" mods/{1}", outputfile, dirName);
                            }
                            else
                            {
                                _startInfo.FileName = _sevenZipLocation;
                                _startInfo.Arguments = String.Format("a -y \"{0}\" \"mods\\{1}\"", outputfile, dirName);
                            }
                            _process.StartInfo = _startInfo;
                            _process.Start();
                            CreateTableRow(dirName, dirName.ToLower(), MakeUrlFriendly(_modpackName + "-" + _modpackVersion));
                            _process.WaitForExit();

                            if (useSolder.Checked)
                            {
                                int id = _solderSqlHandler.GetModId(dirName.ToLower());
                                if (id == -1)
                                {
                                    _solderSqlHandler.AddModToSolder(dirName.ToLower(), null, null, null, dirName);
                                    id = _solderSqlHandler.GetModId(dirName.ToLower());
                                }
                                String modversion = MakeUrlFriendly(_modpackName + "-" + _modpackVersion);
                                String md5 = SqlHelper.CalculateMd5(outputfile).ToLower();
                                if (_solderSqlHandler.IsModversionOnline(dirName.ToLower(), modversion))
                                    _solderSqlHandler.UpdateModversionMd5(dirName.ToLower(), modversion, md5);
                                else
                                    _solderSqlHandler.AddNewModversionToSolder(id, modversion, md5);

                                id = _solderSqlHandler.GetModId(dirName.ToLower());
                                int modVersionId = _solderSqlHandler.GetModversionId(id, modversion);
                                _solderSqlHandler.AddModversionToBuild(_buildId, modVersionId);
                            }
                            if (File.Exists(md5ValuesFile))
                            {
                                File.Delete(md5ValuesFile);
                            }
                            foreach (String md5Value in md5Values)
                            {
                                File.AppendAllText(md5ValuesFile, md5Value + Environment.NewLine);
                            }
                        }
                        else
                        {
                            if (Globalfunctions.IsUnix())
                            {
                                _startInfo.FileName = "zip";
                                _startInfo.Arguments = String.Format("-r \"{0}\" \"./mods/{1}\"", _modpackArchive, dirName);
                            }
                            else
                            {
                                _startInfo.FileName = _sevenZipLocation;
                                _startInfo.Arguments = String.Format("a -y \"{0}\" \"mods\\{1}\"", _modpackArchive, dirName);
                            }
                            _process.StartInfo = _startInfo;
                            _process.Start();
                            _process.WaitForExit();
                        }
                    }
                    if (CreateFTBPack.Checked)
                    {
                        // Create FTB Pack

                        String tmpDir = Path.Combine(_outputDirectory, "minecraft", "mods");
                        Directory.CreateDirectory(tmpDir);
                        if (Globalfunctions.IsUnix())
                        {
                            _startInfo.FileName = "cp";
                            _startInfo.Arguments = String.Format("-r \"./mods/{0}\" \"{1}\"", dirName, tmpDir);
                            _process.StartInfo = _startInfo;
                            _process.Start();
                            _process.WaitForExit();
                        }
                        else
                        {
                            String input = Path.Combine(_inputDirectory, dirName);
                            DirectoryCopy(input, tmpDir, true);
                        }
                    }
                }

            }

            // Pack additional folders if they are marked
            if (CreateTechnicPack.Checked)
            {

                StatusLabel.Text = "Packing additional selected folders.";
                Environment.CurrentDirectory = _inputDirectory.Remove(_inputDirectory.LastIndexOf(Globalfunctions.PathSeperator));
                foreach (string folderName in from cb in _additionalDirectories where cb.Value.Checked select cb.Key.Substring(cb.Key.LastIndexOf(Globalfunctions.PathSeperator) + 1).ToLower())
                {
                    if (SolderPack.Checked)
                    {
                        bool Solder = useSolder.Checked;
                        var worker = new BackgroundWorker();
                        var name = folderName;
                        worker.DoWork += (sender, args) =>
                        {
                            _runningProcess++;
                            String mpname = _modpackName.Replace(" ", "-").ToLower();
                            String of = Path.Combine(_outputDirectory, "mods", name);
                            Directory.CreateDirectory(of);
                            String outputfile = Path.Combine(of,
                                name.ToLower() + "-" + mpname + "-" + _modpackVersion + ".zip");
                            if (Globalfunctions.IsUnix())
                            {
                                _startInfo.FileName = "zip";
                                _startInfo.Arguments = String.Format("-r \"{0}\" {1}", outputfile, name);
                            }
                            else
                            {
                                _startInfo.FileName = _sevenZipLocation;
                                _startInfo.Arguments = String.Format("a -y \"{0}\" \"{1}\"", outputfile, name);
                            }
                            _process.StartInfo = _startInfo;
                            _process.Start();
                            _process.WaitForExit();

                            CreateTableRow(name, name.ToLower(), mpname + "-" + _modpackVersion);

                            if (Solder)
                            {
                                int id = _solderSqlHandler.GetModId(name.ToLower());
                                if (id == -1)
                                {
                                    _solderSqlHandler.AddModToSolder(name.ToLower(), null, null, null,
                                        name);
                                    id = _solderSqlHandler.GetModId(name.ToLower());
                                }
                                String md5 = SqlHelper.CalculateMd5(outputfile).ToLower();
                                if (_solderSqlHandler.IsModversionOnline(name.ToLower(),
                                    mpname + "-" + _modpackVersion))
                                    _solderSqlHandler.UpdateModversionMd5(name.ToLower(),
                                        mpname + "-" + _modpackVersion, md5);
                                else
                                    _solderSqlHandler.AddNewModversionToSolder(id, mpname + "-" + _modpackVersion,
                                        md5);
                                int modVersionId =
                                    _solderSqlHandler.GetModversionId(
                                        _solderSqlHandler.GetModId(name.ToLower()),
                                        mpname + "-" + _modpackVersion);
                                _solderSqlHandler.AddModversionToBuild(_buildId, modVersionId);
                            }
                            _runningProcess--;
                        };
                        worker.RunWorkerAsync();
                    }
                    else
                    {

                        if (Globalfunctions.IsUnix())
                        {
                            _startInfo.FileName = "zip";
                            _startInfo.Arguments = String.Format("-r \"{0}\" \"{1}\"", _modpackArchive, folderName);
                        }
                        else
                        {
                            _startInfo.FileName = _sevenZipLocation;
                            _startInfo.Arguments = String.Format("a -y \"{0}\" \"{1}\"", _modpackArchive, folderName);
                        }
                        _process.StartInfo = _startInfo;
                        _process.Start();
                        _process.WaitForExit();

                    }
                }
            }
            if (CreateTechnicPack.Checked && IncludeForgeVersion.Checked)
            {
                string selectedBuild = ForgeBuild.SelectedItem.ToString();
                PackForge(selectedBuild);
            }

            if (CreateTechnicPack.Checked && IncludeConfigZip.Checked)
                CreateConfigZip();

            //FTB pack configs
            if (CreateFTBPack.Checked)
            {
                foreach (KeyValuePair<String, CheckBox> cb in _additionalDirectories)
                {
                    if (cb.Value.Checked)
                    {
                        String dirName = cb.Key.Substring(cb.Key.LastIndexOf(Globalfunctions.PathSeperator) + 1);
                        String tmpDir = Path.Combine(_outputDirectory, "minecraft");

                        Directory.CreateDirectory(tmpDir);
                        if (Globalfunctions.IsUnix())
                        {
                            _startInfo.FileName = "cp";
                            _startInfo.Arguments = String.Format("-r \"{0}\" \"{1}\"", dirName, tmpDir);
                            _process.StartInfo = _startInfo;
                            _process.Start();
                            _process.WaitForExit();
                        }
                        else
                        {
                            FileAttributes attr = File.GetAttributes(cb.Key);
                            if ((attr & FileAttributes.Directory) == FileAttributes.Directory)
                            {
                                tmpDir = Path.Combine(tmpDir, dirName);
                                DirectoryCopy(cb.Key, tmpDir, true);
                            }
                            else
                            {
                                String outputFile = Path.Combine(tmpDir, dirName);
                                File.Copy(cb.Key, outputFile);
                            }
                        }
                    }
                }

                String tmpConfigDirectory = Path.Combine(_outputDirectory, Path.Combine("minecraft", "config"));
                Directory.CreateDirectory(tmpConfigDirectory);

                String sourceConfigDirectory = InputFolder.Text.Replace(Globalfunctions.PathSeperator + "mods", Globalfunctions.PathSeperator + "config");
                try
                {
                    DirectoryCopy(sourceConfigDirectory, tmpConfigDirectory, true);
                }
                catch (DirectoryNotFoundException)
                {
                    MessageBox.Show("I can't seem to find a config directory for the FTB pack.");
                }

                Environment.CurrentDirectory = _outputDirectory;
                if (Globalfunctions.IsUnix())
                {
                    _startInfo.FileName = "zip";
                    _startInfo.Arguments = String.Format("-r \"{0}\" \"minecraft\" -x minecraft/config/YAMPST.nbt",
                        _ftbModpackArchive);
                }
                else
                    _startInfo.Arguments = string.Format("a -x!minecraft\\config\\YAMPST.nbt -y \"{0}\" \"minecraft\" ", _ftbModpackArchive);

                _process.StartInfo = _startInfo;
                _process.Start();
                _process.WaitForExit();
                Directory.Delete(Path.Combine(_outputDirectory, "minecraft"), true);
            }
            while (_runningProcess > 0)
            {
                StatusLabel.Text = "Waiting for " + _runningProcess + " mod" + (_runningProcess == 1 ? "" : "s") + " to finsh packing";
                if (Globalfunctions.IsUnix ()) {
                    statusStrip.Refresh ();
                    this.Refresh ();
                }
                if (doDebug.Checked)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (string pros in _processesUsingFolder.Keys)
                    {
                        sb.AppendLine(pros);
                    }
                    Debug.WriteLine(sb.ToString());
                }
                Debug.Save();
                Thread.Sleep(100);
            }
            StatusLabel.Text = "Saving mod data";
            _modsSqLhelper.SaveData();
            StatusLabel.Text = "Done saving moddata";

            if (Directory.Exists(Path.Combine(_outputDirectory, "assets")))
                Directory.Delete(Path.Combine(_outputDirectory, "assets"), true);
            if (Directory.Exists(Path.Combine(_outputDirectory, "example")))
                Directory.Delete(Path.Combine(_outputDirectory, "example"), true);
            foreach (String file in Directory.GetFiles(_outputDirectory, "*.info", SearchOption.TopDirectoryOnly))
            {
                File.Delete(file);
            }

            if (CreateTechnicPack.Checked && SolderPack.Checked && !useSolder.Checked)
            {
                File.AppendAllText(_path, AddedModStringBuilder.ToString());
                File.AppendAllText(_path, @"</table><button id=""Reshow"" type=""button"">Unhide Everything</button><p>List autogenerated by TechnicSolderHelper &copy; 2014 - Rasmus Hansen</p></body></html>");
                if (Globalfunctions.IsUnix())
                {
                    Process.Start(_path);
                }
                else
                {
                    try
                    {
                        Process.Start("chrome.exe", "\"" + _path + "\"");
                    }
                    catch (Exception)
                    {
                        try
                        {
                            Process.Start("iexplore", "\"" + _path + "\"");
                        }
                        catch (Exception)
                        {
                            try
                            {
                                Process.Start("firefox.exe", "\"" + _path + "\"");
                            }
                            catch (Exception)
                            {
                                Process.Start("\"" + _path + "\"");
                            }
                        }
                    }
                }

            }
            if (CreateTechnicPack.Checked && SolderPack.Checked && UploadToFTPServer.Checked)
            {
                StatusLabel.Text = "Uploading to FTP";
                UploadingToFTP = true;
                BackgroundWorker bwFtp = new BackgroundWorker();
                bwFtp.DoWork += (s, a) =>
                {
                    if (_ftp == null)
                    {
                        _ftp = new Ftp();
                    }
                    _ftp.UploadFolder(Path.Combine(_outputDirectory, "mods"));
                };
                bwFtp.RunWorkerCompleted += (s, a) =>
                {
                    UploadingToFTP = false;
                    MessageBox.Show("Done uploading to FTP");
                };
                bwFtp.RunWorkerAsync();
            }

            if (CreateTechnicPack.Checked && SolderPack.Checked && UseS3.Checked)
            {
                StatusLabel.Text = "Uploading to S3";
                UploadingToS3 = true;
                BackgroundWorker bwS3 = new BackgroundWorker();
                bwS3.DoWork += (s, a) =>
                {
                    S3 s3Client = new S3();
                    s3Client.UploadFolder(Path.Combine(_outputDirectory, "mods"));
                    UploadingToS3 = false;
                };
                bwS3.RunWorkerCompleted += (s, a) =>
                {
                    UploadingToS3 = false;
                };
                bwS3.RunWorkerAsync();
            }

            InputFolder.Items.Clear();
            try
            {
                InputFolder.Items.AddRange(_inputDirectories.ToArray());
            }
            catch
            {
                // ignored
            }
            toolStripProgressBar.Value = 0;
            StatusLabel.Text = "Waiting...";
        }
コード例 #2
0
        private bool test_Click()
        {
            if (!(serviceURL.Text.StartsWith("http://") ||serviceURL.Text.StartsWith("https://")))
            {
                serviceURL.Text = "http://" + serviceURL.Text;
            }
            if (IsEveryFilledIn())
            {
                if (!Uri.IsWellFormedUriString(serviceURL.Text, UriKind.Absolute))
                {
                    MessageBox.Show("Service url is not valid");
                    return false;
                }

                _service = new S3(accessKey.Text, secretKey.Text, serviceURL.Text);
                try
                {
                    _service.GetBucketList();
                    GetBuckets();
                    return true;
                }
                catch (Exception exception)
                {
                    MessageBox.Show(string.Format("Connection not succesful.\n{0}", exception.Message));
                }

            }
            else
            {
                MessageBox.Show("Please fill in everything.");
            }
            return false;
        }