Exemplo n.º 1
0
        private bool CreateModuleFolder(bool directoryNew = true)
        {
            string        modPath         = ProgramConsole.OriginalModPath;
            string        destPath        = ProgramConsole.DestinationModPath;
            List <string> textFileEndings = new List <string>()
            {
                "TXT", "INI", "H", "FX", "CSV"
            };
            DialogResult forceOverride = DialogResult.Yes;

            if (!directoryNew)
            {
                directoryNew = !Directory.Exists(destPath);
            }

            if (!directoryNew)
            {
                forceOverride = ShowErrorPathAlreadyExists(destPath);
            }

            if (!directoryNew && forceOverride != DialogResult.Yes)
            {
                return(false);
            }

            //if (!directoryNew)
            Directory.CreateDirectory(destPath);

            if (!copyTextFiles_cb.Checked)
            {
                return(true);
            }

            List <string> paths = GetAllPaths(modPath.TrimEnd('\\'));

            foreach (string path in paths)
            {
                string px         = path.Replace(modPath, string.Empty);
                string fileEnding = string.Empty;

                if (px.Contains("."))
                {
                    fileEnding += path.Substring(path.LastIndexOf('.') + 1).ToUpper();
                }

                if (CodeReader.CountCharInString(px, '\\') > 0)
                {
                    string dir = destPath + Path.GetDirectoryName(px);
                    //if (!Directory.Exists(dir))
                    Directory.CreateDirectory(dir);
                    if (textFileEndings.Contains(fileEnding) || copyNonTextFiles_cb.CheckState != CheckState.Unchecked)
                    {
                        File.Copy(path, dir + '\\' + Path.GetFileName(px), !directoryNew);
                    }
                }
                else if (textFileEndings.Contains(fileEnding) || copyNonTextFiles_cb.CheckState != CheckState.Unchecked)
                {
                    File.Copy(path, destPath + Path.GetFileName(path), !directoryNew);
                }
            }

            return(true);
        }