Example #1
0
            //this is ~300 times slower than AFile.Move. SHFileOperation too. Use only for files or other shell items in virtual folders. Unfinished.
            public static void RenameFileOrDirectory(string path, string newName)
            {
                APerf.First();
                if (APath.IsInvalidFileName(newName))
                {
                    throw new ArgumentException("Invalid filename.", nameof(newName));
                }
                path = _PreparePath(path, nameof(path));

                APerf.Next();
                var si = _ShellItem(path, "*rename");

                APerf.Next();
                var fo = new Api.FileOperation() as Api.IFileOperation;

                APerf.Next();
                try {
                    fo.SetOperationFlags(4);             //FOF_SILENT. Without it shows a hidden dialog that becomes the active window.
                    AuException.ThrowIfFailed(fo.RenameItem(si, newName, null), "*rename");
                    APerf.Next();
                    AuException.ThrowIfFailed(fo.PerformOperations(), "*rename");
                    APerf.Next();
                }
                finally {
                    Api.ReleaseComObject(fo);
                    Api.ReleaseComObject(si);
                }
                APerf.NW();
            }
Example #2
0
            static Local()
            {
                //Prevent JIT delay when calling Next etc if not ngened.
                //if(!Util.Assembly_.IsAuNgened) { //unnecessary and makes slower
#if PREPAREMETHOD
                Util.AJit.Compile(typeof(Local), "Next", "NW");
#if DEBUG //else these methods are inlined
                Util.AJit.Compile(typeof(APerf), "Next", "NW");
#endif
#else //similar speed
                APerf.Next(); APerf.NW(); APerf.First();                 //JIT-compiles everything we need. s_enabled prevents calling AOutput.Write etc.
                s_enabled = true;
#endif

                //JIT speed: 1 ms.
            }