Esempio n. 1
0
        /// <summary>
        ///     Execute this backup
        /// </summary>
        public void Execute()
        {
            string backupfolder = "\\backup_" + Name + "_" + DateTime.Now.Ticks;
            string savedir      = TargetDirectory + backupfolder;
            string target       = TargetDirectory + backupfolder;

            if (Compression)
            {
                target = Fl.SafeLocation(RequestFile.Temp) + backupfolder;
            }
            foreach (string folder in Folders)
            {
                DirectoryInfo di = new DirectoryInfo(folder);
                FsUtil.CopyFolder(di.FullName, target);
            }
            foreach (string file in Files)
            {
                FileInfo fi = new FileInfo(file);
                FsUtil.CopyFolder(fi.FullName, target);
            }
            if (Compression)
            {
                Core.Util.Compression.Compress(target,
                                               savedir + ".zip");
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Start a process, start the threads to read the output and send the output to the correct outputhandler
        /// </summary>
        /// <param name="executable">The executable to run</param>
        /// <param name="parameters">The parameters for the executable</param>
        /// <param name="server">The server that is being ran</param>
        /// <param name="serverDir">The directory that should be used as root for the minecraft server</param>
        /// <returns></returns>
        public static Boolean StartServer(string executable, string parameters, IMinecraftServer server,
                                          string serverDir = "")
        {
            try
            {
                if (string.IsNullOrEmpty(executable))
                {
                    return(false);
                }
                if (string.IsNullOrEmpty(parameters))
                {
                    parameters = "";
                }

                if (string.IsNullOrEmpty(serverDir))
                {
                    serverDir = Fl.SafeLocation(RequestFile.Serverdir);
                }
                FileInfo exeFileInfo = new FileInfo(executable);
                Server = server;

                RaiseServerStarting();

                ServerProcess = new Process
                {
                    StartInfo =
                        new ProcessStartInfo
                    {
                        FileName               = exeFileInfo.FullName,
                        Arguments              = parameters,
                        CreateNoWindow         = true,
                        WindowStyle            = ProcessWindowStyle.Hidden,
                        ErrorDialog            = false,
                        UseShellExecute        = false,
                        WorkingDirectory       = serverDir,
                        StandardErrorEncoding  = Encoding.Unicode,
                        StandardOutputEncoding = Encoding.Unicode,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true,
                        RedirectStandardError  = true
                    },
                    EnableRaisingEvents = true,
                };
                // log from startinfo to ensure correct results (in case .NET would alter something)
                Logger.Log(LogLevel.Info, "ProcessHandler", "Starting new process: " + ServerProcess.StartInfo.FileName + " " + ServerProcess.StartInfo.Arguments);
                ServerProcess.Start();
                ServerProcess.Exited += HandleStop;

                StartThreads();

                RaiseServerStarted();
                return(true);
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Warning, "ProcessHandler", "Couldn't start server! " + executable + " " + parameters,
                           exception.Message);
                return(false);
            }
        }
Esempio n. 3
0
 public override void PrepareLaunch()
 {
     // Extract the assembly
     CustomAssembly = Fl.SafeLocation(RequestFile.Temp) + "connector.exe";
     using (FileStream fs = File.Create(CustomAssembly))
     {
         fs.Write(Resources.JsonApiConnector, 0, Resources.JsonApiConnector.Length);
     }
 }
Esempio n. 4
0
        /// <summary>
        ///     Execute this backup
        /// </summary>
        public void Execute()
        {
            string backupfolder = "\\backup_" + Name + "_" + DateTime.Now.Ticks / 10000000;
            // divide by 10 000 000 for a shorter name
            string savedir = TargetDirectory + backupfolder;
            string target  = TargetDirectory + backupfolder;

            try
            {
                // if we need to compress, move to intermediary folder
                if (Compression)
                {
                    target = Fl.SafeLocation(RequestFile.Temp) + backupfolder;
                }

                foreach (string folder in _folders)
                {
                    DirectoryInfo di = new DirectoryInfo(folder);
                    FsUtil.CopyFolder(di.FullName, target);
                }
                foreach (var file in _files)
                {
                    FileInfo fi = new FileInfo(file);
                    FsUtil.CopyFolder(fi.FullName, target);
                }
                if (Compression)
                {
                    // compress target to savedir.zip
                    Core.Util.Compression.Compress(target,
                                                   savedir + ".zip");
                    // delete temporary folder
                    Directory.Delete(target, true);
                }
            }
            catch (PathTooLongException)
            {
                MetroMessageBox.Show(Application.OpenForms[0],
                                     Locale.Tr(
                                         "A backup couldn't be executed. The path is too long! Try using shorter filenames.") +
                                     Environment.NewLine + "Backup name:" + Name,
                                     Locale.Tr("Backup failed"),
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
            catch (Exception)
            {
                MetroMessageBox.Show(Application.OpenForms[0],
                                     Locale.Tr(
                                         "A backup couldn't be executed. Maybe you don't have sufficient rights, or maybe the files are locked by another application.") +
                                     Environment.NewLine + "Backup name:" + Name,
                                     Locale.Tr("Backup failed"),
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Error);
            }
        }
        /// <summary>
        ///     Create a simple list of the plugin in the plugin folder. Fast, but lacks details.
        /// </summary>
        /// <remarks></remarks>
        private static void CreateSimpleList()
        {
            FileInfo[] pluginfiles = new DirectoryInfo(Fl.SafeLocation(RequestFile.Plugindir)).GetFiles();

            //create dictionary
            Plugins = new Dictionary <string, InstalledPlugin>();

            if (pluginfiles.Length < 1)
            {
                Logger.Log(LogLevel.Warning, "pluginmanager", "Cancelled simple list creation: no Plugins");
                // still raise event to update UI, maybe the last plugin was removed
                RaiseInstalledPluginListLoadedSimpleList();
                //no Plugins, nothing to do here
                return;
            }


            //load all the Plugins in the dictionary
            foreach (FileInfo pluginfile in pluginfiles)
            {
                try
                {
                    if (pluginfile.Extension == ".jar")
                    {
                        Plugins.Add(pluginfile.Name,
                                    new InstalledPlugin().ParseSimpleFields(pluginfile.FullName));
                    }
                }
                catch (Exception ex)
                {
                    if (pluginfile != null)
                    {
                        Logger.Log(LogLevel.Warning, "InstalledPlugins",
                                   "Couldn't add plugin to plugin list:" + pluginfile.Name, ex.Message);
                    }
                    else
                    {
                        Logger.Log(LogLevel.Warning, "InstalledPlugins", "Couldn't add plugin to plugin list",
                                   ex.Message);
                    }
                }
            }

            //we got the first list now
            RaiseInstalledPluginListLoadedSimpleList();
        }
Esempio n. 6
0
        private void Initialize()
        {
            try
            {
                string file = _type.ToString().ToLower().Replace('_', '-') + ".json";
                _path = Fl.SafeLocation(RequestFile.Serverdir) + file;

                LoadList();
                _watcher = new FileSystemWatcher(Fl.SafeLocation(RequestFile.Serverdir))
                {
                    Filter              = "*" + file,
                    NotifyFilter        = NotifyFilters.Size | NotifyFilters.LastWrite,
                    EnableRaisingEvents = true
                };
                _watcher.Changed += ((sender, e) => LoadList());
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Warning, "ServerList", "Couldn't initialize " + _type, exception.Message);
            }
        }
Esempio n. 7
0
        /// <summary>
        ///     Load a config file
        /// </summary>
        /// <param name="location"></param>
        public static void LoadFile(string location = "")
        {
            if (string.IsNullOrEmpty(location))
            {
                location = Fl.SafeLocation(RequestFile.Config) + CteFileName;
            }

            _filepath = location;


            Logger.Log(LogLevel.Info, "Config", "Loading file", _filepath);

            if (!File.Exists(_filepath))
            {
                CreateEmptyConfig(_filepath);
            }

            try
            {
                _xmldoc = new XmlDocument();
                _xmldoc.Load(_filepath);

                LoadCache(); //everything's cached, we're ready to go
            }
            catch (Exception exception)
            {
                Logger.Log(LogLevel.Severe, "config", "config file could not be loaded", exception.Message);
                if (
                    MetroMessageBox.Show(null,
                                         "The GUI config file could not be loaded, and as a result, the GUI could not be started.\n" +
                                         "The file is probably corrupt. You either need to fix it manually, or reset the file. Do you want to reset it?",
                                         "Config file corrupt", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    CreateEmptyConfig(_filepath);
                    Application.Restart();
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 ///     Save the log file to the default location
 /// </summary>
 internal static void SaveFile()
 {
     SaveFile(Fl.SafeLocation(RequestFile.Log) + "bukkitgui.log");
 }
Esempio n. 9
0
        /// <summary>
        ///     Install plguins from a zip file
        /// </summary>
        /// <param name="version">Version to install</param>
        /// <param name="showUi">Allow pop-up dialogs</param>
        /// <remarks></remarks>
        private static Boolean InstallZip(BukgetPluginVersion version, bool showUi = true)
        {
            if (showUi)
            {
                if (
                    MetroMessageBox.Show(Application.OpenForms[0],
                                         Locale.Tr("You are about to install") + " " + version.Filename.Replace(".zip", "") + " (" +
                                         version.VersionNumber + ")" + Constants.vbCrLf + Locale.Tr("Do you wish to continue?"),
                                         Locale.Tr("Continue?"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    return(false);
                }
            }

            Logger.Log(LogLevel.Info, "BukGetAPI", "Installing plugin:" + version.Filename + ", packed as zip file");

            string randomName = DateTime.Now.Ticks.ToString();

            string zipfile    = Fl.SafeLocation(RequestFile.Temp) + "install.zip";
            string extraction = Fl.SafeLocation(RequestFile.Temp) + "/install_" + randomName + "/";

            FileDownloader fdd = new FileDownloader();

            fdd.AddFile(version.DownloadLink, zipfile);
            fdd.ShowDialog();

            Compression.Decompress(extraction, zipfile);

            // ******************************
            // At this point, the zip file is extracted to a temporary location
            // Now only the needed files should be moved


            Boolean hasFileBeenMoved = false;

            Boolean hasFolderBeenMoved = false;

            //file is decompressed, now search the needed files
            DirectoryInfo extracteDirectoryInfo = new DirectoryInfo(extraction);

            List <string> extractedFileNamesList = new List <string>();

            foreach (FileInfo fileInfo in extracteDirectoryInfo.GetFiles())
            {
                if (fileInfo.Extension == ".jar")
                {
                    File.Copy(fileInfo.FullName,
                              Fl.Location(RequestFile.Plugindir) + "/" + fileInfo.Name, true);
                    extractedFileNamesList.Add(fileInfo.Name);
                    hasFileBeenMoved = true;
                    Logger.Log(LogLevel.Info, "BukGetAPI", "Jar file found in .zip (L1), copied:" + fileInfo.Name);
                }
            }

            // now we check if there's a folder with the same name as the plugin. This folder should also be moved to the /plugins folder
            foreach (DirectoryInfo directoryInZipInfo in extracteDirectoryInfo.GetDirectories())
            {
                Boolean folderShouldBeMoved = false;

                foreach (string f in extractedFileNamesList)
                {
                    if (f.Contains(directoryInZipInfo.Name))
                    {
                        folderShouldBeMoved = true;
                        Logger.Log(LogLevel.Info, "BukgetAPI",
                                   "Config/Info folder found in .zip, marked directory for copy:" + directoryInZipInfo.Name);
                    }
                }
                if (!folderShouldBeMoved)
                {
                    foreach (FileInfo fileInfo in directoryInZipInfo.GetFiles())
                    {
                        if (fileInfo.Extension == ".txt" | fileInfo.Extension == ".yml" | fileInfo.Extension == ".cfg" |
                            fileInfo.Extension == ".csv" | fileInfo.Extension == ".js")
                        {
                            folderShouldBeMoved = true;
                            Logger.Log(LogLevel.Info, "BukgetAPI",
                                       "Config/Info file found in .zip, marked directory for copy:" + fileInfo.Name);
                        }
                    }
                }
                if (folderShouldBeMoved)
                {
                    Directory.Move(directoryInZipInfo.FullName,
                                   Fl.Location(RequestFile.Plugindir) + "/" + directoryInZipInfo.Name);
                    hasFileBeenMoved   = false;
                    hasFolderBeenMoved = true;
                }

                // If we didn't copy a file yet, check other folders for jar files
                //L2
                if (!hasFileBeenMoved)
                {
                    foreach (FileInfo fileInfo in directoryInZipInfo.GetFiles())
                    {
                        if (fileInfo.Extension != ".jar")
                        {
                            continue;
                        }
                        fileInfo.MoveTo(Fl.Location(RequestFile.Plugindir) + "/" + fileInfo.Name);
                        hasFileBeenMoved = true;
                        Logger.Log(LogLevel.Info, "BukgetAPI", "Jar file found in .zip (L2), copied:" + fileInfo.Name);
                    }
                }

                if (hasFolderBeenMoved)
                {
                    continue;
                }
                // If we didn't find a config folder yet, check deeper. config folders are not required
                foreach (DirectoryInfo dir2 in directoryInZipInfo.GetDirectories())
                {
                    bool copy2 = false;
                    foreach (string f in extractedFileNamesList)
                    {
                        if (!f.Contains(dir2.Name))
                        {
                            continue;
                        }
                        copy2 = true;
                        Logger.Log(LogLevel.Info, "BukgetAPI",
                                   "Config/Info folder found in .zip, marked directory for copy:" + dir2.Name);
                    }
                    foreach (FileInfo fileInfo in dir2.GetFiles())
                    {
                        if (fileInfo.Extension == ".txt" | fileInfo.Extension == ".yml" | fileInfo.Extension == ".cfg" |
                            fileInfo.Extension == ".csv" | fileInfo.Extension == ".js")
                        {
                            copy2 = true;
                            Logger.Log(LogLevel.Info, "BukgetAPI",
                                       "Config/Info file found in .zip, marked directory for copy:" + fileInfo.Name);
                        }
                    }
                    if (copy2)
                    {
                        FsUtil.CopyFolder(directoryInZipInfo.FullName,
                                          Fl.Location(RequestFile.Plugindir) + "/" + dir2.Name, true);
                    }
                }

                // end of second level searching
            }


            Logger.Log(LogLevel.Info, "BukgetAPI",
                       "Finished plugin installation: Success?" + (hasFileBeenMoved || hasFolderBeenMoved));

            //refresh installed list
            if (showUi)
            {
                ShowInstallationComplete(version.PluginName, version.VersionNumber);
            }

            return(hasFileBeenMoved || hasFolderBeenMoved);
        }
 private void btnOpenFolder_Click(object sender, EventArgs e)
 {
     Process.Start(Fl.SafeLocation(RequestFile.Plugindir));
 }
Esempio n. 11
0
 public static void Initialize()
 {
     LoadSettings(Fl.SafeLocation(RequestFile.Serverdir) + "\\server.properties");
     _initialized = true;
 }