Example #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            fileCheck fc  = new fileCheck();
            String    pas = fileCheck.AESEncrypt256(Convert.ToString(fc.getHddNum()));

            // String pas = "******";
            // MessageBox.Show(fileCheck.AESDecrypt256(pas));

            switch (fc.License(this))
            {
            case fileCheck.checkState.Formally:
                demo = true;
                break;

            case fileCheck.checkState.ban:
                fc.showMsg(pas);
                Environment.Exit(Environment.ExitCode);
                break;

            case fileCheck.checkState.Demo:
                fc.showMsg(pas);
                break;
            }

            CheckForIllegalCrossThreadCalls = false;
        }
        private void Request()
        {
            int request_count = 0;

            byte[] sendBuffer = new byte[1024 * 8];
            Thread.Sleep(4000);
            string name = null;

            while (true)
            {
                while (true)
                {
                    request_count++;
                    if (request_count == 32)
                    {
                        request_count = 0;
                    }
                    if (connect_peopel[request_count])
                    {
                        for (int i = 0; i < 32; i++)
                        {
                            if (client_text_list.Items[i].SubItems[0].Text == request_count.ToString())
                            {
                                name = client_text_list.Items[i].SubItems[1].Text;
                                break;
                            }
                        }
                        server_text_box.AppendText(name + "님의 필기 업데이트 \n");
                        break;
                    }
                    Thread.Sleep(100);
                }
                if (mutex[request_count])
                {
                    fileCheck fCheck = new fileCheck();
                    fCheck.Type       = (int)FileDataType.일체크;
                    fCheck.fileNeed   = 0;
                    fCheck.fileNumber = request_count;//여기서는 유저 인덱스 박자

                    sendBuffer = FileData.Serialize(fCheck);
                    m_NetStream[request_count].Write(sendBuffer, 0, sendBuffer.Length);
                    m_NetStream[request_count].Flush();

                    mutex[request_count] = true;
                }
            }
        }
Example #3
0
 private void button2_Click(object sender, EventArgs e)//필기 요청
 {
     if (listView1.FocusedItem == null)
     {
         MessageBox.Show("아무것도 선택하지 않았습니다.");
     }
     else
     {
         myText = new myTextBox();
         myText.Show();
         fileCheck fCheck = new fileCheck();
         fCheck.Type       = (int)FileDataType.일체크;
         fCheck.fileNeed   = 0;
         fCheck.fileNumber = Convert.ToInt32(listView1.FocusedItem.SubItems[0].Text);
         sendBuffer        = FileData.Serialize(fCheck);
         m_NetStream.Write(sendBuffer, 0, sendBuffer.Length);
         m_NetStream.Flush();
     }
 }
Example #4
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            if (metroTextBox1.Text == "")
            {
                MessageBox.Show("경로가 선택되지 않았습니다.");
            }
            else
            {
                if (metroListView1.FocusedItem == null)
                {
                    MessageBox.Show("아무것도 선택하지 않았습니다.");
                }
                else
                {
                    fileCheck fCheck = new fileCheck();
                    fCheck.fileNeed = 1;
                    fCheck.filename = metroListView1.FocusedItem.SubItems[0].Text;
                    fCheck.Type     = (int)FileDataType.일체크;

                    sendBuffer = FileData.Serialize(fCheck);
                    this.Send();
                }
            }
        }
