internal void ScanDirectory(string path, out List <IItemData> newFiles, out List <IItemData> directories)
        {
            directories = new List <IItemData>();
            newFiles    = new List <IItemData>();
            string file       = Path.Combine(path, "*");
            IntPtr fileHandle = NativeMethods.FindFirstFile(file, out findData);

            if (fileHandle != NativeMethods.FILE_INVALIDHANDLE) // Check for invalid file handle
            {
                do
                {
                    var fileInfo = new ColumnarItemData(Path.Combine(path, findData.cFileName).Split('\\', '/'), ColumnInfo.ColumnLookup);

                    long length64 = findData.nFileSizeHigh;
                    fileInfo.SetValue(FILESIZE, findData.nFileSizeLow + (length64 << 32));

                    long fileTime = ((long)(uint)findData.ftLastWriteTime.dwHighDateTime) << 32;
                    fileTime |= (long)(uint)findData.ftLastWriteTime.dwLowDateTime;
                    fileInfo.SetValue(FILETIME, DateTime.FromFileTimeUtc(fileTime));
                    fileInfo.SetValue(ATTRIBUTES, GetAttributesText(findData.dwFileAttributes));
                    if ((findData.dwFileAttributes & NativeMethods.FILE_ATTRIBUTE_DIRECTORY) == 0)
                    {
                        newFiles.Add(fileInfo);
                    }
                    else if (!findData.cFileName.Equals(".") &&
                             !findData.cFileName.Equals("..") &&
                             (findData.dwFileAttributes & NativeMethods.FILE_ATTRIBUTE_REPARSE_POINT) == 0)
                    {
                        directories.Add(fileInfo);
                    }
                } while (NativeMethods.FindNextFile(fileHandle, out findData));
                NativeMethods.FindClose(fileHandle);
            }
        }
Exemple #2
0
        public IItemData[] GetFiles()
        {
            var outputFiles = new List <IItemData>();

            Outlook.Table folderTable = folder.GetTable("", Outlook.OlTableContents.olUserItems);
            folderTable.Columns.RemoveAll();
            // For property names, see: https://stackoverflow.com/questions/50576645/outlook-mapi-message-class-metadata-in-outlook-2016
            // Open Outlook script editor in developer mode and Press F2 to browse classes and fields
            // https://docs.microsoft.com/en-us/office/vba/outlook/concepts/forms/outlook-fields-and-equivalent-properties
            folderTable.Columns.Add("MessageClass");
            folderTable.Columns.Add("Subject");
            folderTable.Columns.Add("Size");
            folderTable.Columns.Add("LastModificationTime");
            while (!folderTable.EndOfTable)
            {
                try
                {
                    Outlook.Row row = folderTable.GetNextRow();
                    if (row["subject"] == null)
                    {
                        continue;
                    }
                    var messageClass = row["MessageClass"].ToString();

                    var pathParts = new List <string>(this.FullName.Split(new char[] { '/', '\\' }));
                    pathParts.Add(row["Subject"].ToString());
                    var newItem = new ColumnarItemData(pathParts.ToArray(), Columns.ColumnLookup);
                    newItem.SetValue(ITEMSIZE, (int)row["Size"]);
                    var lastModificationTime = row["LastModificationTime"];
                    newItem.SetValue(ITEMDATE, lastModificationTime.ToString());
                    outputFiles.Add(newItem);
                }
                catch (System.Exception e)
                {
                    Debug.WriteLine("Mesage Error: " + e.Message);
                }
            }

            return(outputFiles.ToArray());
        }
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Process rows in parallel
        /// </summary>
        /// -----------------------------------------------------------------------------------
        private List <ColumnarItemData> ProcessRows(IEnumerable <string[]> rowProvider, CancellationToken cancelToken)
        {
            var results = new ConcurrentBag <ColumnarItemData[]>();
            var options = new ParallelOptions();

            options.CancellationToken = cancelToken;
            var minSize = _spreadSheetModel.ColumnNames.Length;

            Parallel.ForEach(rowProvider, options, batch =>
            {
                var work = new ColumnarItemData[batch.Length];
                for (int i = 0; i < work.Length; i++)
                {
                    var rawRow = batch[i];
                    if (rawRow == null)
                    {
                        break;
                    }
                    var splitRow = rawRow.Split('\t');
                    if (splitRow.Length < minSize)
                    {
                        continue;
                    }

                    var pathParts = _spreadSheetModel.GetPathParts(splitRow);

                    work[i] = new ColumnarItemData(pathParts, _columnInfo.ColumnLookup, splitRow);
                }
                results.Add(work);
                UnitsScannedSoFar += work.Length;
            });

            var output = new List <ColumnarItemData>();

            foreach (var batch in results)
            {
                output.AddRange(batch);
            }
            return(output);
        }
