Beispiel #1
0
        public void Add(string file, bool update_menu)
        {
            // Validate the filepath
            if (string.IsNullOrEmpty(file))
            {
                throw new Exception("Invalid recent file path");
            }

            // Move the item matching 'file' to the front of the list
            Filepaths.RemoveAll(x => string.Equals(x, file, StringComparison.CurrentCultureIgnoreCase));
            Filepaths.Insert(0, file);

            // Cap the maximum number of recent files
            for (; Filepaths.Count > MaxCount;)
            {
                Filepaths.RemoveAt(Filepaths.Count - 1);
            }

            // Update the menu
            if (update_menu)
            {
                UpdateMenu();
            }

            // Notify recent files changed
            RecentFilesListChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #2
0
        /// <summary>Reset the recent files list</summary>
        public void Clear()
        {
            Filepaths.Clear();
            UpdateMenu();

            // Notify recent files changed
            RecentFilesListChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #3
0
        /// <summary>Remove a filepath from the recent files list</summary>
        public void Remove(string file, bool update_menu)
        {
            Filepaths.RemoveAll(x => string.Equals(x, file, StringComparison.CurrentCultureIgnoreCase));

            if (update_menu)
            {
                UpdateMenu();
            }

            // Notify recent files changed
            RecentFilesListChanged?.Invoke(this, EventArgs.Empty);
        }
Beispiel #4
0
 /// <summary>Import recent files from a single string</summary>
 public void Import(string str)
 {
     if (!string.IsNullOrEmpty(str))
     {
         Filepaths.Clear();
         foreach (var s in str.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
         {
             Filepaths.Add(s);
         }
     }
     UpdateMenu();
 }
        private string GetNewPackFolder()
        {
            string InstallationPath     = Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, ConfigManager.CurrentInstallation.DirectoryName);
            string NewPackDirectoryName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            string NewPackDirectory     = Path.Combine(Filepaths.GetSkinPacksFolderPath(InstallationPath, false), NewPackDirectoryName);

            while (Directory.Exists(NewPackDirectory))
            {
                NewPackDirectoryName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
                NewPackDirectory     = Path.Combine(Filepaths.GetSkinPacksFolderPath(InstallationPath, false), NewPackDirectoryName);
            }

            return(NewPackDirectory);
        }
Beispiel #6
0
        public void ReloadSkinPacks()
        {
            LoadedSkinPacks.Items.Clear();
            SkinPacks.Clear();

            var installation = ConfigManager.CurrentInstallation;

            if (installation == null)
            {
                return;
            }

            string InstallationPath = Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, installation.DirectoryName);
            string normal_folder    = Filepaths.GetSkinPacksFolderPath(InstallationPath, false);
            string dev_folder       = Filepaths.GetSkinPacksFolderPath(InstallationPath, true);

            if (Directory.Exists(normal_folder))
            {
                AddPacks(normal_folder);
            }
            if (Directory.Exists(dev_folder))
            {
                AddPacks(dev_folder);
            }

            UpdateAddSkinButton();

            void AddPacks(string _SourceFolder)
            {
                var SourceFolder = new DirectoryInfo(_SourceFolder);
                var FoundFolders = SourceFolder.GetDirectories();

                foreach (var PossiblePack in FoundFolders)
                {
                    if (PossiblePack.GetFiles().ToList().Exists(x => x.Name == "manifest.json"))
                    {
                        var result = MCSkinPack.ValidatePack(PossiblePack.FullName);
                        if (result != null)
                        {
                            SkinPacks.Add(result);
                            LoadedSkinPacks.Items.Add(result);
                        }
                    }
                }
            }
        }
Beispiel #7
0
        private void ImportSkinPackButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter = "MCPACK Files (*.mcpack)|*.mcpack|ZIP Files (*.zip)|*.zip"
            };

            if (dialog.ShowDialog().Value)
            {
                try
                {
                    var file = ZipFile.OpenRead(dialog.FileName);
                    if (file.Entries.ToList().Exists(x => x.FullName == "skins.json"))
                    {
                        file.Dispose();
                        string InstallationPath     = Filepaths.GetInstallationsFolderPath(ConfigManager.CurrentProfile, ConfigManager.CurrentInstallation.DirectoryName);
                        string NewPackDirectoryName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
                        string NewPackDirectory     = Path.Combine(Filepaths.GetSkinPacksFolderPath(InstallationPath, false), NewPackDirectoryName);

                        while (Directory.Exists(NewPackDirectory))
                        {
                            NewPackDirectoryName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
                            NewPackDirectory     = Path.Combine(Filepaths.GetSkinPacksFolderPath(InstallationPath, false), NewPackDirectoryName);
                        }

                        ZipFile.ExtractToDirectory(dialog.FileName, NewPackDirectory);
                    }
                    else
                    {
                        file.Dispose();
                        ErrorScreenShow.errormsg("notaskinpack");
                    }
                }
                catch (Exception ex)
                {
                    ErrorScreenShow.exceptionmsg(ex);
                }
            }
            ReloadSkinPacks();
        }
