GetInvalidPathChars() 공개 정적인 메소드

public static GetInvalidPathChars ( ) : char[]
리턴 char[]
예제 #1
0
        private async void CreateFolder(string folderName)
        {
            if (string.IsNullOrWhiteSpace(folderName))
            {
                MessageBox.Show("Invalid folder name");
                return;
            }
            List <char> invalidChars = Path.GetInvalidFileNameChars().ToList();

            invalidChars.AddRange(Path.GetInvalidPathChars().ToList());
            foreach (char c in invalidChars)
            {
                if (folderName.Contains(c))
                {
                    MessageBox.Show(string.Format("value '{0}' is invalid for name", c));
                    return;
                }
            }
            CreatingFolderTextBlock.Visibility = Visibility.Visible;
            try
            {
                await Utils.FTPMakeFolderAsync(string.Format("{0}{1}", FTPPath, folderName), Credential);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            FTPReturnFolderName = folderName;
            FTPReturnPath       = string.Format("{0}{1}/", FTPPath, folderName);
            DialogResult        = true;
            Close();
        }
        private void SelectFfmpeg_Click(object sender, RoutedEventArgs e)
        {
            var output = UserSettings.All.FfmpegLocation ?? "";

            if (output.ToCharArray().Any(x => Path.GetInvalidPathChars().Contains(x)))
            {
                output = "";
            }

            //It's only a relative path if not null/empty and there's no root folder declared.
            var isRelative = !string.IsNullOrWhiteSpace(output) && !Path.IsPathRooted(output);
            var notAlt     = !string.IsNullOrWhiteSpace(output) && (UserSettings.All.FfmpegLocation ?? "").Contains(Path.DirectorySeparatorChar);

            //Gets the current directory folder, where the file is located. If empty, it means that the path is relative.
            var directory = !string.IsNullOrWhiteSpace(output) ? Path.GetDirectoryName(output) : "";

            if (!string.IsNullOrWhiteSpace(output) && string.IsNullOrWhiteSpace(directory))
            {
                directory = AppDomain.CurrentDomain.BaseDirectory;
            }

            var initial = Directory.Exists(directory) ? directory : Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            var ofd = new OpenFileDialog
            {
                FileName         = "ffmpeg",
                Filter           = "FFmpeg executable (*.exe)|*.exe", //TODO: Localize.
                Title            = LocalizationHelper.Get("Extras.FfmpegLocation.Select"),
                InitialDirectory = isRelative ? Path.GetFullPath(initial) : initial,
                DefaultExt       = ".exe"
            };

            var result = ofd.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            UserSettings.All.FfmpegLocation = ofd.FileName;

            //Converts to a relative path again.
            if (isRelative && !string.IsNullOrWhiteSpace(UserSettings.All.FfmpegLocation))
            {
                var selected       = new Uri(UserSettings.All.FfmpegLocation);
                var baseFolder     = new Uri(AppDomain.CurrentDomain.BaseDirectory);
                var relativeFolder = Uri.UnescapeDataString(baseFolder.MakeRelativeUri(selected).ToString());

                //This app even returns you the correct slashes/backslashes.
                UserSettings.All.FfmpegLocation = notAlt ? relativeFolder : relativeFolder.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            }

            CheckTools();
        }
예제 #3
0
        public DataDir(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentException(nameof(path), "Path cannot be null or empty.");
            }
            if (path.IndexOfAny(PathType.GetInvalidPathChars()) != -1)
            {
                throw new ArgumentException(nameof(path), "Path contains an invalid character.");
            }

            Path = PathType.GetFullPath(path);
        }
예제 #4
0
        private bool IsProjectDirectoryValidish(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(false);
            }

            var invalidVars = IOPath.GetInvalidPathChars();

            if (path.Any(c => { return(invalidVars.Contains(c)); }))
            {
                return(false);
            }

            return(true);
        }
예제 #5
0
        private void SelectFfmpeg_Click(object sender, RoutedEventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                FileName = "ffmpeg.exe",
                Filter   = "FFmpeg executable (*.exe)|*.exe",
                Title    = FindResource("Extras.FfmpegLocation.Select") as string
            };

            //TODO: Localize.

            //Current location.
            if (!string.IsNullOrWhiteSpace(UserSettings.All.FfmpegLocation) && !UserSettings.All.FfmpegLocation.ToCharArray().Any(x => Path.GetInvalidPathChars().Contains(x)))
            {
                var directory = Path.GetDirectoryName(UserSettings.All.FfmpegLocation);

                if (!string.IsNullOrWhiteSpace(directory) && Directory.Exists(directory))
                {
                    ofd.InitialDirectory = directory;
                }
            }

            if (ofd.ShowDialog(this).Value)
            {
                UserSettings.All.FfmpegLocation = ofd.FileName;
            }
        }
