Ejemplo n.º 1
0
        public enPathType PathIs(IActivityIOPath path)
        {
            enPathType result = enPathType.File;

            // WARN : here for now because FTP has no way of knowing of the user wants a directory or file?!?!
            if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
            {
                result = enPathType.Directory;
            }
            return(result);
        }
        private static enPathType IsDirectory(IActivityIOPath path, enPathType result)
        {
            if (!Dev2ActivityIOPathUtils.IsStarWildCard(path.Path))
            {
                var fa = File.GetAttributes(path.Path);

                if ((fa & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    result = enPathType.Directory;
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        public enPathType PathIs(IActivityIOPath path)
        {
            enPathType result = enPathType.File;

            if (path.Path.StartsWith("\\\\"))
            {
                if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
                {
                    result = enPathType.Directory;
                }
            }
            else
            {
                //  && FileExist(path)
                if (FileExist(path) || DirectoryExist(path))
                {
                    if (!Dev2ActivityIOPathUtils.IsStarWildCard(path.Path))
                    {
                        FileAttributes fa = File.GetAttributes(path.Path);

                        if ((fa & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            result = enPathType.Directory;
                        }
                    }
                }
                else
                {
                    if (Dev2ActivityIOPathUtils.IsDirectory(path.Path))
                    {
                        result = enPathType.Directory;
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        private bool CheckFile(string strPlaylist, int iStart, int iEnd, string basePath, ref string fullPath, ref enPathType PathType)
        {
            // 3) get the path from that boundarys
            string orgPath = strPlaylist.Substring(iStart, iEnd - iStart + 1);

            fullPath = orgPath;

            // 4) check with fileinfo if the path is valid, add to list if valid
            bool bFileExists = false;


            if (!bFileExists) // absolute Paths
            {
                try
                {
                    System.IO.FileInfo fileinfo = new System.IO.FileInfo(orgPath);
                    bFileExists = System.IO.File.Exists(orgPath);

                    PathType = enPathType.absolute;
                }
                catch (Exception ex)
                {
                    // continue
                }
            }

            if (!bFileExists) // M3U style paths - absolute Paths without Root
            {
                try
                {
                    //string basePathDir = System.IO.Path.GetDirectoryName(basePath);
                    fullPath = TaskPlanner.UsefulMethods.PlaylistCombinePaths(basePath, orgPath);
                    System.IO.FileInfo fileinfo = new System.IO.FileInfo(fullPath);
                    bFileExists = System.IO.File.Exists(fullPath);

                    PathType = enPathType.absolute;
                }
                catch (Exception ex2)
                {
                    //continue;
                }
            }



            if (!bFileExists) // relative Paths
            {
                try
                {
                    string basePathDir = System.IO.Path.GetDirectoryName(basePath);
                    fullPath = System.IO.Path.Combine(basePathDir, orgPath);
                    System.IO.FileInfo fileinfo = new System.IO.FileInfo(fullPath);
                    bFileExists = System.IO.File.Exists(fullPath);

                    PathType = enPathType.relative;
                }
                catch (Exception ex2)
                {
                    //continue;
                }
            }


            // 5) Path can be added
            return(bFileExists);
        }
Ejemplo n.º 5
0
        private List <ValidPath> GetAllValidPathsFromString(string strPlaylist, string basePath) // string can be any playlist format
        {
            // Boundary condidtions
            // The paths always contain a ".xxx" ending
            // The path can be inside ""(.wpl) or fill up its own line(.m3u) or after a "="(.kpl)
            // The path can be absolute or relative

            List <ValidPath> listValidPaths = new List <ValidPath>();

            // Procedure:
            // 1) advance the string until a "." is found
            for (int i = 0; i < strPlaylist.Length; i++)
            {
                if (strPlaylist[i] == '.')
                {
                    // 2) from there move back and forth until a invalid path char is found
                    char[] invalidChars = System.IO.Path.GetInvalidPathChars();

                    int iStart = i, iEnd = i;
                    if (GetBoundarys(strPlaylist, invalidChars, ref iStart, ref iEnd, false)) // Normally
                    {
                        string     fullpath = "";
                        enPathType pathType = enPathType.absolute;
                        if (CheckFile(strPlaylist, iStart, iEnd, basePath, ref fullpath, ref pathType)) // 3) check if path ok
                        {
                            ValidPath validPath = new ValidPath();

                            validPath.strValidPath = fullpath;
                            validPath.iEnd         = iEnd;
                            validPath.iStart       = iStart;
                            validPath.PathType     = pathType;

                            listValidPaths.Add(validPath);
                            i = iEnd + 1;
                            continue;
                        }
                    }

                    iStart = i;
                    iEnd   = i;
                    if (GetBoundarys(strPlaylist, invalidChars, ref iStart, ref iEnd, true)) // In case of KPL
                    {
                        string     fullpath = "";
                        enPathType pathType = enPathType.absolute;
                        if (CheckFile(strPlaylist, iStart, iEnd, basePath, ref fullpath, ref pathType)) // 3) check if path ok
                        {
                            ValidPath validPath = new ValidPath();

                            validPath.strValidPath = fullpath;
                            validPath.iEnd         = iEnd;
                            validPath.iStart       = iStart;
                            validPath.PathType     = pathType;

                            listValidPaths.Add(validPath);
                            i = iEnd + 1;
                            continue;
                        }
                    }
                }
            }

            return(listValidPaths);
        }