Beispiel #8
0
        private static void Main(string[] args)
        {
            if (Mutex.WaitOne(TimeSpan.Zero, true))
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                // Create data directory
                if (!Filepaths.CreateDataDirectory())
                {
                    MessageBox.Show(
                        @"Could not create data directory! Make sure that your SST directory is not read-only. Exiting.",
                        @"Fatal error",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }

                if (args.Length > 0)
                {
                    if (args[0].Equals("--restart", StringComparison.InvariantCultureIgnoreCase))
                    {
                        sst = new SynServerTool(true);
                    }
                }
                else
                {
                    sst = new SynServerTool(false);
                }

                // Load the GUI
                Application.Run(new UserInterface(sst));
            }
            else
            {
                MessageBox.Show(
                    @"SST is already running. Only one copy of SST can run at a time!",
                    @"SST is already running",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #9
0
        public static void Load()
        {
            string json;

            if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
            {
                Default = new LauncherSettings();
            }
            else
            {
                if (File.Exists(Filepaths.GetSettingsFilePath()))
                {
                    json = File.ReadAllText(Filepaths.GetSettingsFilePath());
                    try { Default = JsonConvert.DeserializeObject <LauncherSettings>(json, JsonSerializerSettings); }
                    catch { Default = new LauncherSettings(); }
                }
                else
                {
                    Default = new LauncherSettings();
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Verifies the configuration location and file.
        /// </summary>
        public void VerifyConfigLocation()
        {
            if (!Directory.Exists(Filepaths.DataDirectoryPath))
            {
                Log.WriteCritical("Data directory does not exist. Will attempt to create.",
                                  _logClassType, _logPrefix);
                Filepaths.CreateDataDirectory();
            }
            if (!File.Exists(Filepaths.ConfigurationFilePath))
            {
                Log.WriteCritical("Config file does not exist. Restoring default config.",
                                  _logClassType, _logPrefix);
                RestoreDefaultConfiguration();
            }
            var fileInfo = new FileInfo(Filepaths.ConfigurationFilePath);

            if (fileInfo.Length != 0)
            {
                return;
            }
            Log.WriteCritical("Config exists but is empty. Restoring default config.",
                              _logClassType, _logPrefix);
            RestoreDefaultConfiguration();
        }
Beispiel #11
0
        public void Save()
        {
            string json = JsonConvert.SerializeObject(this, Formatting.Indented);

            File.WriteAllText(Filepaths.GetSettingsFilePath(), json);
        }
Beispiel #12
0
 /// <summary>Returns true if the given filepath is in the recent files list</summary>
 public bool IsInRecents(string file)
 {
     return(Filepaths.FindIndex(x => string.Equals(x, file, StringComparison.CurrentCultureIgnoreCase)) != -1);
 }