예제 #6
0
        private void buttonCreateShortcut_Click(object sender, RoutedEventArgs e)
        {
            #region Verify
            if (string.IsNullOrEmpty(textBoxShortcutName.Text))
            {
                textBoxShortcutName.Focus();
                // TODO: [NOTIFICATION] 파일 이름을 입력하세요.
                // 텍스트 박스 붉은 빛으로 깜빡이기
                return;
            }

            char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
            int    invalidCharIndex     = textBoxShortcutName.Text.IndexOfAny(invalidFileNameChars);
            if (invalidCharIndex != -1)
            {
                int lastInvalidCharIndex = textBoxShortcutName.Text.LastIndexOfAny(invalidFileNameChars);
                textBoxShortcutName.Focus();
                textBoxShortcutName.Select(invalidCharIndex, Math.Max(lastInvalidCharIndex - invalidCharIndex, 1));
                // TODO: [NOTIFICATION] 파일 이름에 이상한 문자가 있습니다. 파일 이름에 다음의 문자들은 사용할 수 없습니다. invalidFileNameChars
                // 텍스트 박스 붉은 빛으로 깜빡이기
                return;
            }
            #endregion

            try
            {
                string directory   = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
                string filename    = textBoxShortcutName.Text;
                string description = "Execute Bibimbaaaaaab with custom arguments.";
                string arguments   = textBoxCommandLine.Text;

                #region Create Shortcut
                if (directory.IndexOfAny(Path.GetInvalidPathChars()) != -1)
                {
                    throw new ArgumentException("directory");
                }
                if (filename.IndexOfAny(Path.GetInvalidFileNameChars()) != -1)
                {
                    throw new ArgumentException("filename");
                }

                WshShell     shell        = new WshShell();
                string       shortcutPath = Path.ChangeExtension(Path.Combine(directory, filename), "lnk");
                IWshShortcut shortcut     = (IWshShortcut)shell.CreateShortcut(shortcutPath);
                shortcut.TargetPath       = System.Reflection.Assembly.GetEntryAssembly().CodeBase;
                shortcut.WorkingDirectory = Path.GetDirectoryName(shortcut.TargetPath);
                shortcut.Arguments        = arguments;
                shortcut.Description      = description;
                shortcut.Save();
                #endregion
            }
            catch (Exception ex)
            {
                // TODO: [NOTIFICATION] 바로가기를 만드는 중 문제가 발생하였습니다.
                throw ex;
            }

            // TODO: [NOTIFICATION] 성공하였습니다.
            // 버튼 주위에 툴팁 보여주기
            textBoxShortcutName.Text = string.Empty;
        }
예제 #7
0
        protected override async Task <DatabaseTaskOutcome> RunImplementation()
        {
            if (includeDocuments == false && includeAttachements == false && includeIndexes == false && includeTransformers == false)
            {
                return(DatabaseTaskOutcome.Abandoned);
            }

            var saveFile = new SaveFileDialog
            {
                DefaultExt = ".ravendump",
                Filter     = "Raven Dumps|*.ravendump;*.raven.dump",
            };

            var name            = ApplicationModel.Database.Value.Name;
            var normalizedName  = new string(name.Select(ch => Path.GetInvalidPathChars().Contains(ch) ? '_' : ch).ToArray());
            var defaultFileName = string.Format("Dump of {0}, {1}", normalizedName, DateTimeOffset.Now.ToString("dd MMM yyyy HH-mm", CultureInfo.InvariantCulture));

            try
            {
                saveFile.DefaultFileName = defaultFileName;
            }
            catch { }

            if (saveFile.ShowDialog() != true)
            {
                return(DatabaseTaskOutcome.Abandoned);
            }

            using (var stream = saveFile.OpenFile())
            {
                ItemType operateOnTypes = 0;

                if (includeDocuments)
                {
                    operateOnTypes |= ItemType.Documents;
                }

                if (includeAttachements)
                {
                    operateOnTypes |= ItemType.Attachments;
                }

                if (includeIndexes)
                {
                    operateOnTypes |= ItemType.Indexes;
                }

                if (removeAnalyzers)
                {
                    operateOnTypes |= ItemType.RemoveAnalyzers;
                }

                if (includeTransformers)
                {
                    operateOnTypes |= ItemType.Transformers;
                }

                var smuggler = new SmugglerApi(new SmugglerOptions
                {
                    BatchSize = batchSize
                },
                                               DatabaseCommands,
                                               message => Report(message));

                var forwardtoUiBoundStream = new ForwardtoUIBoundStream(stream);
                var taskGeneration         = new Task <Task>(() => smuggler.ExportData(forwardtoUiBoundStream, new SmugglerOptions
                {
                    BatchSize            = batchSize,
                    Filters              = filterSettings,
                    TransformScript      = transformScript,
                    ShouldExcludeExpired = shouldExcludeExpired,
                    OperateOnTypes       = operateOnTypes
                }, false));

                ThreadPool.QueueUserWorkItem(state => taskGeneration.Start());


                await taskGeneration.Unwrap();

                forwardtoUiBoundStream.Flush();
                stream.Flush();
            }

            return(DatabaseTaskOutcome.Succesful);
        }