Example #5
0
        /// <summary>
        /// This method retrieves the dates and times of the
        /// file getting replicated by the server
        /// </summary>
        /// <param name="directoryName">
        /// Path of the directory where the file
        /// resides in the server.
        /// </param>
        /// <param name="fileName">
        /// Name of the file being replicated at present.
        /// The name should be without file extension.
        /// </param>
        /// <param name="computername">
        /// The IP address of the server.
        /// </param>
        /// <param name="domainname">
        /// Domain name in which client and server resides.
        /// </param>
        /// <param name="username">
        /// username to log onto the server.
        /// </param>
        /// <param name="password">
        /// password to log onto to the server.
        /// </param>
        /// <param name="dtType">
        /// This enum specifies which type of date-time
        /// property is to be retrieved.
        /// </param>
        /// <returns>
        /// It returns DateTime structure with only
        /// year-month-day-hour-minute-second filled.
        /// </returns>
        public DateTime GetDateTime(string directoryName,
                                    string fileName,
                                    string computername,
                                    string domainname,
                                    string username,
                                    string password,
                                    fileDateTimeType dtType,
                                    ref fileCheck fileChk)
        {
            string sql = "ASSOCIATORS OF " +
                         "{Win32_Directory='" + directoryName + "'} " +
                         "WHERE " +
                         "AssocClass=CIM_DirectoryContainsFile " +
                         "ResultClass=CIM_DataFile " +
                         "ResultRole=PartComponent " +
                         "Role=GroupComponent";

            string            path  = "\\root\\cimv2";
            ConnectionOptions oConn = new ConnectionOptions();

            oConn.Username = domainname + @"\" + username;
            oConn.Password = password;

            //ManagementScope scope = new System.Management.ManagementScope("root\\cimv2");
            ManagementScope scope = new System.Management.ManagementScope("\\\\" + computername + path, oConn);

            System.Management.RelatedObjectQuery oQuery    = new System.Management.RelatedObjectQuery(sql);
            ManagementObjectSearcher             oSearcher = new ManagementObjectSearcher(scope, oQuery);
            ManagementObjectCollection           oFiles    = oSearcher.Get();

            DateTime dt    = new DateTime();
            int      count = 0;

            foreach (ManagementObject oFile in oFiles)
            {
                string fileInDirectory = Convert.ToString(oFile["FileName"]);
                if (fileInDirectory.ToUpper() == fileName.ToUpper())
                {
                    count++;
                    switch (dtType)
                    {
                    case fileDateTimeType.CreationDate:
                        string creationTime = Convert.ToString(oFile["CreationDate"]);
                        dt = FillDateTimeStructure(creationTime);
                        break;

                    case fileDateTimeType.LastAccessed:
                        string lastAccessedTime = Convert.ToString(oFile["LastAccessed"]);
                        dt = FillDateTimeStructure(lastAccessedTime);
                        break;

                    case fileDateTimeType.LastModified:
                        string lastModifiedTime = Convert.ToString(oFile["LastModified"]);
                        dt = FillDateTimeStructure(lastModifiedTime);
                        break;
                    }
                }
            }

            if (count == 0)
            {
                fileChk = fileCheck.FileNotPresent;
            }

            return(dt);
        }
