SharpCifs.Smb.SmbFile.GetUncPath0 C# (CSharp) Method

GetUncPath0() private method

private GetUncPath0 ( ) : string
return string
        internal virtual string GetUncPath0()
        {
            if (Unc == null)
            {
                char[] instr = Url.LocalPath.ToCharArray();
                char[] outstr = new char[instr.Length];
                int length = instr.Length;
                int i;
                int o;
                int state;

                state = 0;
                o = 0;
                for (i = 0; i < length; i++)
                {
                    switch (state)
                    {
                        case 0:
                            {
                                if (instr[i] != '/')
                                {
                                    return null;
                                }
                                outstr[o++] = instr[i];
                                state = 1;
                                break;
                            }

                        case 1:
                            {
                                if (instr[i] == '/')
                                {
                                    break;
                                }
                                if (instr[i] == '.' && ((i + 1) >= length || instr[i + 1] == '/'))
                                {
                                    i++;
                                    break;
                                }
                                if ((i + 1) < length && instr[i] == '.' && instr[i + 1] == '.' && ((i + 2) >= length
                                                                                               || instr[i + 2] == '/'))
                                {
                                    i += 2;
                                    if (o == 1)
                                    {
                                        break;
                                    }
                                    do
                                    {
                                        o--;
                                    }
                                    while (o > 1 && outstr[o - 1] != '/');
                                    break;
                                }
                                state = 2;
                                goto case 2;
                            }

                        case 2:
                            {
                                if (instr[i] == '/')
                                {
                                    state = 1;
                                }
                                outstr[o++] = instr[i];
                                break;
                            }
                    }
                }
                _canon = new string(outstr, 0, o);
                if (o > 1)
                {
                    o--;
                    i = _canon.IndexOf('/', 1);
                    if (i < 0)
                    {
                        _share = Runtime.Substring(_canon, 1);
                        Unc = "\\";
                    }
                    else
                    {
                        if (i == o)
                        {
                            _share = Runtime.Substring(_canon, 1, i);
                            Unc = "\\";
                        }
                        else
                        {
                            _share = Runtime.Substring(_canon, 1, i);
                            Unc = Runtime.Substring(_canon, i, outstr[o] == '/' ? o : o + 1);
                            Unc = Unc.Replace('/', '\\');
                        }
                    }
                }
                else
                {
                    _share = null;
                    Unc = "\\";
                }
            }
            return Unc;
        }

Usage Example

Example #1
0
 /// <exception cref="SharpCifs.Smb.SmbException"></exception>
 internal virtual void CopyTo0(SmbFile dest, byte[][] b, int bsize, WriterThread
      w, SmbComReadAndX req, SmbComReadAndXResponse resp)
 {
     int i;
     if (_attrExpiration < Runtime.CurrentTimeMillis())
     {
         _attributes = AttrReadonly | AttrDirectory;
         _createTime = 0L;
         _lastModified = 0L;
         _isExists = false;
         IInfo info = QueryPath(GetUncPath0(), Trans2QueryPathInformationResponse.SMB_QUERY_FILE_BASIC_INFO
             );
         _attributes = info.GetAttributes();
         _createTime = info.GetCreateTime();
         _lastModified = info.GetLastWriteTime();
         _isExists = true;
         _attrExpiration = Runtime.CurrentTimeMillis() + AttrExpirationPeriod;
     }
     if (IsDirectory())
     {
         SmbFile[] files;
         SmbFile ndest;
         string path = dest.GetUncPath0();
         if (path.Length > 1)
         {
             try
             {
                 dest.Mkdir();
                 dest.SetPathInformation(_attributes, _createTime, _lastModified);
             }
             catch (SmbException se)
             {
                 if (se.GetNtStatus() != NtStatus.NtStatusAccessDenied && se.GetNtStatus() != NtStatus
                     .NtStatusObjectNameCollision)
                 {
                     throw;
                 }
             }
         }
         files = ListFiles("*", AttrDirectory | AttrHidden | AttrSystem, null, null);
         try
         {
             for (i = 0; i < files.Length; i++)
             {
                 ndest = new SmbFile(dest, files[i].GetName(), files[i].Type, files[i]._attributes,
                     files[i]._createTime, files[i]._lastModified, files[i]._size);
                 files[i].CopyTo0(ndest, b, bsize, w, req, resp);
             }
         }
         catch (UnknownHostException uhe)
         {
             throw new SmbException(Url.ToString(), uhe);
         }
         catch (UriFormatException mue)
         {
             throw new SmbException(Url.ToString(), mue);
         }
     }
     else
     {
         long off;
         try
         {
             Open(ORdonly, 0, AttrNormal, 0);
             try
             {
                 dest.Open(OCreat | OWronly | OTrunc, SmbConstants.FileWriteData |
                      SmbConstants.FileWriteAttributes, _attributes, 0);
             }
             catch (SmbAuthException sae)
             {
                 if ((dest._attributes & AttrReadonly) != 0)
                 {
                     dest.SetPathInformation(dest._attributes & ~AttrReadonly, 0L, 0L);
                     dest.Open(OCreat | OWronly | OTrunc, SmbConstants.FileWriteData |
                          SmbConstants.FileWriteAttributes, _attributes, 0);
                 }
                 else
                 {
                     throw;
                 }
             }
             i = 0;
             off = 0L;
             for (; ; )
             {
                 req.SetParam(Fid, off, bsize);
                 resp.SetParam(b[i], 0);
                 Send(req, resp);
                 lock (w)
                 {
                     if (w.E != null)
                     {
                         throw w.E;
                     }
                     while (!w.Ready)
                     {
                         try
                         {
                             Runtime.Wait(w);
                         }
                         catch (Exception ie)
                         {
                             throw new SmbException(dest.Url.ToString(), ie);
                         }
                     }
                     if (w.E != null)
                     {
                         throw w.E;
                     }
                     if (resp.DataLength <= 0)
                     {
                         break;
                     }
                     w.Write(b[i], resp.DataLength, dest, off);
                 }
                 i = i == 1 ? 0 : 1;
                 off += resp.DataLength;
             }
             dest.Send(new Trans2SetFileInformation(dest.Fid, _attributes, _createTime, _lastModified
                 ), new Trans2SetFileInformationResponse());
             dest.Close(0L);
         }
         catch (SmbException se)
         {
             if (IgnoreCopyToException == false)
             {
                 throw new SmbException("Failed to copy file from [" + ToString() + "] to ["
                     + dest + "]", se);
             }
             if (Log.Level > 1)
             {
                 Runtime.PrintStackTrace(se, Log);
             }
         }
         finally
         {
             Close();
         }
     }
 }
All Usage Examples Of SharpCifs.Smb.SmbFile::GetUncPath0