Exemplo n.º 1
0
        private FileSystemMetadata ToMetadata(SmbFile info, bool?isDirectory = null)
        {
            var result = new FileSystemMetadata();

            result.Exists    = info.Exists();
            result.FullName  = GetReturnPath(info);
            result.Extension = Path.GetExtension(result.FullName);
            result.Name      = info.GetName();

            if (result.Exists)
            {
                result.IsDirectory = info.IsDirectory();
                result.IsHidden    = info.IsHidden();

                result.IsReadOnly = !info.CanWrite();

                if (info.IsFile())
                {
                    result.Length        = info.Length();
                    result.DirectoryName = info.GetParent();
                }

                result.CreationTimeUtc  = baseDate.AddMilliseconds(info.CreateTime());
                result.LastWriteTimeUtc = baseDate.AddMilliseconds(info.GetLastModified());
            }
            else
            {
                if (isDirectory.HasValue)
                {
                    result.IsDirectory = isDirectory.Value;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
 /// <exception cref="System.IO.IOException"></exception>
 internal virtual void EnsureOpen()
 {
     // ensure file is open
     if (_file.IsOpen() == false)
     {
         _file.Open(_openFlags, _access | SmbConstants.FileWriteData, SmbFile.AttrNormal,
                    0);
         if (_append)
         {
             _fp = _file.Length();
         }
     }
 }
Exemplo n.º 3
0
 public override DnHead Head()
 {
     try
     {
         var file = new SmbFile(FromUri.ToString());
         var len  = (int)file.Length();
         return(new DnHead()
         {
             Size = len
         });
     }
     catch (Exception e)
     {
         Reset();
         throw;
     }
 }
Exemplo n.º 4
0
 /// <exception cref="SharpCifs.Smb.SmbException"></exception>
 /// <exception cref="System.UriFormatException"></exception>
 /// <exception cref="UnknownHostException"></exception>
 internal SmbFileOutputStream(SmbFile file, bool append, int openFlags)
 {
     this._file      = file;
     this._append    = append;
     this._openFlags = openFlags;
     _access         = ((int)(((uint)openFlags) >> 16)) & 0xFFFF;
     if (append)
     {
         try
         {
             _fp = file.Length();
         }
         catch (SmbAuthException sae)
         {
             throw;
         }
         catch (SmbException)
         {
             _fp = 0L;
         }
     }
     if (file is SmbNamedPipe && file.Unc.StartsWith("\\pipe\\"))
     {
         file.Unc = Runtime.Substring(file.Unc, 5);
         file.Send(new TransWaitNamedPipe("\\pipe" + file.Unc),
                   new TransWaitNamedPipeResponse());
     }
     file.Open(openFlags,
               _access | SmbConstants.FileWriteData,
               SmbFile.AttrNormal,
               0);
     this._openFlags &= ~(SmbFile.OCreat | SmbFile.OTrunc);
     _writeSize       = file.Tree.Session.transport.SndBufSize - 70;
     _useNtSmbs       = file.Tree.Session.transport.HasCapability(SmbConstants.CapNtSmbs);
     if (_useNtSmbs)
     {
         _reqx = new SmbComWriteAndX();
         _rspx = new SmbComWriteAndXResponse();
     }
     else
     {
         _req = new SmbComWrite();
         _rsp = new SmbComWriteResponse();
     }
 }
Exemplo n.º 5
0
 /// <exception cref="WinrtCifs.Smb.SmbException"></exception>
 public virtual long Length()
 {
     return(_file.Length());
 }
Exemplo n.º 6
0
        public override long Seek(long offset, System.IO.SeekOrigin origin)
        {
            if (mStream == null)
            {
                throw new ObjectDisposedException("SambaInputStream");
            }
            try
            {
                                #if DEBUG_SAMBA
                Android.Util.Log.Debug("SambaInputStream", "Seeking with offset " + offset + " and origin " + origin);
                                #endif
                long newPos = mPos;
                switch (origin)
                {
                case System.IO.SeekOrigin.Begin:
                    if (offset < 0)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    newPos = offset;
                    break;

                case SeekOrigin.Current:
                    if (offset < -mPos)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    newPos = mPos + offset;
                    break;

                case SeekOrigin.End:
                {
                    long len = mFile.Length();
                    if (offset > 0)
                    {
                        throw new ArgumentOutOfRangeException("offset");
                    }
                    newPos = len + offset;
                }
                break;

                default:
                    break;
                }
                if (newPos > mPos)
                {
                    mStream.Skip(newPos - mPos);
                }
                else if (newPos < mPos)
                {
                    // SmbInputStream can't seek backwards; have to recreate
                    mStream.Close();
                    mStream = new SmbFileInputStream(mFile);
                    mStream.Skip(newPos);
                }
                mPos = newPos;
                                #if DEBUG_SAMBA
                Android.Util.Log.Debug("SambaInputStream", "New position is " + mPos);
                                #endif
                return(mPos);
            }
            catch (SmbException ex)
            {
                throw new System.IO.IOException(ex.Message, ex);
            }
            catch (Java.IO.IOException ex)
            {
                throw new System.IO.IOException(ex.Message, ex);
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult <string> > GetAudioPath(Guid sessionGuid)
        {
            var folder = new SmbFile("smb://Alon Amrani:alon1023@DESKTOP-AQLIK4S/Users/Efrat/Desktop/Hackathon/AlonShare");

            return(folder.Length().ToString());
        }
Exemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 /// <remarks>
 /// Add by dobes
 /// mod interface to WrappedSystemStream readable, for random access.
 /// </remarks>
 internal override bool CanSeek()
 {
     return(File.Length() >= 0);
 }