fCraft.Paths.Contains C# (CSharp) Method

Contains() public static method

Checks whether childPath is inside parentPath
public static Contains ( [ parentPath, [ childPath ) : bool
parentPath [ Path that is supposed to contain childPath
childPath [ Path that is supposed to be contained within parentPath
return bool
        public static bool Contains( [NotNull] string parentPath, [NotNull] string childPath )
        {
            if ( parentPath == null )
                throw new ArgumentNullException( "parentPath" );
            if ( childPath == null )
                throw new ArgumentNullException( "childPath" );
            return Contains( parentPath, childPath, MonoCompat.IsCaseSensitive );
        }

Same methods

Paths::Contains ( [ parentPath, [ childPath, bool caseSensitive ) : bool

Usage Example

Example #1
0
        public static string FindMapFile([NotNull] Player player, [NotNull] string fileName)
        {
            if (player == null)
            {
                throw new ArgumentNullException("player");
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            // Check if path contains missing drives or invalid characters
            if (!Paths.IsValidPath(fileName))
            {
                player.Message("Invalid filename or path.");
                return(null);
            }

            // Look for the file
            string sourceFullFileName = Path.Combine(Paths.MapPath, fileName);

            if (!File.Exists(sourceFullFileName) && !Directory.Exists(sourceFullFileName))
            {
                if (File.Exists(sourceFullFileName + ".fcm"))
                {
                    // Try with extension added
                    sourceFullFileName += ".fcm";
                }
                else if (MonoCompat.IsCaseSensitive)
                {
                    try {
                        // If we're on a case-sensitive OS, try case-insensitive search
                        FileInfo[] candidates = Paths.FindFiles(sourceFullFileName + ".fcm");
                        if (candidates.Length == 0)
                        {
                            candidates = Paths.FindFiles(sourceFullFileName);
                        }

                        if (candidates.Length == 0)
                        {
                            player.Message("File/directory not found: {0}", fileName);
                        }
                        else if (candidates.Length == 1)
                        {
                            player.Message("Filenames are case-sensitive! Did you mean to load \"{0}\"?", candidates[0].Name);
                        }
                        else
                        {
                            player.Message("Filenames are case-sensitive! Did you mean to load one of these: {0}",
                                           String.Join(", ", candidates.Select(c => c.Name).ToArray()));
                        }
                    } catch (DirectoryNotFoundException ex) {
                        player.Message(ex.Message);
                    }
                    return(null);
                }
                else
                {
                    // Nothing found!
                    player.Message("File/directory not found: {0}", fileName);
                    return(null);
                }
            }

            // Make sure that the given file is within the map directory
            if (!Paths.Contains(Paths.MapPath, sourceFullFileName))
            {
                player.MessageUnsafePath();
                return(null);
            }

            return(sourceFullFileName);
        }
All Usage Examples Of fCraft.Paths::Contains