示例#1
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireContextHandlerRegistered();
            RequireExtHasHandler();

            const string cval         = "exp-imp";
            string       propertyName = "System.Comment";

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1);

            // Use API Code Pack to set the value
            IShellProperty prop = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName);

            (prop as ShellProperty <string>).Value = cval;

            // Set up ContextHandler and tell it about the target file
            var handler = new CContextMenuHandler();
            var dobj    = new DataObject();

            dobj.SetFileDropList(new StringCollection {
                fileName
            });
            handler.Initialize(new IntPtr(0), dobj, 0);
            handler.QueryContextMenu(0, 0, 0, 0, 0); // This fails, but  that's ok

            //export the metadata
            CMINVOKECOMMANDINFOEX cmd = new CMINVOKECOMMANDINFOEX();

            cmd.lpVerb = new IntPtr((int)ContextMenuVerbs.Export);
            var cw = new CommandWrapper(cmd);

            handler.InvokeCommand(cw.Ptr);

            // Create a 2nd temp file for import
            string fileName2 = CreateFreshFile(2);

            Marshal.ReleaseComObject(handler);  // preempt GC for CCW

            // rename metadata file
            RenameWithDelete(MetadataFileName(fileName), MetadataFileName(fileName2));

            // Get a new handler and import
            handler = new CContextMenuHandler();
            dobj    = new DataObject();
            dobj.SetFileDropList(new StringCollection {
                fileName2
            });
            handler.Initialize(new IntPtr(0), dobj, 0);
            handler.QueryContextMenu(0, 0, 0, 0, 0); // This fails, but  that's ok

            cmd        = new CMINVOKECOMMANDINFOEX();
            cmd.lpVerb = new IntPtr((int)ContextMenuVerbs.Import);
            cw         = new CommandWrapper(cmd);
            handler.InvokeCommand(cw.Ptr);

            Marshal.ReleaseComObject(handler);  // preempt GC for CCW

            // Use API Code Pack to read the value
            prop = ShellObject.FromParsingName(fileName2).Properties.GetProperty(propertyName);
            object oval = prop.ValueAsObject;

            // Clean up files - checks if they have been released, too
            File.Delete(fileName);
            File.Delete(fileName2);
            File.Delete(MetadataFileName(fileName2));

            // good if original value has made it round
            return(cval == (string)oval);
        }
示例#2
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireContextHandlerRegistered();
            RequireExtHasHandler();

            string cval1 = "할말있어";

            string[] cval2         = { "hello", "Приветствия" };
            string   cval3         = "title";
            string   propertyName1 = "System.Comment";
            string   propertyName2 = "System.Category";
            string   propertyName3 = "System.Title";

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1);

            // Use API Code Pack to set the values
            IShellProperty prop1 = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName1);

            (prop1 as ShellProperty <string>).Value = cval1;
            IShellProperty prop2 = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName2);

            (prop2 as ShellProperty <string[]>).Value = cval2;
            IShellProperty prop3 = ShellObject.FromParsingName(fileName).Properties.GetProperty(propertyName3);

            (prop3 as ShellProperty <string>).Value = cval3;

            // Set up ContextHandler and tell it about the target file
            var handler = new CContextMenuHandler();
            var dobj    = new DataObject();

            dobj.SetFileDropList(new StringCollection {
                fileName
            });
            handler.Initialize(new IntPtr(0), dobj, 0);
            handler.QueryContextMenu(0, 0, 0, 0, 0); // This fails, but  that's ok

            //export the metadata
            CMINVOKECOMMANDINFOEX cmd = new CMINVOKECOMMANDINFOEX();

            cmd.lpVerb = new IntPtr((int)ContextMenuVerbs.Export);
            var cw = new CommandWrapper(cmd);

            handler.InvokeCommand(cw.Ptr);

            // Create a 2nd temp file for import
            string fileName2 = CreateFreshFile(2);

            Marshal.ReleaseComObject(handler);  // preempt GC for CCW

            // rename metadata file
            RenameWithDelete(MetadataFileName(fileName), MetadataFileName(fileName2));

            // Get a new handler and import
            handler = new CContextMenuHandler();
            dobj    = new DataObject();
            dobj.SetFileDropList(new StringCollection {
                fileName2
            });
            handler.Initialize(new IntPtr(0), dobj, 0);
            handler.QueryContextMenu(0, 0, 0, 0, 0); // This fails, but  that's ok

            cmd        = new CMINVOKECOMMANDINFOEX();
            cmd.lpVerb = new IntPtr((int)ContextMenuVerbs.Import);
            cw         = new CommandWrapper(cmd);
            handler.InvokeCommand(cw.Ptr);

            Marshal.ReleaseComObject(handler);  // preempt GC for CCW

            // Use API Code Pack to read the values
            prop1 = ShellObject.FromParsingName(fileName2).Properties.GetProperty(propertyName1);
            string result1 = (string)prop1.ValueAsObject;

            prop2 = ShellObject.FromParsingName(fileName2).Properties.GetProperty(propertyName2);
            string[] result2 = (string[])prop2.ValueAsObject;
            prop3 = ShellObject.FromParsingName(fileName2).Properties.GetProperty(propertyName3);
            string result3 = (string)prop3.ValueAsObject;

            // Clean up files - checks if they have been released, too
            File.Delete(fileName);
            File.Delete(fileName2);
            File.Delete(MetadataFileName(fileName2));

            // good if original value has made it round
            return(cval1 == result1 && result2.Length == 2 && cval2[0] == result2[0] && cval2[1] == result2[1] && cval3 == result3);
        }
