Пример #1
0
        //This function changes the currDirectory of the Client
        //To a new one, and initializes new folders to be created
        public bool changeToDirectory(string destination)
        {
            FileObj newWorkingDir = workingDir.subdirectory.Find(x => x.fileinfo.name == destination);

            if (newWorkingDir == null)
            {
                //Get new folder information if the folder has not been added to the structure yet

                return true;
            }
            else
            {
                if (newWorkingDir.fileinfo.directory)
                {
                    //Just move the working directory over to the new one
                    workingDir = (FolderObj)newWorkingDir;
                    //Append new directory name
                    path.Add(destination);
                    //checks existing structure so it doesn't have to keep rebuilding the structure from scratch if it was already built
                    updateConsistency();
                    return true;
                }
                else
                {
                    //Selected object is not a folder
                    //As of right now, do nothing
                    //However we could return something so it decides to download the file or whatever
                    return false;
                }
            }
        }
Пример #2
0
        //Default Constructor
        public LocalDirectory()
        {
            path = new List<string>();
            parseLocalDirectory();
            DirectoryInfo dinfo = new DirectoryInfo(Directory.GetCurrentDirectory());
            workingDir = new FolderObj("","","",0,dinfo.CreationTime.ToString(),dinfo.Name,getPath(), null);

            initializeDirectory();
        }
Пример #3
0
        public void CreateFolder(string name, string path)
        {
            name = name.ToLower();
            path = path.ToLower();
            if (!string.IsNullOrEmpty(path) && path.ToCharArray().Last() == '/')
            {
                var listOfChars = path.ToCharArray().ToList();
                listOfChars.RemoveAt(listOfChars.Count - 1);
                path = new string(listOfChars.ToArray());
            }
            ValidatePath(name, path);
            IFolder newFolder = new FolderObj(name, path, _constance.DefaultNumberOfElementOnPage);
            var     parent    = GetParentFolder(newFolder);

            _folderContentPageService.ValidateUniquenessOnAllFolderPages(parent, newFolder);
            CreateFolder(newFolder);
        }
Пример #4
0
        private void Form1_Load(object sender, EventArgs e)
        {
            DriveInfo[] Drives = DriveInfo.GetDrives();
            string[] directories;
            ICatalog Current;
            TreeNode node;
            for (int i = 0; i < Drives.Length; i++)
            {
                treeView1.Nodes.Add(Drives[i].Name);
                if (Drives[i].DriveType == DriveType.Removable || Drives[i].DriveType == DriveType.CDRom)
                    continue;
                FolderObj fo = new FolderObj();
                Current = (ICatalog)fo;
                Current.Initialize(Drives[i].Name);
                Current.ReloadFiles();
                int n = Current.GetDirectoriesCount();
                if (n == 0)
                    continue;
                directories = new string[n];
                for (int j = 0; j < n; j++)
                    directories[j] = Current.GetDirectoryName(j);

                foreach (var directory in directories)
                {
                    node = new TreeNode(directory);
                    node.ImageIndex = 0;
                    treeView1.Nodes[i].Nodes.Add(node);
                }
            }
            for(int i=0; i < treeView1.Nodes.Count; i++)
            {
                DriveInfo di = new DriveInfo(treeView1.Nodes[i].Text);
                if (di.DriveType == DriveType.Fixed)
                {
                    treeView1.SelectedNode = treeView1.Nodes[i];
                    return;
                }
            }
        }
Пример #5
0
 private void treeView1_BeforeExpand(object sender, TreeViewCancelEventArgs e)
 {
     ICatalog cat;
     TreeNode temp;
     foreach (TreeNode node in e.Node.Nodes)
     {
         node.Nodes.Clear();
         FolderObj fo = new FolderObj();
         cat = (ICatalog)fo;
         cat.Initialize(node.FullPath);
         string[] directories;
         cat.ReloadFiles();
         int n = cat.GetDirectoriesCount();
         if (n == 0)
             continue;
         directories = new string[n];
         for (int i = 0; i < n; i++)
             directories[i] = cat.GetDirectoryName(i);
         foreach (var dir in directories)
         {
             temp = new TreeNode(dir);
             temp.Name = dir;
             node.Nodes.Add(temp);
         }
     }
 }
Пример #6
0
 private void Paste()
 {
     IFSObject temp;
     foreach (var file in copied)
     {
         if (Directory.Exists(file))
         {
             FolderObj fo = new FolderObj();
             temp = (IFSObject)fo;
         }
         else
         {
             FileObj fo = new FileObj();
             temp = (IFSObject)fo;
         }
         temp.Initialize(file);
         if (cutted)
             temp.Move(Current.GetFullPath());
         else
             temp.Copy(Current.GetFullPath());
     }
     OpenDir(Current.GetFullPath());
     foreach(var file in copied)
         listView1.FindItemWithText(Path.GetFileName(file)).Selected = true;
 }