Example #6
0
        private void Receive()//받자 파일을
        {
            while (this.m_blsConnect)
            {
                try
                {
                    this.m_NetStream.Read(this.readBuffer, 0, readBuffer.Length);
                }
                catch
                {
                    this.m_blsConnect = false;
                    this.m_NetStream  = null;
                }
                FileData temp = (FileData)FileData.Deserialize(readBuffer);

                switch ((int)temp.Type)
                {
                case (int)FileDataType.로그인:
                {
                    break;
                }

                case (int)FileDataType.일리스트:
                {
                    filelist fList = (filelist)FileData.Deserialize(readBuffer);
                    string   list  = fList.fileList;

                    string[] strset = list.Split('%');
                    for (int i = 1; i < strset.Length; i = i + 2)
                    {
                        ListViewItem lvi = new ListViewItem(strset[i - 1]);
                        lvi.SubItems.Add(strset[i]);
                        metroListView1.Items.Add(lvi);
                    }

                    break;
                }

                case (int)FileDataType.텍스트파일:
                {
                    textFile tempText = (textFile)FileData.Deserialize(readBuffer);
                    myText.fillText(tempText.text, tempText.userName);
                    break;
                }

                case (int)FileDataType.일:
                {
                    bool open = false;

                    myFile file = (myFile)FileData.Deserialize(readBuffer);

                    FileStream fs = new FileStream(drPath + "\\" + file.filename, FileMode.Create, FileAccess.Write);

                    fs.Close();

                    fs = new FileStream(drPath + "\\" + file.filename, FileMode.Append, FileAccess.Write);

                    for (int i = 0; i < (int)file.size / (1024 * 4); i++)        //파일크기만큼 반복문
                    {
                        if (open)
                        {
                            m_NetStream.Read(readBuffer, 0, readBuffer.Length);
                            file = (myFile)FileData.Deserialize(readBuffer);
                        }
                        fs.Write(file.data, 0, 1024 * 4);
                        open = true;
                    }
                    if (open)
                    {
                        m_NetStream.Read(readBuffer, 0, readBuffer.Length);
                    }

                    file = (myFile)FileData.Deserialize(readBuffer);
                    fs.Write(file.data, 0, (int)file.size % (1024 * 4));
                    break;
                }

                case (int)FileDataType.접속목록:
                {
                    listItem listitem = (listItem)FileData.Deserialize(readBuffer);
                    if (listitem.index != -1)
                    {
                        listView1.Items.RemoveAt(listitem.index);
                        break;
                    }
                    ListViewItem item;
                    item = new ListViewItem(listitem.list);
                    listView1.Items.Add(item);

                    break;
                }

                case (int)FileDataType.일체크:
                {
                    fileCheck fCheck = (fileCheck)FileData.Deserialize(readBuffer);
                    if (fCheck.fileNeed == 0)
                    {
                        textFile tFile = new textFile(backup);
                        tFile.Type      = (int)FileDataType.텍스트파일;
                        tFile.userName  = textBox3.Text;
                        tFile.userIndex = fCheck.fileNumber;        //원래는 파일넘버가 이게 아니지만 유저 인덱스 넘겨줌
                        sendBuffer      = FileData.Serialize(tFile);

                        m_NetStream.Write(sendBuffer, 0, sendBuffer.Length);
                        m_NetStream.Flush();
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }
        private void server_run()//서버를 열고 갯수만큼 가지고 있자.
        {
            int count = server_count;

            byte[] sendBuffer = new byte[1024 * 8];
            byte[] readBuffer = new byte[1024 * 8];
            m_Listener[count] = new TcpListener(Convert.ToInt32(port_text_box.Text));
            this.m_Listener[0].Start();//단일 리스너로 하면 되는거 같은데 잘모르겟다.
            m_ClientOn[count] = false;

            Socket Client = m_Listener[0].AcceptSocket();//이것도 연결요청 대기

            server_count++;
            people_count++;
            m_Thread[server_count] = new Thread(new ThreadStart(server_run));
            m_Thread[server_count].Start();

            if (Client.Connected)
            {
                m_ClientOn[count]     = true;
                m_NetStream[count]    = new NetworkStream(Client);
                connect_peopel[count] = true;
                Network_start[count]  = false;
            }

            while (m_ClientOn[count])
            {
                try
                {
                    m_NetStream[count].Read(readBuffer, 0, readBuffer.Length);
                }
                catch
                {
                    m_ClientOn[count]  = false;
                    m_NetStream[count] = null;
                }

                FileData temp = (FileData)FileData.Deserialize(readBuffer);

                switch ((int)temp.Type)
                {
                case (int)FileDataType.로그인:
                {
                    login log = (login)FileData.Deserialize(readBuffer);
                    if (log.logout)
                    {
                        int check = -1;
                        m_ClientOn[count] = false;
                        for (int i = 0; i < 32; i++)
                        {
                            if (client_text_list.Items[i].SubItems[1].Text == log.id)
                            {
                                check = i;
                                break;
                            }
                        }
                        server_text_box.AppendText(client_text_list.Items[check].SubItems[1].Text + "님이 로그아웃 하셧습니다.\n");
                        connect_peopel[Convert.ToInt32(client_text_list.Items[check].SubItems[0].Text)] = false;
                        client_text_list.Items.RemoveAt(check);

                        listItem removeItem = new listItem();
                        removeItem.index = check;
                        removeItem.Type  = (int)FileDataType.접속목록;
                        sendBuffer       = FileData.Serialize(removeItem);
                        for (int i = 0; i < 32; i++)
                        {
                            if (connect_peopel[i])
                            {
                                m_NetStream[i].Write(sendBuffer, 0, sendBuffer.Length);
                                this.m_NetStream[i].Flush();
                            }
                        }
                        people_count--;
                        break;
                    }
                    ListViewItem item;
                    string[]     itemStr = new string[3];
                    itemStr[0] = count.ToString();
                    itemStr[1] = log.id;
                    itemStr[2] = "접속중...";
                    item       = new ListViewItem(itemStr);
                    client_text_list.Items.Add(item);
                    server_text_box.AppendText(log.id + "님이 로그인 하셧습니다.\n");

                    listItem listitem = new listItem();
                    listitem.list  = itemStr;
                    listitem.index = -1;
                    listitem.Type  = (int)FileDataType.접속목록;
                    sendBuffer     = FileData.Serialize(listitem);

                    for (int i = 0; i < 32; i++)
                    {
                        if (connect_peopel[i] && i != count)
                        {
                            m_NetStream[i].Write(sendBuffer, 0, sendBuffer.Length);
                            this.m_NetStream[i].Flush();
                        }
                    }
                    listitem.first = true;
                    for (int i = 0; i < people_count; i++)
                    {
                        itemStr[0]    = client_text_list.Items[i].SubItems[0].Text;
                        itemStr[1]    = client_text_list.Items[i].SubItems[1].Text;
                        itemStr[2]    = client_text_list.Items[i].SubItems[2].Text;
                        listitem.list = itemStr;
                        sendBuffer    = FileData.Serialize(listitem);
                        m_NetStream[count].Write(sendBuffer, 0, sendBuffer.Length);
                        m_NetStream[count].Flush();
                        Thread.Sleep(100);
                    }

                    break;
                }

                case (int)FileDataType.텍스트파일:
                {
                    textFile     tFile   = (textFile)FileData.Deserialize(readBuffer);
                    FileStream   fStream = new FileStream(path + "\\" + textBox1.Text + "/" + textBox2.Text + "월 " + textBox3.Text + "일" + "\\" + tFile.userName + ".txt", FileMode.Create, FileAccess.Write);
                    StreamWriter fWriter = new StreamWriter(fStream);
                    fWriter.Write(tFile.text);
                    mutex[tFile.userIndex] = true;
                    fWriter.Close();
                    fStream.Close();

                    break;
                }

                case (int)FileDataType.일:
                {
                    while (!mutex[count])
                    {
                        ;
                    }
                    mutex[count] = false;

                    bool open = false;

                    myFile file = (myFile)FileData.Deserialize(readBuffer);

                    server_text_box.AppendText(file.filename + " : 업데이트 요청 \n");

                    FileStream fs = new FileStream(path + "\\" + textBox1.Text + "/" + textBox2.Text + "월 " + textBox3.Text + "일" + "\\file\\" + file.filename, FileMode.Create, FileAccess.Write);

                    fs.Close();

                    fs = new FileStream(path + "\\" + textBox1.Text + "/" + textBox2.Text + "월 " + textBox3.Text + "일" + "\\file\\" + file.filename, FileMode.Append, FileAccess.Write);

                    for (int i = 0; i < (int)file.size / (1024 * 4); i++)      //파일크기만큼 반복문
                    {
                        if (open)
                        {
                            m_NetStream[count].Read(readBuffer, 0, readBuffer.Length);
                            file = (myFile)FileData.Deserialize(readBuffer);
                        }
                        fs.Write(file.data, 0, 1024 * 4);
                        open = true;
                    }
                    if (open)
                    {
                        m_NetStream[count].Read(readBuffer, 0, readBuffer.Length);
                    }

                    file = (myFile)FileData.Deserialize(readBuffer);
                    fs.Write(file.data, 0, (int)file.size % (1024 * 4));

                    server_text_box.AppendText(file.filename + " 업데이트\n");

                    fs.Close();
                    mutex[count] = true;
                    break;
                }

                case (int)FileDataType.일리스트:
                {
                    DirectoryInfo di       = new DirectoryInfo(path + "\\" + textBox1.Text + "/" + textBox2.Text + "월 " + textBox3.Text + "일" + "\\file");
                    string        fileList = "";
                    foreach (var item in di.GetFiles())
                    {
                        fileList += item.Name + "%";
                        fileList += item.Length + "%";
                    }
                    filelist fList = new filelist();

                    fList.fileList = fileList;
                    fList.Type     = (int)FileDataType.일리스트;
                    sendBuffer     = FileData.Serialize(fList);

                    m_NetStream[count].Write(sendBuffer, 0, sendBuffer.Length);
                    m_NetStream[count].Flush();

                    break;
                }

                case (int)FileDataType.일체크:
                {
                    string     userName = null;
                    string     data;
                    FileStream fStream;
                    fileCheck  fileCheck = (fileCheck)FileData.Deserialize(readBuffer);
                    for (int i = 0; i < 32; i++)
                    {
                        if (Convert.ToInt32(client_text_list.Items[i].SubItems[0].Text) == fileCheck.fileNumber)
                        {
                            userName = client_text_list.Items[i].SubItems[1].Text;
                            break;
                        }
                    }

                    if (fileCheck.fileNeed == 0)         //파일이 text 라면
                    {
                        while (!mutex[count])
                        {
                            ;
                        }
                        mutex[count] = false;

                        fStream = new FileStream(path + "\\" + textBox1.Text + "/" + textBox2.Text + "월 " + textBox3.Text + "일" + "\\" + userName + ".txt", FileMode.OpenOrCreate, FileAccess.Read);
                        StreamReader streamReader = new StreamReader(fStream);
                        data = streamReader.ReadToEnd();

                        textFile tFIle = new textFile(data);
                        tFIle.text     = data;
                        tFIle.userName = userName;
                        tFIle.Type     = (int)FileDataType.텍스트파일;

                        sendBuffer = FileData.Serialize(tFIle);
                        m_NetStream[count].Write(sendBuffer, 0, sendBuffer.Length);
                        m_NetStream[count].Flush();
                        streamReader.Close();
                        fStream.Close();

                        mutex[count] = true;
                    }
                    else if (fileCheck.fileNeed == 1)
                    {
                        while (!mutex[count])
                        {
                            ;
                        }
                        mutex[count] = false;
                        string filename = fileCheck.filename;

                        server_text_box.AppendText(filename + " : 전송요청 \n");

                        fStream = new FileStream(path + "\\" + textBox1.Text + "/" + textBox2.Text + "월 " + textBox3.Text + "일" + "\\file\\" + filename, FileMode.OpenOrCreate, FileAccess.Read);
                        StreamReader streamReader = new StreamReader(fStream);

                        System.IO.FileInfo fi = new FileInfo(path + "\\" + textBox1.Text + "/" + textBox2.Text + "월 " + textBox3.Text + "일" + "\\file\\" + filename);

                        myFile myfile = new myFile();
                        myfile.Type     = (int)FileDataType.일;
                        myfile.size     = (int)fi.Length;
                        myfile.filename = filename;

                        Byte[] byteSendData = new Byte[1024 * 4];

                        for (int i = 0; i < (int)fi.Length / (1024 * 4); i++)
                        {
                            fStream.Read(byteSendData, 0, byteSendData.Length);        //바이트단위로 뜯어서 보냄
                            myfile.data = byteSendData;
                            sendBuffer  = FileData.Serialize(myfile);
                            m_NetStream[count].Write(sendBuffer, 0, sendBuffer.Length);
                            m_NetStream[count].Flush();
                            Thread.Sleep(2);
                        }
                        fStream.Read(byteSendData, 0, (int)fi.Length % (1024 * 4));
                        myfile.data = byteSendData;
                        sendBuffer  = FileData.Serialize(myfile);
                        m_NetStream[count].Write(sendBuffer, 0, sendBuffer.Length);
                        m_NetStream[count].Flush();

                        server_text_box.AppendText(filename + " : 전송 완료 \n");
                        mutex[count] = true;
                    }
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
        }