Ejemplo n.º 1
0
        //Returns the two array attached to a session
        public ArrayList GetTemporaryArray(string sSession, bool FileList = false)
        {
            for (int i = 0; i < aTemporarySessions.Count; i++)
            {
                TemporarySession aTempSession = ((TemporarySession)aTemporarySessions[i]);
                if (aTempSession.sID == sSession)
                {
                    if (!FileList)
                    {
                        return(aTempSession.aTemporaryVariables);
                    }
                    else
                    {
                        return(aTempSession.aFileList);
                    }
                }
            }

            //Create an temporary session variable since it did not exist
            TemporarySession temporarySession = new TemporarySession
            {
                sID                 = sSession,
                aFileList           = new ArrayList(),
                aTemporaryVariables = new ArrayList()
            };

            aTemporarySessions.Add(temporarySession);

            if (!FileList)
            {
                return(temporarySession.aTemporaryVariables);
            }
            else
            {
                return(temporarySession.aFileList);
            }
        }
Ejemplo n.º 2
0
        public ArrayList GenerateFilelist(string sSession, string sPath, string sParent = "")
        {
            ArrayList aFileList = new ArrayList();

            //Not logged in, then no go...
            if (!SessionLoggedIn(sSession, GetTemporaryVariable(sSession, "Username")))
            {
                return(aFileList);
            }

            if (Directory.Exists(sPath))
            {
                //Get the sort-string; NAME, MODIFY, SIZE
                string sSorting = GetTemporaryVariable(sSession, "Sorting");
                if (sSorting.Length == 0)
                {
                    sSorting = "NAME";
                }

                DirectoryInfo[] dirArray   = null;
                FileInfo[]      filesArray = null;

                if (sSorting == "MODIFY")
                {
                    dirArray = new DirectoryInfo(sPath)
                               .GetDirectories("*")
                               .OrderByDescending(f => f.LastWriteTime)
                               .ToArray();
                    filesArray = new DirectoryInfo(sPath)
                                 .GetFiles("*")
                                 .OrderByDescending(f => f.LastWriteTime)
                                 .ToArray();
                }
                else if (sSorting == "SIZE")
                {
                    dirArray = new DirectoryInfo(sPath)
                               .GetDirectories("*")
                               .OrderByDescending(f => f.Name)
                               .ToArray();
                    filesArray = new DirectoryInfo(sPath)
                                 .GetFiles("*")
                                 .OrderByDescending(f => f.Length)
                                 .ToArray();
                }
                else   //NAME
                {
                    dirArray = new DirectoryInfo(sPath)
                               .GetDirectories("*")
                               //.OrderByDescending(f => f.LastWriteTime)
                               .ToArray();
                    filesArray = new DirectoryInfo(sPath)
                                 .GetFiles("*")
                                 //.OrderByDescending(f => f.LastWriteTime)
                                 .ToArray();
                }

                //First add the ".." for the top
                if (sParent.Length > 0)
                {
                    TemporaryFileList aDirDots = new TemporaryFileList();
                    aDirDots.bIsFolder    = true;
                    aDirDots.nID          = aFileList.Count;
                    aDirDots.sRealname    = sParent;
                    aDirDots.sDisplayName = "(parent directory)";
                    aDirDots.sFileSize    = "..";
                    aFileList.Add(aDirDots);
                }

                //Check if the user wants cleaned dirs or not
                string sValue = GetTemporaryVariable(sSession, "Clean");
                if (sValue.Count() == 0)
                {
                    sValue = "False";
                }
                bool bCleanFilename = Convert.ToBoolean(sValue);

                //Always show directory first when we are not sorting by size
                if (sSorting != "SIZE")
                {
                    foreach (DirectoryInfo sDir in dirArray)
                    {
                        TemporaryFileList aDir = new TemporaryFileList();
                        aDir.bIsFolder = true;
                        aDir.nID       = aFileList.Count;
                        aDir.sRealname = sDir.FullName;
                        aDir.sFileSize = "";
                        if (bCleanFilename)
                        {
                            aDir.sDisplayName = CleanDirectoryAndFilename(sDir.Name);
                            if (!IgnoreFileOrDirectory(sDir.Name))
                            {
                                aFileList.Add(aDir);
                            }
                        }
                        else
                        {
                            aDir.sDisplayName = sDir.Name.Substring(sDir.Name.LastIndexOf('\\') + 1);
                            aFileList.Add(aDir);
                        }
                    }
                }

                foreach (FileInfo sFile in filesArray)
                {
                    TemporaryFileList aFile = new TemporaryFileList();
                    aFile.bIsFolder = false;
                    aFile.nID       = aFileList.Count;
                    aFile.sRealname = sFile.Name;
                    aFile.sFileSize = this.HumanFileSize(sFile.Length);
                    if (bCleanFilename)
                    {
                        aFile.sDisplayName = CleanDirectoryAndFilename(sFile.Name, false);
                        if (!IgnoreFileOrDirectory(sFile.Name))
                        {
                            aFileList.Add(aFile);
                        }
                    }
                    else
                    {
                        aFile.sDisplayName = sFile.Name.Substring(sFile.Name.LastIndexOf('\\') + 1);
                        aFileList.Add(aFile);
                    }
                }

                //Equal as above, but directories are after files
                if (sSorting == "SIZE")
                {
                    foreach (DirectoryInfo sDir in dirArray)
                    {
                        TemporaryFileList aDir = new TemporaryFileList();
                        aDir.bIsFolder = true;
                        aDir.nID       = aFileList.Count;
                        aDir.sRealname = sDir.FullName;
                        aDir.sFileSize = "";
                        if (bCleanFilename)
                        {
                            aDir.sDisplayName = CleanDirectoryAndFilename(sDir.Name);
                            if (!IgnoreFileOrDirectory(sDir.Name))
                            {
                                aFileList.Add(aDir);
                            }
                        }
                        else
                        {
                            aDir.sDisplayName = sDir.Name.Substring(sDir.Name.LastIndexOf('\\') + 1);
                            aFileList.Add(aDir);
                        }
                    }
                }
            }

            //Find the filelist
            for (int i = 0; i < aTemporarySessions.Count; i++)
            {
                TemporarySession aTempSession = ((TemporarySession)aTemporarySessions[i]);
                if (aTempSession.sID == sSession)
                {
                    aTempSession.aFileList = aFileList;
                    aTemporarySessions.RemoveAt(i);
                    aTemporarySessions.Insert(i, aTempSession);
                }
            }

            //Now create a temp array to return to user without sRealName (real directory name)
            ArrayList aTempFilelist = new ArrayList();

            for (int i = 0; i < aFileList.Count; i++)
            {
                TemporaryFileListClean filelistTemp = new TemporaryFileListClean();
                filelistTemp.bIsFolder    = ((TemporaryFileList)aFileList[i]).bIsFolder;
                filelistTemp.nID          = ((TemporaryFileList)aFileList[i]).nID;
                filelistTemp.sDisplayName = ((TemporaryFileList)aFileList[i]).sDisplayName;
                filelistTemp.sFileSize    = ((TemporaryFileList)aFileList[i]).sFileSize;
                aTempFilelist.Add(filelistTemp);
            }

            return(aTempFilelist);
        }