Пример #7
0
 private void OpenDir(string path)
 {
     ListViewItem lvi;
     FolderObj fo = new FolderObj();
     IFSObject temp = null;
     Current = (ICatalog)fo;
     Current.Initialize(path);
     Current.ReloadFiles();
     listView1.Items.Clear();
     string[] files;
     int n = Current.GetFileSystemEntriesCount();
     if (n == 0)
         return;
     files = new string[n];
     for (int i = 0; i < n; i++)
         files[i] = Current.GetFileSystemEntryName(i);
     for(int i=0; i < files.Length; i++)
     {
         temp = Current.GetFile(i);
         if (temp.isDir() == 1)
             lvi = new ListViewItem(files[i], 0);
         else
             lvi = new ListViewItem(files[i], 1);
         listView1.Items.Add(lvi);
     }
     textBox1.Text = path;
 }
Пример #8
0
 private void LoadDirs(TreeNode node)
 {
     FolderObj fo = new FolderObj();
     ICatalog temp = (ICatalog)fo;
     temp.Initialize(node.FullPath);
     temp.ReloadFiles();
     string[] directories;
     int n = temp.GetDirectoriesCount();
     if (n == 0)
         return;
     directories = new string[n];
     for (int i = 0; i < n; i++)
         directories[i] = temp.GetDirectoryName(i);
     foreach (var directory in directories)
         node.Nodes.Add(directory);
 }
Пример #9
0
        //To the parent directory, (if it exist)
        public void changeToParentDirectory()
        {
            if (workingDir.parentDir != null)
            {
                //Remove the directory from the currDirectory string
                //The length +2 is to account for the starting '/' and ending '/'
                path.RemoveAt(path.Count - 1);
                workingDir = workingDir.parentDir;
            }
            else
            {
                //check if parent exist
                DirectoryInfo dinfo = new DirectoryInfo(Directory.GetCurrentDirectory() + "/../");

                if (dinfo.Exists)
                {

                    //remove at end
                    if (path.Count > 1)
                    path.RemoveAt(path.Count - 1);

                    //checks existing structure so it doesn't have to keep rebuilding the structure from scratch if it was already built
                    //save a temp of the current working directory

                    FolderObj parent = new FolderObj("", "", "", 0, dinfo.CreationTime.ToString(), dinfo.Name, getPath(), null);
                    workingDir.parentDir = parent;
                    parent.subdirectory.Add(workingDir);
                    workingDir = workingDir.parentDir;
                    updateConsistency();

                }
                else
                {
                    Console.WriteLine("ERROR: Current Directory has no Parent");
                }
            }
        }
Пример #10
0
        /*Update consistency is going to look through current version of its subdirectory
        * then compares the names of every file on the local machines's directory with what it has
        * saved at the location given by currentPath, If there is something new not added, it will add it,
         * if thing has been removed it will remove it*/
        private void updateConsistency(FolderObj workingDir, string currentPath)
        {
            List<FileObj> fileData = new List<FileObj>();
            FileInfo currFile;
            DirectoryInfo currDir;

            foreach (string folders in Directory.GetDirectories(currentPath))
            {
                currDir = new DirectoryInfo(folders);
                fileData.Add(new FolderObj(" ", "", "", 0, currDir.CreationTime.ToString(), currDir.Name, currentPath + currDir.Name + "/", null));
            }
            foreach (string files in Directory.GetFiles(currentPath))
            {
                currFile = new FileInfo(files);
                fileData.Add(new FileObj(currFile.IsReadOnly.ToString(), "", "", (UInt64)currFile.Length, currFile.CreationTime.ToString(), currFile.Name, currentPath));
            }

            //If the directory we are going to is empty, we don't need to do anything, except clear.
            if (fileData == null)
            {
                workingDir.subdirectory.Clear();
                return;
            }
            if (fileData.Count == 0)
            {
                workingDir.subdirectory.Clear();
                return;
            }
            //Sort the two list before performing the algorithm
            fileData.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
            workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
            int i = 0; //marker for currConsistency
            int j = 0; //marker for workingDir

            //The idea with this algorithm is to traverse both list simultaneously and
            //find any disparities
            while (i < fileData.Count && j < workingDir.subdirectory.Count)
            {
                if (string.Compare(fileData[i].fileinfo.name, workingDir.subdirectory[j].fileinfo.name) == 0)
                {
                    //Item exist in both list, so skip it
                    i++;
                    j++;
                }
                else if (string.Compare(fileData[i].fileinfo.name, workingDir.subdirectory[j].fileinfo.name) > 0)
                {
                    //remove working directory's jth entry
                    workingDir.subdirectory.RemoveAt(j);
                    workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                    j++;
                    i++;
                }
                else if (string.Compare(fileData[i].fileinfo.name, workingDir.subdirectory[j].fileinfo.name) < 0)
                {
                    //Add to working directory
                    workingDir.AddToSubDirectory(fileData[i].fileinfo);
                    workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                    j++;
                    i++;
                }
            }
            while (j < workingDir.subdirectory.Count)
            {
                //remove remaining items
                //remove working directory's jth entry
                workingDir.subdirectory.RemoveAt(j);
                workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                j++;
                i++;
            }
            while (i < fileData.Count)
            {
                //Add to working directory
                workingDir.AddToSubDirectory(fileData[i].fileinfo);
                workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                i++;
            }
        }