Exemple #4
0
        public IItemData[] GetFiles()
        {
            var outputFiles = new List <IItemData>();

            Outlook.Table folderTable = folder.GetTable("", Outlook.OlTableContents.olUserItems);
            folderTable.Columns.RemoveAll();
            folderTable.Columns.Add("MessageClass");
            folderTable.Columns.Add("Subject");
            folderTable.Columns.Add("Size");
            while (!folderTable.EndOfTable)
            {
                Outlook.Row row = folderTable.GetNextRow();
                if (row["subject"] == null)
                {
                    continue;
                }

                var newItem = new ColumnarItemData(new string[] { row["Subject"].ToString() }, Columns.ColumnLookup);
                newItem.SetValue(ITEMSIZE, (int)row["Size"]);
                outputFiles.Add(newItem);
            }

            return(outputFiles.ToArray());
        }
        // ******************************************************************************
        /// <summary>
        /// Scans a registry hive for subkeys and Values.
        /// </summary>
        /// <returns>Array of SliceDirectoryInfo objects</returns>
        // ******************************************************************************
        internal void ScanRegistry(string path, out List <IItemData> newValues, out List <IItemData> newKeys)
        {
            newKeys   = new List <IItemData>();
            newValues = new List <IItemData>();

            try
            {
                string   delimStr          = "\\";
                char[]   delimiter         = delimStr.ToCharArray();
                string[] rootPathPair      = path.Split(delimiter, 2);
                string[] registryValueList = null;

                RegistryKey currentKey = null;

                //Connect to one of the well known registry roots.
                switch (rootPathPair[0])
                {
                case "ClassesRoot":
                    currentKey = Registry.ClassesRoot;
                    break;

                case "CurrentUser":
                    currentKey = Registry.CurrentUser;
                    break;

                case "LocalMachine":
                    currentKey = Registry.LocalMachine;
                    break;

                case "Users":
                    currentKey = Registry.Users;
                    break;

                case "PerformanceData":
                    currentKey = Registry.PerformanceData;
                    break;

                case "CurrentConfig":
                    currentKey = Registry.CurrentConfig;
                    break;
                }

                //Using a string path for the registry Hive\Key is nice in that it mimics the same format of the
                //FileTreehanlder, but does cause a small problem for processing the information.  If we are at the
                //Root, all we need to do is open the key and the rooPathPair will contain exactly 1 string.
                //If there is a second string in the pair, then that is the Subkey we want to open.
                if (rootPathPair.Length > 1)
                {
                    currentKey = currentKey.OpenSubKey(rootPathPair[1]);
                }

                registryValueList = currentKey.GetValueNames();
                foreach (string currentRegistryValue in registryValueList)
                {
                    var fullName = string.Format("{0}\\{1}", path, currentRegistryValue.ToString());
                    var reginfo  = new ColumnarItemData(fullName.Split('\\'), Columns.ColumnLookup);
                    var itemType = currentKey.GetValueKind(currentRegistryValue).ToString();
                    reginfo.SetValue("ItemType", itemType);

                    //The calculation for the size of the registry value depends on the TYPE of the
                    //Value.
                    reginfo.SetValue(ITEMSIZE, 0);
                    switch (itemType)
                    {
                    case "Binary":
                        byte[] bytes = (byte[])currentKey.GetValue(currentRegistryValue);
                        reginfo.SetValue(ITEMSIZE, bytes.Length);
                        break;

                    case "DWord":
                        reginfo.SetValue(ITEMSIZE, sizeof(UInt32));
                        break;

                    case "QWord":
                        reginfo.SetValue(ITEMSIZE, sizeof(UInt64));
                        break;

                    //For the registry String object types we need to add 1 to the length of the string
                    //(accounting for the \n char) to get the true size in bytes of the string.
                    case "String":
                        string valueSz = (string)currentKey.GetValue(currentRegistryValue);
                        reginfo.SetValue(ITEMSIZE, (valueSz.Length + 1) * sizeof(char));
                        break;

                    case "ExpandString":
                        string value = (string)currentKey.GetValue(currentRegistryValue);
                        reginfo.SetValue(ITEMSIZE, (value.Length + 1) * sizeof(char));
                        break;

                    case "MultiString":
                        string[] multiString = (string[])currentKey.GetValue(currentRegistryValue);
                        foreach (string sz in multiString)
                        {
                            reginfo.SetValue(ITEMSIZE, (sz.Length + 1) * sizeof(char));
                        }
                        break;

                    //The type of Unknown & None represent 0 length binary values.
                    case "Unknown":
                    case "None":
                        break;

                    default:
                        Debugger.Break();
                        break;
                    }
                    newValues.Add(reginfo);
                }

                string[] RegSubKeys = currentKey.GetSubKeyNames();
                foreach (string regSubKey in RegSubKeys)
                {
                    var valueinfo = new ColumnarItemData(string.Format("{0}\\{1}", path, regSubKey).Split('\\', '/'), Columns.ColumnLookup);
                    newKeys.Add(valueinfo);
                }
                currentKey.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error: " + e.Message);
            }
        }
