void listMods() { modDescriptionLabel.Text = ""; mainModList.Items.Clear(); if (!Directory.Exists(modFolderPath)) { Directory.CreateDirectory(modFolderPath); } var files = Directory.GetFiles(modFolderPath); if (files != null && files.Length > 0) { foreach (string modPath in files) { if (ModFile.isModFile(modPath)) { var mod = new ModFile(modPath); if (mod != null) { mainModList.Items.Add(new ListModItem(mod)); } } } } initialized = true; }
static long getTotalSize(string[] files) { var size = 0L; foreach (string file in files) { if (File.Exists(file) && (ModFile.isModFile(file) || file.EndsWith(".desc"))) { size += new FileInfo(file).Length; } } return(size); }
void AddModBtnClick(object sender, EventArgs e) { addModDialog.ShowDialog(); var fileNames = addModDialog.FileNames; if (fileNames != null && fileNames.Length > 0) { for (int i = 0; i < fileNames.Length; i++) { var file = fileNames[i]; var noPath = Path.GetFileName(file); var descFile = file.Substring(0, file.Length - Path.GetExtension(file).Length) + ".desc"; var mod = new ModFile(file); if (File.Exists(file)) { if (File.Exists(modFolderPath + "\\" + noPath)) { var result = MessageBox.Show("A mod called " + mod.getModName() + " already exists! Do you want to overwrite it?", "Duplicate Mod", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } File.Delete(modFolderPath + "\\" + noPath); } File.Copy(file, modFolderPath + "\\" + noPath); if (File.Exists(descFile)) { if (File.Exists(modFolderPath + "\\" + Path.GetFileName(descFile))) { File.Delete(modFolderPath + "\\" + Path.GetFileName(descFile)); } File.Copy(descFile, modFolderPath + "\\" + Path.GetFileName(descFile)); } } } } listMods(); }
public static bool saveCurrentConfig(string modFolder, string configName) { createConfigFolder(); if (!Directory.Exists(modFolder)) { return(false); } var files = Directory.GetFiles(modFolder); if (files == null || files.Length <= 0) { return(false); } var zipFile = savedConfigFolder + "\\" + configName + ".zip"; if (File.Exists(zipFile)) { var result = MessageBox.Show("Config '" + configName + "' already exists!\nWould you like to overwrite it?", "Configuration Duplicate!", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { File.Delete(zipFile); } else { return(false); } } var destination = File.Create(zipFile); var zipStream = new ZipOutputStream(destination); zipStream.SetLevel(3); var folderOffset = modFolder.Length + (modFolder.EndsWith("\\") ? 0 : 1); var current = 0l; var progressBar = new ZipProgressBar((int)getTotalSize(files)); progressBar.Show(); foreach (string modFile in files) { if (File.Exists(modFile) && (ModFile.isModFile(modFile) || modFile.EndsWith(".desc"))) { var info = new FileInfo(modFile); var entryName = modFile.Substring(folderOffset); entryName = ZipEntry.CleanName(entryName); var newEntry = new ZipEntry(entryName); newEntry.DateTime = info.LastWriteTime; newEntry.Size = info.Length; zipStream.PutNextEntry(newEntry); var buffer = new byte[4096]; using (var streamReader = File.OpenRead(modFile)) { StreamUtils.Copy(streamReader, zipStream, buffer); } zipStream.CloseEntry(); current += info.Length; progressBar.progressBar.Value = (int)min(progressBar.progressBar.Maximum, (progressBar.progressBar.Value + info.Length)); } } progressBar.Close(); zipStream.IsStreamOwner = true; zipStream.Close(); return(true); }
public static void loadConfiguration(string modFolder, string configName) { createConfigFolder(); if (Directory.Exists(modFolder)) { Directory.CreateDirectory(modFolder); } var zippedConfig = savedConfigFolder + "\\" + configName + ".zip"; if (!File.Exists(zippedConfig)) { MessageBox.Show("'" + configName + "' does not exist!", "No Configuration Exist!"); return; } var files = Directory.GetFiles(modFolder); if (files != null && files.Length > 0) { var hasMods = false; foreach (var file in files) { if (ModFile.isModFile(file)) { hasMods = true; break; } } if (hasMods) { var result = MessageBox.Show("You currently already have some mods installed.\nPlumMod will overwrite any duplicate mods!\nWould you like to continue?", "Possible Duplicates", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } } var progress = new ZipProgressBar((int)new FileInfo(zippedConfig).Length); progress.Show(); ZipFile configZip = null; try { var fStream = File.OpenRead(zippedConfig); configZip = new ZipFile(fStream); foreach (ZipEntry zipEntry in configZip) { if (!zipEntry.IsFile) { continue; } var fileName = zipEntry.Name; var buffer = new byte[4096]; var stream = configZip.GetInputStream(zipEntry); var fullZipToPath = Path.Combine(modFolder, fileName); if (File.Exists(fullZipToPath)) { File.Delete(fullZipToPath); } var directoryName = Path.GetDirectoryName(fullZipToPath); if (directoryName.Length > 0 && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } using (var streamWriter = File.Create(fullZipToPath)) { StreamUtils.Copy(stream, streamWriter, buffer); } progress.progressBar.Value = (int)min(progress.progressBar.Maximum, (progress.progressBar.Value + new FileInfo(fullZipToPath).Length)); } } finally { if (configZip != null) { configZip.IsStreamOwner = true; configZip.Close(); } progress.Close(); } }
public ListModItem(ModFile mod) : base() { this.mod = mod; updateModStatus(); }