예제 #8
0
 public void TestGetInvalidPathChars() => Assert.IsTrue(Pri.LongPath.Path.GetInvalidPathChars().SequenceEqual(Path.GetInvalidPathChars()));
예제 #9
0
        /// <summary>
        /// 在指定路径(shp/mdb/gdb)中创建新的要素类,并返回该要素类(注意路径中不能存在同名要素类)
        /// </summary>
        /// <param name="fullPath">
        /// 要素类的完整保存路径,包含以下情况:
        /// ①shp文件路径,创建shp文件;若shp文件所在目录不存在则自动创建;
        /// ②mdb文件路径[\DatasetName]\FeatureClassName,在mdb中或mdb的指定要素集中,创建指定名称的图层;若mdb或要素集不存在则自动创建;
        /// ③gdb目录[\DatasetName]\FeatureClassName,在gdb中或gdb的指定要素集中,创建指定名称的图层;若gdb或要素集不存在则自动创建;
        /// </param>
        /// <param name="fields">要创建的字段集,必须包含OID和SHAPE字段,创建字段集可参考<see cref="FieldOpt.CreateBaseFields"/>等方法</param>
        /// <returns></returns>
        public static IFeatureClass CreateToPath(string fullPath, IFields fields)
        {
            const string _shp = ".shp", _mdb = ".mdb", _gdb = ".gdb";
            var          chars = Path.GetInvalidPathChars();

            foreach (var c in chars)
            {
                if (fullPath.Contains(c))
                {
                    throw new Exception("路径不符合规范,文件路径不能包含以下字符串:" + string.Concat(chars));
                }
            }

            fullPath = fullPath.ToLower();
            if (fullPath.EndsWith(_shp))
            {
                var dir = Path.GetDirectoryName(fullPath);
                if (dir != null)
                {
                    Directory.CreateDirectory(dir);
                    return(CreateToDb(Path.GetDirectoryName(fullPath), Path.GetFileNameWithoutExtension(fullPath), null, fields));
                }
            }
            else if (fullPath.Contains(_mdb))
            {
                var dbPath = fullPath.Substring(0, fullPath.IndexOf(_mdb, StringComparison.OrdinalIgnoreCase));
                if (!File.Exists(dbPath))
                {
                    var workspace = WorkspaceEx.NewWorkspace(EWorkspaceType.Access, Path.GetDirectoryName(dbPath), Path.GetFileNameWithoutExtension(dbPath));
                    Marshal.ReleaseComObject(workspace);
                }

                var names = fullPath.Replace(dbPath, "").Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
                if (names.Length == 1)
                {
                    return(CreateToDb(dbPath, null, names[0], fields));
                }
                if (names.Length == 2)
                {
                    return(CreateToDb(dbPath, names[0], names[1], fields));
                }
            }
            else if (fullPath.Contains(_gdb))
            {
                var dbPath = fullPath.Substring(0, fullPath.IndexOf(_gdb, StringComparison.OrdinalIgnoreCase));
                if (!Directory.Exists(dbPath))
                {
                    var dirInfo = new DirectoryInfo(dbPath);
                    if (dirInfo.Parent == null)
                    {
                        throw new Exception($"路径“{dbPath}”不是有效的文件地理数据库路径!");
                    }
                    var workspace = WorkspaceEx.NewWorkspace(EWorkspaceType.FileGDB, dirInfo.Parent.FullName, dirInfo.Name);
                    Marshal.ReleaseComObject(workspace);
                }
                var names = fullPath.Replace(dbPath, "").Split(new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
                if (names.Length == 1)
                {
                    return(CreateToDb(dbPath, null, names[0], fields));
                }
                if (names.Length == 2)
                {
                    return(CreateToDb(dbPath, names[0], names[1], fields));
                }
            }
            return(null);
        }