private void addModButton_Click(object sender, EventArgs e)
        {
            if (GameLocation == "" || File.Exists(ExecutableLocation) == false)
            {
                MessageBox.Show("Chaos exectuable not found.");
                return;
            }

            if (addModDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string srcPath = Path.GetDirectoryName(addModDialog.FileName);

            string name = "";

            name = File.ReadAllLines(srcPath + "\\ModData.txt")[0];

            name = new string(name.Where(c => !InvalidFileNameChars.Contains(c)).ToArray());

            string destPath = GameLocation + "\\Mods\\" + name + "\\";

            foreach (string dirPath in Directory.GetDirectories(srcPath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dirPath.Replace(srcPath, destPath));
            }

            foreach (string newPath in Directory.GetFiles(srcPath, "*.*", SearchOption.AllDirectories))
            {
                File.Copy(newPath, newPath.Replace(srcPath, destPath), true);
            }

            string i = destPath + "\\icon.png";

            string[] liness = File.ReadAllLines(destPath + "\\ModData.txt");

            ListViewItem item = modView.Items.Add(liness[0]);

            item.SubItems.Add(liness[1]);
            item.SubItems.Add(liness[2]);
            item.SubItems.Add(liness[3]);
            item.ImageKey = name;
            if (File.Exists(i))
            {
                Bitmap icon = new Bitmap(i);
                smallImages.Images.Add(name, icon);
                largeImages.Images.Add(name, icon);
            }
        }
Beispiel #2
0
        public static string CleanInvalidFileName(string fileName)
        {
            fileName = fileName + "";
            fileName = InvalidFileNameChars.Aggregate(fileName, (current, c) => current.Replace(c + "", ""));

            if (fileName.Length > 1)
            {
                if (fileName[0] == '.')
                {
                    fileName = "dot" + fileName.TrimStart('.');
                }
            }

            return(fileName);
        }
Beispiel #3
0
        public static string ToSafeFilename(this string path, char replacement = '_', int maxlen = 128)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(path);
            }

            var chars = path.ToCharArray(0, maxlen > 0 && path.Length > maxlen ? maxlen : path.Length);

            for (int i = 0; i < chars.Length; i++)
            {
                if (InvalidFileNameChars.Contains(chars[i]))
                {
                    chars[i] = replacement;
                }
            }

            return(new string(chars));
        }
Beispiel #4
0
        public string NormalizePath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            if (!path.Any(x => InvalidFileNameChars.Contains(x)) && path[0] != '{')
            {
                path = Path.GetFullPath(path);
            }

            path = path.TrimEnd('\\');

            //Volume Label, we add a slash because some systems (Windows XP) can't handle "C:"
            if (path.Length == 2 && path[1] == ':')
            {
                return(path + "\\");
            }

            return(path);
        }
Beispiel #5
0
 public static bool IsValidFileName(string fileName)
 {
     return(!string.IsNullOrWhiteSpace(fileName) && fileName.All(c => !InvalidFileNameChars.Contains(c)));
 }
Beispiel #6
0
 public static char[] GetInvalidFileNameChars()
 {
     return((char[])InvalidFileNameChars.Clone());
 }
Beispiel #7
0
 public static char[] GetInvalidFileNameChars() => (char[])InvalidFileNameChars.Clone();
Beispiel #8
0
 private static string CleanSubject(string source)
 {
     // Replace any whitespace to single space
     source = Regex.Replace(source, @"\s+", " ");
     return(new string(source.Where(c => !InvalidFileNameChars.Contains(c)).ToArray()));
 }
Beispiel #9
0
 public static bool AnyInvalidFileNameChars(string fileName)
 {
     return(InvalidFileNameChars.Intersect(fileName).Any());
 }
Beispiel #10
0
 public bool IsValidFilename(string filename) =>
 !string.IsNullOrWhiteSpace(filename) && !filename.Any(x => InvalidFileNameChars.Contains(x));
Beispiel #11
0
 public static bool FileHasInvalidChars(FileInfo file)
 {
     return(file.CheckExists() && file.ArgumentNotNull().FullName.IndexOfAny(InvalidFileNameChars.ToArray()) != -1);
 }
        private void createModButton_Click(object sender, EventArgs e)
        {
            if (File.Exists(ExecutableLocation) == false)
            {
                MessageBox.Show("Chaos executable not found.");
                return;
            }

            if (modCreatorFiles.CheckedItems.Count == 0)
            {
                MessageBox.Show("Error: No items were selected to be used in the mod.");
                return;
            }

            if (modCreatorNameBox.Text == "")
            {
                MessageBox.Show("Mod has no name. Please enter one.");
                return;
            }

            if (modCreatorAuthorBox.Text == "")
            {
                MessageBox.Show("Mod has no author. Please enter one.");
                return;
            }

            if (modCreatorVersionBox.Text == "")
            {
                MessageBox.Show("Mod has no version number. Please enter one.");
                return;
            }

            if (modCreatorFiles.CheckedItems.Count >= 300 && MessageBox.Show("Your mod has over 300 files. Remember to only include modified files. Are you sure you would like to create it anyway?", "Many entries", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            string name = modCreatorNameBox.Text;

            bool valid = name.Where(c => InvalidFileNameChars.Contains(c)).ToList().Count > 0;

            if (valid == true)
            {
                MessageBox.Show("Name has invalid filename characters.");
                return;
            }

            string dir = GameLocation + "\\Mods\\";

            Directory.CreateDirectory(dir);
            string modDir = dir + name + "\\";

            bool copyOver = false;

            if (File.Exists(modDir + "ModData.txt") == true)
            {
                DeleteDirectory(DataLocation + "\\Temp\\");
                modDir   = DataLocation + "\\Temp\\";
                copyOver = true;
            }
            else if (Directory.Exists(modDir) && MessageBox.Show("Mod list already has a mod with this name. Would you like to replace it?", "Existing Mod", MessageBoxButtons.YesNo) != DialogResult.Yes)
            {
                return;
            }

            Directory.CreateDirectory(modDir);

            foreach (ListViewItem i in modCreatorFiles.CheckedItems)
            {
                Directory.CreateDirectory(Path.GetDirectoryName(modDir + i.Text));
                File.Copy(i.Tag.ToString(), modDir + i.Text);
            }

            modCreatorIcon.Image?.Save(modDir + "icon.png");

            File.WriteAllLines(modDir + "ModData.txt", new string[] { modCreatorNameBox.Text, modCreatorAuthorBox.Text, modCreatorDescBox.Text, modCreatorVersionBox.Text });

            if (copyOver)
            {
                CopyDirectory(DataLocation + "\\Temp\\", dir + name + "\\");
                foreach (ListViewItem i in modCreatorFiles.Items)
                {
                    if (i.Checked)
                    {
                        continue;
                    }

                    Directory.CreateDirectory(Path.GetDirectoryName(modDir + i.Text));
                    DeleteFile(dir + name + "\\" + i.Text);
                }
                MessageBox.Show("Mod successfully updated.");
                return;
            }

            ListViewItem item = modView.Items.Add(modCreatorNameBox.Text);

            item.SubItems.Add(modCreatorAuthorBox.Text);
            item.SubItems.Add(modCreatorDescBox.Text);
            item.SubItems.Add(modCreatorVersionBox.Text);
            item.ImageKey = name;
            if (modCreatorIcon.Image != null)
            {
                Bitmap icon = new Bitmap(modCreatorIcon.Image);
                smallImages.Images.Add(name, icon);
                largeImages.Images.Add(name, icon);
            }
            MessageBox.Show("Mod successfully created.");
        }