Exemple #6
0
        // ******************************************************************************
        /// <summary>
        /// Scans the current directory for files and other directories
        /// </summary>
        /// <returns>Array of SliceCosmosDirectoryInfo objects</returns>
        // ******************************************************************************
        long ScanDirectory(string path, out List <IItemData> newFiles, out List <IItemData> directories)
        {
            scanned = true;
            Debug.WriteLine("Scanning " + path);


            directories = new List <IItemData>();
            newFiles    = new List <IItemData>();
            long totalSize = 0;

            if (path == "Cosmos")
            {
                MessageBox.Show("To scan a Cosmos directory, drag and drop the URL for that folder from the address bar in Internet Explorer." +
                                "  (You must have already cached your Cosmos credentials on the local computer using scope.exe.)",
                                "Cosmos Scan");
                return(0);
            }

            bool retry = true;

            while (retry)
            {
                try
                {
                    RunspaceConfiguration rsc = RunspaceConfiguration.Create();
                    using (Runspace rs = RunspaceFactory.CreateRunspace(rsc))
                    {
                        rs.Open();
                        using (RunspaceInvoke scriptInvoker = new RunspaceInvoke())
                        {
                            //Debug.Write(scriptInvoker.Invoke("[IntPtr]::Size")[0].ToString());
                            scriptInvoker.Invoke("Import-Module cosmos");
                            Collection <PSObject> cosmosMetadatas = scriptInvoker.Invoke(String.Format("Get-CosmosStream {0}", path));
                            foreach (PSObject cosmosMetadata in cosmosMetadatas)
                            {
                                Debug.Write(".");

                                long cosmosFileSize;
                                long.TryParse(cosmosMetadata.Properties["Length"].Value.ToString(), out cosmosFileSize);
                                cosmosFileSize = Math.Max(0, cosmosFileSize);
                                totalSize     += cosmosFileSize;

                                string fullName = cosmosMetadata.Properties["StreamName"].Value.ToString();//.TrimEnd('/');
                                var    fileInfo = new ColumnarItemData(fullName.Split('\\', '/'), Columns.ColumnLookup);
                                fileInfo.SetValue(STREAMSIZE, cosmosFileSize);

                                bool isDirectory;
                                bool.TryParse(cosmosMetadata.Properties["IsDirectory"].Value.ToString(), out isDirectory);

                                if (isDirectory)
                                {
                                    directories.Add(fileInfo);
                                }
                                else
                                {
                                    newFiles.Add(fileInfo);
                                }
                            }
                            Debug.WriteLine("");
                            retry = false;
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                    MessageBoxResult result = MessageBox.Show("Cosmos Error!  Retry?\r\n\r\n Error: " + e.ToString(),
                                                              "Cosmos Error", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.No)
                    {
                        retry = false;
                    }
                }
            }

            return(totalSize);
        }