Beispiel #1
0
        /// <summary>
        /// 保存base64文件
        /// </summary>
        /// <param name="base64"></param>
        /// <param name="dir">目录信息</param>
        /// <returns></returns>
        protected TempFileInfo SaveBase64Image(string base64, IDir dir)
        {
            if (base64.IsNullOrEmpty())
            {
                return(new TempFileInfo());
            }
            Span <byte> span = new Span <byte>(new byte[base64.Length]);
            int         outLen;

            if (!Convert.TryFromBase64String(base64, span, out outLen))
            {
                return(new TempFileInfo());
            }
            using var memStream = new MemoryStream(span.ToArray());
            using var bitmap    = new Bitmap(memStream);
            var      fileName = $"{Guid.NewGuid()}.jpg";
            FileInfo fileInfo = new FileInfo(dir.GetUpFilePathWithSystem(fileName));

            using var fileStream = fileInfo.Create();
            bitmap.Save(fileStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            return(new TempFileInfo
            {
                ServerDirPath = dir.GetDownFileDir(),
                ServerFileName = fileName
            });
        }
Beispiel #2
0
        // pozwala edytować plik systemowy.
        // Działa z ikonoą oraz notataką
        /// <summary>
        /// overwrites desktop.ini and set new, folder and dir, note and Icon
        /// </summary>
        /// <param name="newNote"></param>
        /// <param name="dir"></param>
        /// <param name="iconAddress"></param>
        public void ChangeCreatedDirSystemValue(string newNote, IDir dir, string iconAddress)
        {
            if (String.IsNullOrWhiteSpace(newNote) && String.IsNullOrWhiteSpace(newNote))
            {
                throw new ArgumentException("one or more string is valid");
            }
            dir = dir ?? throw new ArgumentNullException("dir is null");

            FileWrite.ReplaceSystemFolderInfoFile(dir.Description.FullName, newNote, iconAddress);
            dir.Description.Note        = newNote;
            dir.Description.IconAddress = iconAddress;
        }
Beispiel #3
0
 public static Stream Createf(IDir self, String unixPath, ConDyn cd) {
     if (unixPath == null) throw new StorException("unixPath is null");
     if (unixPath.StartsWith("/")) {
         return Createf(GetRoot(self), unixPath.Substring(1), cd);
     }
     int p = unixPath.IndexOf('/');
     String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
     String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
     if (s1 == ".") {
         return Createf(self, s2, cd);
     }
     if (s1 == "..") {
         return Createf(self.ParentDir, s2, cd);
     }
     if (s2 == null) {
         MacfNam m2 = cd.ParseName(s1);
         try {
             self.CreatefHere(m2.Name);
         }
         catch (DSIException err) {
             if (err.ErrorCode == (int)AFPt2.DSIException.ResultCode.kFPObjectExists) {
             }
             else throw new StorException("Failed", err);
         }
         IEnt o2 = self.FindReal(m2.Name);
         if (false) { }
         else if (m2.Ty == Forkty.Data && o2 is ICanUP) return ((ICanUP)o2).OpenWrite(false);
         else if (m2.Ty == Forkty.Res && o2 is ICanUP) return ((ICanUP)o2).OpenWrite(true);
         else if (m2.Ty == Forkty.Finder && o2 is ICanUPFi) return ((ICanUPFi)o2).OpenWriteFinder();
         else throw new StorException("We can't write to \"" + o2.Name + "\".");
     }
     IEnt o = self.FindReal(s1);
     if (o is IDir) {
         return Createf((IDir)o, s2, cd);
     }
     else if (o != null) {
         throw new StorException("We knew \"" + o.Name + "\" is a file.");
     }
     throw new StorException("We can't be here for \"" + o.Name + "\".");
 }
Beispiel #4
0
        public static void CreateDir(IDir self, String unixPath) {
            if (unixPath == null) return; // Already exists
            if (unixPath.StartsWith("/")) {
                CreateDir(GetRoot(self), unixPath.Substring(1));
                return;
            }
            int p = unixPath.IndexOf('/');
            String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
            String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
            if (s1 == ".") {
                CreateDir(self, s2);
                return;
            }
            if (s1 == "..") {
                CreateDir(self.ParentDir, s2);
                return;
            }
            for (int t = 0; t < 2; t++) {
                IEnt o = self.FindReal(s1);
                if (o is IDir) {
                    CreateDir((IDir)o, s2);
                    return;
                }
                else if (o != null) {
                    throw new MkdException("We knew \"" + o.Name + "\" is a file.");
                }

                self.CreateDirHere(s1);

                if (s2 == null) return;
            }
            throw new MkdException("We can't create \"" + unixPath + "\".");
        }
Beispiel #5
0
 public static void RMDir(IDir self, String unixPath) {
     if (unixPath == null) {
         self.RMDirMe();
         return;
     }
     if (unixPath.StartsWith("/")) {
         RMDir(TravUt.GetRoot(self), unixPath.Substring(1));
         return;
     }
     int p = unixPath.IndexOf('/');
     String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
     String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
     if (s1 == ".") {
         RMDir(self, s2);
         return;
     }
     if (s1 == "..") {
         RMDir(self.ParentDir, s2);
         return;
     }
     IEnt o = self.FindReal(s1);
     if (o is IDir) {
         RMDir((IDir)o, s2);
         return;
     }
     else if (o != null) {
         throw new RmdException("We knew \"" + o.Name + "\" is a file.");
     }
     throw new RmdException("We can't remove \"" + unixPath + "\".");
 }
Beispiel #6
0
 public static IDir GetRoot(IDir parent) {
     if (parent != null) {
         while (parent.ParentDir != null) {
             parent = parent.ParentDir;
         }
     }
     return parent;
 }
Beispiel #7
0
 public static IEnt Find(IDir parent, String rel, bool onlyDir) {
     if (rel.Length == 0 || rel == ".") {
         return parent;
     }
     if (rel.StartsWith("/")) {
         return Find(GetRoot(parent), rel.Substring(1), onlyDir);
     }
     if (rel == "..") {
         return parent.ParentDir;
     }
     if (rel.StartsWith("./")) {
         return Find(parent, rel.Substring(2), onlyDir);
     }
     if (rel.StartsWith("../")) {
         return Find(parent.ParentDir, rel.Substring(3), onlyDir);
     }
     int p = rel.IndexOf('/');
     String part = (p < 0) ? rel : rel.Substring(0, p);
     foreach (IEnt o in parent.GetEnts()) {
         if (o.Name.Equals(part)) {
             if (o is IDir) {
                 if (p < 0)
                     return o;
                 return Find(o as IDir, rel.Substring(p + 1), onlyDir);
             }
             else if (onlyDir) {
                 throw new EntNotFoundException("We knew \"" + rel + "\" is a file.");
             }
             else {
                 if (p < 0)
                     return o;
                 throw new EntNotFoundException("We knew \"" + rel + "\" is a file.");
             }
         }
     }
     throw new EntNotFoundException("We don't find \"" + rel + "\".");
 }
Beispiel #8
0
 public static IDir Cwd(IDir parent, String rel) {
     return Find(parent, rel, true) as IDir;
 }
Beispiel #9
0
 public Dir(IDir dir)
 {
     Name    = dir.Name;
     Files   = dir.Files;
     SubDirs = dir.SubDirs;
 }
Beispiel #10
0
 public MacDir(FileParameters parm, MyDSI3 comm, ConDyn cd, IDir parentDir) {
     this.parm = parm;
     this.comm = comm;
     this.cd = cd;
     this.parentDir = parentDir;
 }
Beispiel #11
0
        public static IEnt FindReal(string name, MyDSI3 comm, ConDyn cd, IDir self) {
            MLoc m = MLoc.Ut.Get(self);
            TransmitRes res = comm.Transmit(new DSICommand().WithRequestPayload(new FPGetFileDirParms()
                .WithVolumeID(m.VolID)
                .WithDirectoryID(m.DirID)
                .WithFileBitmap(AfpFileBitmap.LongName | AfpFileBitmap.NodeID
                    | (cd.ExtRW ? (AfpFileBitmap.ExtDataForkLength | AfpFileBitmap.ExtResourceForkLength) : AfpFileBitmap.DataForkLength | AfpFileBitmap.ResourceForkLength))
                .WithDirectoryBitmap(AfpDirectoryBitmap.NodeID | AfpDirectoryBitmap.LongName)
                .WithPath(PUt.CombineRaw(m.RawPath, name))
            ));
            if (res.pack.IsResponse && res.pack.ErrorCode == 0) {

            }
            else if (res.pack.ErrorCode == (int)AFPt2.DSIException.ResultCode.kFPObjectNotFound) {
                return null;
            }
            else throw new DSIException(res.pack.ErrorCode, res.pack);

            GetFileDirParmsPack pack = new GetFileDirParmsPack(res.br);

            FileParameters ent = pack.Parms;

            if (ent.IsDirectory) {
                return new MacDir(ent, comm, cd, self);
            }
            else {
                return new MacEnt(ent, Forkty.Data, comm, cd, self);
            }
        }
Beispiel #12
0
        public static IEnumerable<IEnt> GetEnts310(MLoc m, MyDSI3 comm, ConDyn cd, IDir self) {
            for (uint x = 0; ; ) {
                TransmitRes res1 = comm.Transmit(new DSICommand().WithRequestPayload(new FPEnumerateExt2()
                    .WithPath(m.RawPath)
                    .WithStartIndex(Convert.ToUInt32(1U + x))
                    .WithVolumeID(m.VolID)
                    .WithDirectoryID(m.DirID)
                    .WithFileBitmap(AfpFileBitmap.ExtDataForkLength | AfpFileBitmap.ExtResourceForkLength | AfpFileBitmap.LongName | AfpFileBitmap.NodeID | AfpFileBitmap.ModificationDate)
                    .WithDirectoryBitmap(AfpDirectoryBitmap.NodeID | AfpDirectoryBitmap.LongName | AfpDirectoryBitmap.ModificationDate)
                    ));
                if (res1.pack.ErrorCode == -5018) break;
                if (res1.pack.IsResponse && res1.pack.ErrorCode == 0) {
                }
                else { throw new DSIException(res1.pack.ErrorCode, res1.pack); }

                EnumerateExtPack pack = new EnumerateExtPack(res1.br);

                foreach (FileParameters ent in pack.Ents) {
                    if (ent.IsDirectory) {
                        yield return new MacDir(ent, comm, cd, self);
                    }
                    else {
                        yield return new MacEnt(ent, Forkty.Data, comm, cd, self);
                        if (cd.EnumRes && ((Utfs.ResFork(ent) > 0) || !cd.IfAvail)) yield return new MacEnt(ent, Forkty.Res, comm, cd, self);
                        if (cd.EnumFi) yield return new MacEnt(ent, Forkty.Finder, comm, cd, self);
                    }
                }

                if (pack.ActualCount == 0) break;

                x += pack.ActualCount;
            }
        }
Beispiel #13
0
 public static IEnumerable<IEnt> GetEnts(MLoc m, MyDSI3 comm, ConDyn cd, IDir self) {
     if (cd.AFP31) return GetEnts310(m, comm, cd, self);
     if (cd.AFP30) return GetEnts300(m, comm, cd, self);
     return GetEnts220(m, comm, cd, self);
 }
Beispiel #14
0
 public MacEnt(FileParameters parm, Forkty ty, MyDSI3 comm, ConDyn cd, IDir parentDir) {
     this.parm = parm;
     this.ty = ty;
     this.comm = comm;
     this.cd = cd;
     this.parentDir = parentDir;
 }
Beispiel #15
0
 public static Object Dele(IDir self, String unixPath, ConDyn cd) {
     if (unixPath == null) throw new DeleException("unixPath is null");
     if (unixPath.StartsWith("/")) {
         return Dele(GetRoot(self), unixPath.Substring(1), cd);
     }
     int p = unixPath.IndexOf('/');
     String s1 = (p < 0) ? unixPath : unixPath.Substring(0, p);
     String s2 = (p < 0) ? null : unixPath.Substring(1 + p);
     if (s1 == ".") {
         return Dele(self, s2, cd);
     }
     if (s1 == "..") {
         return Dele(self.ParentDir, s2, cd);
     }
     if (s2 == null) {
         MacfNam m2 = cd.ParseName(s1);
         IEnt o2 = self.FindReal(m2.Name);
         if (false) { }
         else if (m2.Ty == Forkty.Data && o2 is ICanDele) ((ICanDele)o2).DeletefMe(false);
         else if (m2.Ty == Forkty.Res && o2 is ICanDele) ((ICanDele)o2).DeletefMe(true);
         else if (m2.Ty == Forkty.Finder && o2 is ICanDeleFi) ((ICanDeleFi)o2).DeletefMeFinder();
         else throw new DeleException("We can't delete \"" + o2.Name + "\".");
         return null;
     }
     IEnt o = self.FindReal(s1);
     if (o is IDir) {
         return Dele((IDir)o, s2, cd);
     }
     else if (o != null) {
         throw new DeleException("We knew \"" + o.Name + "\" is a file.");
     }
     throw new DeleException("We can't be here for \"" + s1 + "\".");
 }
Beispiel #16
0
 public MacVol(VolStruc vol, MyDSI3 comm, ConDyn cd, IDir parentDir) {
     this.vol = vol;
     this.comm = comm;
     this.cd = cd;
     this.parentDir = parentDir;
 }
Beispiel #17
0
 public static String GetAbs(IDir parent, String rel) {
     return GetAbs(MLoc.Ut.Get(parent).UnixPath, rel);
 }