Пример #11
0
        //This function changes the currDirectory of the Client
        //To the parent directory, (if it exist)
        public void changeToParentDirectory(Client client)
        {
            if (workingDir.parentDir != null)
            {
                //Remove the directory from the currDirectory string
                //The length +2 is to account for the starting '/' and ending '/'
                client.currDirectory = client.currDirectory.Remove(client.currDirectory.Length - (workingDir.fileinfo.name.Length + 1), (workingDir.fileinfo.name.Length + 1));
                workingDir = workingDir.parentDir;
            }
            else
            {
                if (client.isFile(".."))
                {
                    //Append new directory name, and then move
                    if (!client.currDirectory.EndsWith("/"))
                    {
                        client.currDirectory += "/";
                    }
                    client.currDirectory += "..";
                    //checks existing structure so it doesn't have to keep rebuilding the structure from scratch if it was already built
                    //save a temp of the current working directory
                    FolderObj temp = workingDir;
                    workingDir.subdirectory.Clear();
                    workingDir.subdirectory.Add(temp);
                    temp.parentDir = workingDir;
                    updateConsistency(client);

                }
                Console.WriteLine("ERROR: Current Directory has no Parent");
            }
        }
Пример #12
0
 //Default Constructor
 public RemoteDirectory()
 {
     /*by default, the parent directory of the starting folder is just null*/
     workingDir = new FolderObj("", null);
 }
Пример #13
0
        /*Update consistency is going to look through current version of its subdirectory
        * then compares the names of every file on the server's directory with what it has
        * passed in as a currPath, If there is something new not added, it will add it, if thing
         * has been removed it will remove it*/
        public void updateConsistency(Client client, FolderObj workingDir, string currPath)
        {
            string tempPath = client.currDirectory;
            client.currDirectory = currPath;
            List<string> currConsistency = client.getCurrDetailedDirectory();
            //If the directory we are going to is empty, we don't need to do anything, except clear.
            if (currConsistency == null)
            {
                workingDir.subdirectory.Clear();
                return;
            }
            if (currConsistency.Count == 0)
            {
                workingDir.subdirectory.Clear();
                return;
            }

            List<FileObj.FileInfo> fileData = FileObj.parseFileInfo(currConsistency, client.currDirectory);
            //Sort the two list before performing the algorithm
            fileData.Sort((x, y) => x.name.CompareTo(y.name));
            workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
            int i = 0; //marker for currConsistency
            int j = 0; //marker for workingDir

            //The idea with this algorithm is to traverse both list simultaneously and
            //find any disparities
            while (i < currConsistency.Count && j < workingDir.subdirectory.Count)
            {
                if (string.Compare(fileData[i].name, workingDir.subdirectory[j].fileinfo.name) == 0)
                {
                    //Item exist in both list, so skip it
                    i++;
                    j++;
                }
                else if (string.Compare(fileData[i].name, workingDir.subdirectory[j].fileinfo.name) > 0)
                {
                    //remove working directory's jth entry
                    workingDir.subdirectory.RemoveAt(j);
                    workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                    j++;
                    i++;
                }
                else if (string.Compare(fileData[i].name, workingDir.subdirectory[j].fileinfo.name) < 0)
                {
                    //Add to working directory
                    workingDir.AddToSubDirectory(fileData[i]);
                    workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                    j++;
                    i++;
                }
            }
            while (j < workingDir.subdirectory.Count)
            {
                //remove remaining items
                //remove working directory's jth entry
                workingDir.subdirectory.RemoveAt(j);
                workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                j++;
            }
            while (i < fileData.Count)
            {
                //Add to working directory
                workingDir.AddToSubDirectory(fileData[i]);
                workingDir.subdirectory.Sort((x, y) => x.fileinfo.name.CompareTo(y.fileinfo.name));
                i++;
            }
            client.currDirectory = tempPath;
        }