예제 #1
0
        public int Convert(string options, string from, string to)
        {
            message = "";
            int  exitCode = 0;
            bool zip      = to.EndsWith(".zip");

            if (zip)
            {
                to = to.Substring(0, to.Length - 4);
            }
            callString = ImPath + ConvertCommand + " " + options + " " + Os.escapeParam(from) + " " + Os.escapeParam(to);
            call       = new RaiSystem(callString);
            call.Exec(out message);
            exitCode = call.ExitCode;
            if (exitCode != 0 && message.Contains("Permission denied"))
            {
                try
                {
                    FileInfo          fiIntern        = new FileInfo(Os.winInternal(from));
                    FileSecurity      fsec            = fiIntern.GetAccessControl();
                    IdentityReference currentIdentity = new NTAccount(System.Security.Principal.WindowsIdentity.GetCurrent().Name);
                    fsec.SetOwner(currentIdentity);
                    FileSystemAccessRule permissions = new FileSystemAccessRule(currentIdentity, FileSystemRights.ReadAndExecute, AccessControlType.Allow);
                    fsec.AddAccessRule(permissions);
                    fiIntern.SetAccessControl(fsec);
                    // try it again
                    call.Exec(out message);
                    exitCode = call.ExitCode;
                }
                catch (Exception)
                {
                }
            }
            if (zip)
            {
                var inFolder = new RaiFile(to);
                inFolder.Path = inFolder.Path + inFolder.Name;
                inFolder.mkdir();
                inFolder.mv(new RaiFile(to));
                File.Delete(inFolder.FullName + ".zip");
                try
                {
                    ZipFile.CreateFromDirectory(inFolder.Path, to + ".zip");
                }
                catch (Exception)
                {
                }
            }
            return(exitCode);
        }
예제 #2
0
        public void TestRaiFile1()
        {
            var temp     = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/325/325859/325859_11.tiff");
            var original = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/325/325859/325859_03.tiff");

            Assert.True(File.Exists(original.FullName));
            temp.rm();
            Assert.False(File.Exists(temp.FullName));
            temp.cp(original);
            Assert.True(File.Exists(temp.FullName));
            var dest = new RaiFile($"{TestDir}/Data/pic3/d/iserv/testpic/325/325859/325859_01.tiff");

            dest.rm();
            dest.mv(temp);
            Assert.True(File.Exists(dest.FullName));
            Assert.False(File.Exists(temp.FullName));
        }