/// <summary> /// Saves loaded_skins to a file, deletes the contents of KShootMania's img and se directories and repopulates them with the files from the skin. /// </summary> private void Load_Skin() { CommonData.Save_skins_xml(loaded_skins); #region Empty directories Directory.Delete(CommonData.KSMDir + "\\imgs", true); Directory.Delete(CommonData.KSMDir + "\\se", true); Directory.Delete(CommonData.KSMDir + "\\cache", true); Directory.CreateDirectory(CommonData.KSMDir + "\\imgs"); Directory.CreateDirectory(CommonData.KSMDir + "\\se"); Directory.CreateDirectory(CommonData.KSMDir + "\\cache"); #endregion #region Repopulate directories for (int i = 0; i < loaded_skins.Count; i++) { string imgdir = CommonData.SkinDir + '\\' + loaded_skins[i] + "\\imgs"; if (Directory.Exists(imgdir)) { ATEMMethods.CopyDirectory(imgdir, CommonData.KSMDir + "\\imgs", ATEMMethods.FolderExistsResponse.MergeOverwrite, true); } string sedir = CommonData.SkinDir + '\\' + loaded_skins[i] + "\\se"; if (Directory.Exists(sedir)) { ATEMMethods.CopyDirectory(sedir, CommonData.KSMDir + "\\se", ATEMMethods.FolderExistsResponse.MergeOverwrite, true); } } #endregion Close(); }
/// <summary> /// Installs the specified skin to the user's list of skins. /// </summary> /// <param name="zip"></param> public static void Install_Skin(string zip) { #region Create unique id Random randint = new Random(); string id = randint.Next(9999).ToString(); while (Directory.Exists(ExeDir + '\\' + id)) { id = randint.Next(9999).ToString(); } #endregion string skindir = ExeDir + '\\' + id; ZipFile.ExtractToDirectory(zip, skindir); string[] subdirs; while (true) { subdirs = Directory.GetDirectories(skindir); if (subdirs.Contains(skindir + "\\imgs") || subdirs.Contains(skindir + "\\se")) { break; } else if (subdirs.Length == 0) { MessageBox.Show("ERROR: The skin within the zip file could not be found.", "ERROR"); return; } else { skindir = subdirs[0]; } } string skinname = skindir.Split('\\').GetFromLast(0); if (File.Exists(SkinDir + '\\' + skinname)) { if (MessageBox.Show("ERROR: The skin you're trying to install is already installed. Overwrite?", "ERROR", MessageBoxButtons.YesNo) == DialogResult.Yes) { Directory.Delete(SkinDir + '\\' + skinname, true); } else { return; } } ATEMMethods.CopyDirectory(skindir, SkinDir + '\\' + skinname, true); Directory.Delete(ExeDir + "\\" + id, true); }
/// <summary> /// Install KShootMania Skin Manager /// </summary> private void Begin_setupButton_Click(object sender, EventArgs e) { Directory.CreateDirectory(CommonData.SkinDir); CommonData.KSMDir = KSM_install_locationTextBox.Text; CommonData.Save(); #region Copy default skin #region Create unique id Random randint = new Random(); string id = randint.Next(9999).ToString(); while (Directory.Exists(CommonData.ExeDir + '\\' + id)) { id = randint.Next(9999).ToString(); } #endregion ZipFile.ExtractToDirectory(Zip_fileTextBox.Text, CommonData.ExeDir + '\\' + id); ATEMMethods.CopyDirectory(CommonData.ExeDir + "\\" + id + "\\kshootmania\\imgs", CommonData.SkinDir + '\\' + CommonData.DefaultSkinName + "\\imgs", true); ATEMMethods.CopyDirectory(CommonData.ExeDir + '\\' + id + "\\kshootmania\\se", CommonData.SkinDir + '\\' + CommonData.DefaultSkinName + "\\se", true); Directory.Delete(CommonData.ExeDir + "\\" + id, true); #endregion #region Insert shortcut into startup folder WindowsPrincipal windowsPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); string startup_path = "C:\\"; if (Install_for_allCheckBox.Checked && windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator)) { startup_path += "ProgramData"; } else { startup_path += "Users\\" + Environment.UserName + "\\Appdata\\Roaming"; } startup_path += "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\KShootMania Skin Manager.lnk"; IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell(); IWshRuntimeLibrary.IWshShortcut shortcut = shell.CreateShortcut(startup_path); shortcut.TargetPath = Environment.GetCommandLineArgs()[0]; shortcut.Save(); #endregion MessageBox.Show("Installation complete. Please note that in order to best make use of KShootMania Skin Manager, KShootMania must be run in windowed mode. Fullscreen mode will work, but it'll be a bit messy"); Close(); }
private void OpenButton_Click(object sender, EventArgs e) { if (optionsform.Use_C2_Player) { #region Cytus 2 #region Get directory string[] c2_directory_split = optionsform.C2_Player_path.Split('\\'); string c2_directory = c2_directory_split.SubArray(0, c2_directory_split.Length - 1).Stitch('\\'); #endregion #region Create new settings.txt string backup_settings_txt = File.ReadAllText(c2_directory + "\\Settings.txt", Encoding.UTF8); JSON.C2Level level = JSON.C2Level.Load(c2_directory + "\\Settings.txt"); level.Name = current_level.title; level.DiffName = (string)ChartComboBox.SelectedItem; level.DiffNumber = current_level.charts[ChartComboBox.SelectedIndex].difficulty; level.Musicpath = Chart_folderTextBox.Text + '\\' + GetChartAudio(current_level, ChartComboBox.SelectedIndex); level.Backgroundpath = Chart_folderTextBox.Text + '\\' + current_level.background.path; level.Chartpath = Chart_folderTextBox.Text + '\\' + current_level.charts[ChartComboBox.SelectedIndex].path; #region Determine chart type string chart = File.ReadAllText(level.Chartpath).Trim(); if (chart[0] == '{') { level.useOldFormat = false; } else { level.useOldFormat = true; } #endregion level.Save(c2_directory + "\\Settings.txt"); #endregion #region Create wav file bool generated_wav = false; if (!File.Exists(level.Musicpath)) { CacheWav cache = null; string cachefile_path = level.Musicpath.Substring(0, level.Musicpath.Length - 3) + "mp3.cachewav"; if (File.Exists(cachefile_path)) { cache = CacheWav.Load(cachefile_path); } else { cache = new CacheWav(cachefile_path.Substring(0, cachefile_path.Length - 9)); } File.WriteAllBytes(level.Musicpath, cache.GetWav()); cache.Save(); generated_wav = true; } #endregion #region Launch Cytus 2 Player string cwd = Environment.CurrentDirectory; Environment.CurrentDirectory = c2_directory; Process c2p_process = new Process(); c2p_process.StartInfo = new ProcessStartInfo("PlayerDemo.exe"); c2p_process.Start(); c2p_process.WaitForExit(); #endregion #region Clean up Environment.CurrentDirectory = cwd; File.WriteAllText(c2_directory + "\\Settings.txt", backup_settings_txt, Encoding.UTF8); if (generated_wav) { File.Delete(level.Musicpath); } #endregion #endregion } else { #region Cytoid #region Copy level to play directory if (!Directory.Exists(play_directory)) { Directory.CreateDirectory(play_directory); } Directory.Delete(play_directory, true); ATEMMethods.CopyDirectory(Chart_folderTextBox.Text, play_directory); JSON.Level level = current_level.Clone(); level.charts = new JSON.Chart[] { level.charts[ChartComboBox.SelectedIndex] }; level.charts[0].music_override = new JSON.File() { path = GetChartAudio(level, 0) }; level.Save(play_directory + "\\level.json"); #endregion #region Create wav file if (!File.Exists(play_directory + '\\' + level.charts[0].music_override.path)) { CacheWav cache = null; string cachefile_path = Chart_folderTextBox.Text + '\\' + level.charts[0].music_override.path.Substring(0, level.charts[0].music_override.path.Length - 3) + "mp3.cachewav"; if (File.Exists(cachefile_path)) { cache = CacheWav.Load(cachefile_path); } else { cache = new CacheWav(cachefile_path.Substring(0, cachefile_path.Length - 9)); } File.WriteAllBytes(play_directory + '\\' + level.charts[0].music_override.path, cache.GetWav()); cache.Save(); } #endregion #region Launch Cytoid Player Process cp_process = new Process(); cp_process.StartInfo = new ProcessStartInfo(optionsform.Cytoid_Player_path); cp_process.Start(); cp_process.WaitForExit(); #endregion #endregion } }