示例#3
0
        public override bool RunBody(State state)
        {
            RequirePropertyHandlerRegistered();
            RequireContextHandlerRegistered();
            RequireExtHasHandler(extension);

            state.RecordEntry(String.Format("Starting mass property setting on '{0}'...", extension));

            //Create a temp file to put metadata on
            string fileName = CreateFreshFile(1, extension);

            savedProps = new List <SavedProp>();

            // Give all writable properties random values, according to their type
            foreach (var propDesc in state.PropertyDescriptions.Where(p => !p.TypeFlags.HasFlag(TestDriverCodePack.PropertyTypeOptions.IsInnate)))
            {
                // These properties don't seem to be writeable.  Don't know why, but they don't appear anyway in the list
                // of usable properties at http://msdn.microsoft.com/en-us/library/windows/desktop/dd561977(v=vs.85).aspx
                if (propDesc.CanonicalName == "System.History.UrlHash" ||
                    propDesc.CanonicalName == "System.DuiControlResource" ||
                    propDesc.CanonicalName == "System.OfflineFiles.CreatedOffline" ||
                    propDesc.CanonicalName == "System.PropList.XPDetailsPanel" ||
                    propDesc.CanonicalName == "System.SDID" ||
                    propDesc.CanonicalName == "Windows.Registry.Type")
                {
                    continue;
                }

                // Use API Code Pack to set the value, except for strings, because the Code Pack blows when setting strings of length 1 !!
                // Still use Code Pack elsewhere for its nullable type handling
                IShellProperty prop = ShellObject.FromParsingName(fileName).Properties.GetProperty(propDesc.CanonicalName);
                SetPropertyValue(fileName, propDesc, prop);
            }
            state.RecordEntry(String.Format("{0} property values set on {1}", savedProps.Count, fileName));

            // Go around again, using the Handler directly to read all the values written and then check them
            int errors = GetAndCheckValues(fileName, state);

            state.RecordEntry(String.Format("{0} properties read back, {1} mismatches", savedProps.Count, errors));

            if (errors > 0)
            {
                return(false);
            }

            // Use ContextHandler to export all the values
            var contextHandler = new CContextMenuHandler();
            var dobj           = new DataObject();

            dobj.SetFileDropList(new StringCollection {
                fileName
            });
            contextHandler.Initialize(new IntPtr(0), dobj, 0);
            contextHandler.QueryContextMenu(0, 0, 0, 0, 0); // This fails, but  that's ok

            //export the metadata
            CMINVOKECOMMANDINFOEX cmd = new CMINVOKECOMMANDINFOEX();

            cmd.lpVerb = new IntPtr((int)ContextMenuVerbs.Export);
            var cw = new CommandWrapper(cmd);

            contextHandler.InvokeCommand(cw.Ptr);

            Marshal.ReleaseComObject(contextHandler);  // preempt GC for CCW

            // Create new file and import values to it
            string fileName2 = CreateFreshFile(2, extension);

            // rename metadata file
            RenameWithDelete(MetadataFileName(fileName), MetadataFileName(fileName2));
            state.RecordEntry("Metadata exported, starting to import onto new file and check...");

            // Get a new handler and import
            contextHandler = new CContextMenuHandler();
            dobj           = new DataObject();
            dobj.SetFileDropList(new StringCollection {
                fileName2
            });
            contextHandler.Initialize(new IntPtr(0), dobj, 0);
            contextHandler.QueryContextMenu(0, 0, 0, 0, 0); // This fails, but  that's ok

            cmd        = new CMINVOKECOMMANDINFOEX();
            cmd.lpVerb = new IntPtr((int)ContextMenuVerbs.Import);
            cw         = new CommandWrapper(cmd);
            contextHandler.InvokeCommand(cw.Ptr);

            Marshal.ReleaseComObject(contextHandler);  // preempt GC for CCW

            // Go around one last time, reading and checking the imported values
            // We don't use the Code Pack because of it's boolean value bug
            errors = GetAndCheckValues(fileName2, state, false);

            state.RecordEntry(String.Format("{0} properties read back, {1} mismatches", savedProps.Count, errors));

            // Clean up files - checks if they have been released, too
            // Leave files around for analysis if there have been problems
            if (errors == 0)
            {
                File.Delete(fileName);
                File.Delete(fileName2);
                File.Delete(MetadataFileName(fileName2));
            }

            return(errors == 0);
        }