Dataset Viewer
Auto-converted to Parquet Duplicate
code
stringlengths
1
1.05M
repo_name
stringlengths
6
83
path
stringlengths
3
242
language
stringclasses
222 values
license
stringclasses
20 values
size
int64
1
1.05M
#!/bin/sh # defines variable git=`ls -d */` && path=`pwd` && gitpath=$path/$git # git pull cd $gitpath && git pull && sh init.sh \ && now=`git log -1 --format="%at"` \ && last=`cat $path/last` # check timestamp, if changed print git log if [ ! $last ] || [ $now -gt $last ] ; then echo "git changed!!" && echo $now>$path/last && echo `git log -1` else echo "git not change" fi # git push date > date.md if [ -n "$(git status -s)" ] ; then git add . git commit -m "update: `date +"%Y-%m-%d %H:%M:%S"` auto commit" git push fi
00fly/git-auto-push
all-in-one-cron-push.sh
Shell
apache-2.0
546
#!/bin/bash cp all-in-one-cron*.sh .. dos2unix ../*.sh && chmod +x ../*.sh
00fly/git-auto-push
init.sh
Shell
apache-2.0
76
#!/bin/sh # defines variable git=`ls -d */` && path=`pwd` && gitpath=$path/$git # git pull cd $gitpath && git pull \ && now=`git log -1 --format="%at"` \ && last=`cat $path/last` # check timestamp, if changed print git log if [ ! $last ] || [ $now -gt $last ] ; then echo "git changed!!" && echo $now>$path/last && echo `git log -1` else echo "git not change" fi
00fly/git-auto-push
run.sh
Shell
apache-2.0
369
QT += core gui network greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ chat.cpp \ file.cpp \ friend.cpp \ index.cpp \ main.cpp \ client.cpp \ onlineuser.cpp \ protocol.cpp \ reshandler.cpp HEADERS += \ chat.h \ client.h \ file.h \ friend.h \ index.h \ onlineuser.h \ protocol.h \ reshandler.h FORMS += \ chat.ui \ client.ui \ file.ui \ friend.ui \ index.ui \ onlineuser.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target RESOURCES += \ config.qrc
2201_75373101/CloudFileManagementSystem
Client/Client.pro
QMake
unknown
1,330
#include "chat.h" #include "protocol.h" #include "ui_chat.h" #include "client.h" Chat::Chat(QWidget *parent) : QWidget(parent), ui(new Ui::Chat) { ui->setupUi(this); setAttribute(Qt::WA_QuitOnClose, false); } Chat::~Chat() { delete ui; } void Chat::updateShowContent(QString strMsg) { ui->showContent_TE->append(strMsg); } void Chat::setChatName(QString strName) { this->m_strChatName = strName; this->setWindowTitle(strName); } void Chat::on_send_PB_clicked() { QString strMsg = ui->input_LE->text(); ui->input_LE->clear(); PDU* pdu = mkPDU(ENUM_MSG_TYPE_CHAT_REQUEST, strMsg.toStdString().size()); memcpy(pdu->caData, Client::getInstance().m_strLoginName.toStdString().c_str(), 32); memcpy(pdu->caData + 32, m_strChatName.toStdString().c_str(), 32); memcpy(pdu->caMsg, strMsg.toStdString().c_str(), pdu->uiMsgLen); Client::getInstance().sendMsg(pdu); }
2201_75373101/CloudFileManagementSystem
Client/chat.cpp
C++
unknown
920
#ifndef CHAT_H #define CHAT_H #include <QWidget> namespace Ui { class Chat; } class Chat : public QWidget { Q_OBJECT public: explicit Chat(QWidget *parent = nullptr); ~Chat(); QString m_strChatName; void updateShowContent(QString strMsg); void setChatName(QString strName); private slots: void on_send_PB_clicked(); private: Ui::Chat *ui; }; #endif // CHAT_H
2201_75373101/CloudFileManagementSystem
Client/chat.h
C++
unknown
400
#include <QFile> #include <QDebug> #include <QHostAddress> #include <QMessageBox> #include "client.h" #include "protocol.h" #include "ui_client.h" #include "index.h" Client::Client(QWidget *parent): QWidget(parent), ui(new Ui::Client) { ui->setupUi(this); rh = new ResHandler(); loadConfig(); //加载配置 connect(&m_tcpSocket, &QTcpSocket::connected, this, &Client::showConnect); connect(&m_tcpSocket, &QTcpSocket::readyRead, this, &Client::recvMsg); m_tcpSocket.connectToHost(QHostAddress(this->m_strIP), this->m_usPORT); } // 返回单例模式下的静态对象 Client &Client::getInstance() { static Client instance; return instance; } // 发送消息 void Client::sendMsg(PDU *pdu) { // 显示pdu内容 qDebug() << "发送消息->" << "消息类型:" << pdu->uiMsgType << "PDU长度:" << pdu->uiPDULen << "消息长度:" << pdu->uiMsgLen << "PDU数据1:" << pdu->caData << "PDU数据2:" << pdu->caData + 32 << "消息内容:" << pdu->caMsg; // 将pdu写如套接字(发送pdu) m_tcpSocket.write((char*)pdu, pdu->uiPDULen); free(pdu); pdu = NULL; } PDU *Client::readPDU() { qDebug() << "recvMsg 接收消息的长度:" << m_tcpSocket.bytesAvailable(); // 从套接字中读取协议总长度到uiPDULen uint uiPDULen = 0; m_tcpSocket.read((char*)&uiPDULen, sizeof(uint)); // 计算协议消息长度到uiMsgLen uint uiMsgLen = uiPDULen - sizeof(PDU); PDU* pdu = mkPDU(0, uiMsgLen) ; m_tcpSocket.read((char*)pdu + sizeof(uint), uiPDULen - sizeof(uint)); // 读取除了总长度以外的剩余长度的内容 qDebug() << "接收消息->" << "消息类型:" << pdu->uiMsgType << "PDU长度:" << pdu->uiPDULen << "消息长度:" << pdu->uiMsgLen << "PDU数据1:" << pdu->caData << "PDU数据2:" << pdu->caData + 32 << "消息内容:" << pdu->caMsg; return pdu; } void Client::handleRes(PDU *pdu) { rh->pdu = pdu; switch(pdu->uiMsgType){ case ENUM_MSG_TYPE_REGIST_RESPOND: { rh->regist(); break; } case ENUM_MSG_TYPE_LOGIN_RESPOND: { rh->login(); break; } case ENUM_MSG_TYPE_FIND_USER_RESPOND: { rh->findUser(); break; } case ENUM_MSG_TYPE_ONLINE_USER_RESPOND: { rh->onlineUser(m_strLoginName); break; } case ENUM_MSG_TYPE_ADD_FRIEND_RESPOND: { rh->addFriend(); break; } case ENUM_MSG_TYPE_ADD_FRIEND_REQUEST: { rh->addFriendRequest(); break; } case ENUM_MSG_TYPE_ADD_FRIEND_AGREE_RESPOND: { rh->addFriendAgree(); break; } case ENUM_MSG_TYPE_ADD_FRIEND_AGREE_REQUEST: { rh->addFriendAgree(); break; } case ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND: { rh->flushFriend(); break; } case ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND: { rh->delFriend(); break; } case ENUM_MSG_TYPE_CHAT_RESPOND: { rh->chatRequest(); break; } case ENUM_MSG_TYPE_MKDIR_RESPOND: { rh->mkDir(); break; } default: break; } } QString Client::getRootPath() { return m_strRootPath; } Client::~Client() { delete rh; delete ui; } // 加载配置文件 void Client::loadConfig() { QFile file(":/client.config"); if(file.open(QIODevice::ReadOnly)) { QByteArray baData = file.readAll(); QString strData = QString(baData); QStringList strList = strData.split("\r\n"); m_strIP = strList.at(0); m_usPORT = strList.at(1).toUShort(); m_strRootPath = strList.at(2); file.close(); qDebug() << "loadConfig ip:" << m_strIP << "port:" << m_usPORT << "m_strRootPath:" << m_strRootPath; } else { qDebug() << "打开配置失败"; } } // 显示服务器连接情况 void Client::showConnect() { qDebug() << "连接服务器成功"; } // 接收消息 void Client::recvMsg() { PDU* pdu = readPDU(); handleRes(pdu); free(pdu); pdu = NULL; } void Client::on_regist_PB_clicked() { QString strName = ui->name_LE->text(); QString strPwd = ui->pwd_LE ->text(); PDU* pdu = mkPDU(ENUM_MSG_TYPE_REGIST_REQUEST, 0); memcpy(pdu->caData , strName.toStdString().c_str(), 32); memcpy(pdu->caData + 32, strPwd .toStdString().c_str(), 32); sendMsg(pdu); } void Client::on_login_PB_clicked() { QString strName = ui->name_LE->text(); QString strPwd = ui->pwd_LE ->text(); m_strLoginName = strName; PDU* pdu = mkPDU(ENUM_MSG_TYPE_LOGIN_REQUEST, 0); memcpy(pdu->caData , strName.toStdString().c_str(), 32); memcpy(pdu->caData + 32, strPwd .toStdString().c_str(), 32); sendMsg(pdu); }
2201_75373101/CloudFileManagementSystem
Client/client.cpp
C++
unknown
4,954
#ifndef CLIENT_H #define CLIENT_H #include <QWidget> #include <QTcpSocket> #include "protocol.h" #include "index.h" #include "reshandler.h" QT_BEGIN_NAMESPACE namespace Ui { class Client; } QT_END_NAMESPACE class Client : public QWidget { Q_OBJECT public: ~Client(); static Client& getInstance(); // 单例模式下返回实例 void loadConfig() ; // 加载配置文件 void sendMsg(PDU* pdu) ; // 发送消息 PDU* readPDU() ; void handleRes(PDU* pdu); QString getRootPath(); QString m_strLoginName; ResHandler* rh; public slots: void showConnect(); // 显示服务器连接情况 void recvMsg() ; // 接收消息 //private slots: // void on_pushButton_clicked(); private slots: void on_regist_PB_clicked(); // 注册按钮槽函数 void on_login_PB_clicked() ; // 登录按钮槽函数 private: // 单例模式 Client(QWidget* parent = nullptr); Client(const Client& instance) = delete; Client& operator=(const Client&) = delete; Ui::Client *ui ; // 客服端ui界面 QString m_strIP ; // 服务器IP qint16 m_usPORT ; // 服务器端口号 QTcpSocket m_tcpSocket; // 套接字(与服务器通信) QString m_strRootPath; }; #endif // CLIENT_H
2201_75373101/CloudFileManagementSystem
Client/client.h
C++
unknown
1,326
#include "client.h" #include "file.h" #include "ui_file.h" #include <QInputDialog> #include <QMessageBox> File::File(QWidget *parent) : QWidget(parent), ui(new Ui::File) { ui->setupUi(this); m_strUserPath = QString("%1/%2").arg(Client::getInstance().getRootPath()).arg(Client::getInstance().m_strLoginName); m_strCurPath = m_strUserPath; } File::~File() { delete ui; } void File::on_mkdir_PB_clicked() { QString strNewDir = QInputDialog::getText(this, "新建文件夹", "新建文件夹名"); if(strNewDir.isEmpty() || strNewDir.toStdString().size() > 32){ QMessageBox::information(this, "新建文件夹", "文件夹名长度非法"); return; } PDU* pdu = mkPDU(ENUM_MSG_TYPE_MKDIR_REQUEST, m_strCurPath.toStdString().size() + 1); memcpy(pdu->caData, strNewDir.toStdString().c_str(), 32); memcpy(pdu->caMsg, m_strCurPath.toStdString().c_str(), m_strCurPath.toStdString().size()); Client::getInstance().sendMsg(pdu); }
2201_75373101/CloudFileManagementSystem
Client/file.cpp
C++
unknown
987
#ifndef FILE_H #define FILE_H #include <QWidget> namespace Ui { class File; } class File : public QWidget { Q_OBJECT public: explicit File(QWidget *parent = nullptr); ~File(); QString m_strUserPath; QString m_strCurPath ; private slots: void on_mkdir_PB_clicked(); private: Ui::File *ui; }; #endif // FILE_H
2201_75373101/CloudFileManagementSystem
Client/file.h
C++
unknown
344
#include "friend.h" #include "protocol.h" #include "ui_friend.h" #include "client.h" #include <QInputDialog> #include <QMessageBox> Friend::Friend(QWidget *parent) : QWidget(parent), ui(new Ui::Friend) { ui->setupUi(this); m_pOnlineUser = new OnlineUser; m_pChat = new Chat; flushFriend(); } Friend::~Friend() { delete ui; } OnlineUser *Friend::getOnlineUser() { return m_pOnlineUser; } void Friend::flushFriend() { PDU* pdu = mkPDU(ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST, 0); Client::getInstance().sendMsg(pdu); } void Friend::updateFriendWigetList(QStringList &friendlist) { ui->friend_LW->clear(); ui->friend_LW->addItems(friendlist); } void Friend::on_findUser_BP_clicked() { qDebug() << "输入查找用户名"; QString strName = QInputDialog::getText(this, "查找用户", "用户名:"); PDU* pdu = mkPDU(ENUM_MSG_TYPE_FIND_USER_REQUEST, 0); memcpy(pdu->caData, strName.toStdString().c_str(), 32); Client::getInstance().sendMsg(pdu); } void Friend::on_onlineUser_BP_clicked() { if(m_pOnlineUser->isHidden()) { m_pOnlineUser->show(); } PDU* pdu = mkPDU(ENUM_MSG_TYPE_ONLINE_USER_REQUEST, 0); Client::getInstance().sendMsg(pdu); } void Friend::on_flushFriend_BP_clicked() { flushFriend(); } void Friend::on_delFriend_BP_clicked() { QListWidgetItem* pItem = ui->friend_LW->currentItem(); if(!pItem){ QMessageBox::information(this, "删除好友", "请选择要删除的好友"); return; } QString strTarName = pItem->text(); if(QMessageBox::question(this, "删除好友", QString("确认删除%1吗?").arg(strTarName)) == QMessageBox::No) return; PDU* pdu = mkPDU(ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST, 0); memcpy(pdu->caData, Client::getInstance().m_strLoginName.toStdString().c_str(), 32); memcpy(pdu->caData + 32, strTarName.toStdString().c_str(), 32); Client::getInstance().sendMsg(pdu); } void Friend::on_chat_BP_clicked() { QListWidgetItem* pItem = ui->friend_LW->currentItem(); if(!pItem){ QMessageBox::information(this, "聊天", "请选择要聊天的好友"); return; } if(m_pChat->isHidden()){ m_pChat->show(); } m_pChat->setChatName(pItem->text()); }
2201_75373101/CloudFileManagementSystem
Client/friend.cpp
C++
unknown
2,265
#ifndef FRIEND_H #define FRIEND_H #include <QWidget> #include "onlineuser.h" #include "chat.h" namespace Ui { class Friend; } class Friend : public QWidget { Q_OBJECT public: explicit Friend(QWidget *parent = nullptr); ~Friend(); OnlineUser* getOnlineUser(); void flushFriend(); void updateFriendWigetList(QStringList& friendlist); Chat* m_pChat; private slots: void on_findUser_BP_clicked(); void on_onlineUser_BP_clicked(); void on_flushFriend_BP_clicked(); void on_delFriend_BP_clicked(); void on_chat_BP_clicked(); private: Ui::Friend *ui; OnlineUser* m_pOnlineUser; }; #endif // FRIEND_H
2201_75373101/CloudFileManagementSystem
Client/friend.h
C++
unknown
663
#include "index.h" #include "ui_index.h" Index::Index(QWidget *parent) : QWidget(parent), ui(new Ui::Index) { ui->setupUi(this); } Index::~Index() { delete ui; } Index& Index::getInstance() { static Index instance; return instance; } Friend *Index::getFriend() { return ui->friendPage; } File *Index::getFile() { return ui->filePage; } void Index::on_friend_PB_clicked() { ui->stackedWidget->setCurrentIndex(0); ui->friend_PB->setStyleSheet("QPushButton{border:none;background-color:rgb(255,255,255);padding:20px};"); ui->file_PB ->setStyleSheet("QPushButton{border:none;background-color:rgba(255,255,255,0);padding:20px};"); } void Index::on_file_PB_clicked() { ui->stackedWidget->setCurrentIndex(1); ui->file_PB ->setStyleSheet("QPushButton{border:none;background-color:rgb(255,255,255);padding:20px};"); ui->friend_PB->setStyleSheet("QPushButton{border:none;background-color:rgba(255,255,255,0);padding:20px};"); }
2201_75373101/CloudFileManagementSystem
Client/index.cpp
C++
unknown
979
#ifndef INDEX_H #define INDEX_H #include <QWidget> #include "friend.h" #include "file.h" namespace Ui { class Index; } class Index : public QWidget { Q_OBJECT public: ~Index(); static Index& getInstance(); Friend* getFriend(); File * getFile (); private slots: void on_friend_PB_clicked(); void on_file_PB_clicked(); private: Ui::Index *ui; explicit Index(QWidget *parent = nullptr); }; #endif // INDEX_H
2201_75373101/CloudFileManagementSystem
Client/index.h
C++
unknown
452
#include "client.h" #include "protocol.h" #include "index.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Client::getInstance().show(); return a.exec(); }
2201_75373101/CloudFileManagementSystem
Client/main.cpp
C++
unknown
211
#include "client.h" #include "onlineuser.h" #include "ui_onlineuser.h" OnlineUser::OnlineUser(QWidget *parent) : QWidget(parent), ui(new Ui::OnlineUser) { ui->setupUi(this); setAttribute(Qt::WA_QuitOnClose, false); } OnlineUser::~OnlineUser() { delete ui; } void OnlineUser::updateOnlineUserWigetList(QStringList &userlist) { ui->onlineUser_LW->clear(); ui->onlineUser_LW->addItems(userlist); } void OnlineUser::on_onlineUser_LW_itemDoubleClicked(QListWidgetItem *item) { QString strCurName = Client::getInstance().m_strLoginName; QString strTarName = item->text(); PDU* pdu = mkPDU(ENUM_MSG_TYPE_ADD_FRIEND_REQUEST, 0); memcpy(pdu->caData , strCurName.toStdString().c_str(), 32); memcpy(pdu->caData + 32, strTarName.toStdString().c_str(), 32); Client::getInstance().sendMsg(pdu); }
2201_75373101/CloudFileManagementSystem
Client/onlineuser.cpp
C++
unknown
845
#ifndef ONLINEUSER_H #define ONLINEUSER_H #include <QListWidget> #include <QWidget> namespace Ui { class OnlineUser; } class OnlineUser : public QWidget { Q_OBJECT public: explicit OnlineUser(QWidget *parent = nullptr); ~OnlineUser(); void updateOnlineUserWigetList(QStringList& userlist); private slots: void on_onlineUser_LW_itemDoubleClicked(QListWidgetItem *item); private: Ui::OnlineUser *ui; }; #endif // ONLINEUSER_H
2201_75373101/CloudFileManagementSystem
Client/onlineuser.h
C++
unknown
455
#include "protocol.h" #include <stdlib.h> PDU *mkPDU(uint uiMsgType, uint uiMsgLen) { PDU* pdu = (PDU*)malloc(sizeof (PDU) + uiMsgLen); if(pdu == NULL){ //判断是否成功分配内存 exit(1); } pdu->uiMsgLen = uiMsgLen; pdu->uiPDULen = uiMsgLen + sizeof(PDU); pdu->uiMsgType = uiMsgType; return pdu; }
2201_75373101/CloudFileManagementSystem
Client/protocol.cpp
C++
unknown
345
#ifndef PROTOCOL_H #define PROTOCOL_H typedef unsigned int uint; enum ENUM_MSG_TYPE{ // 消息类型 ENUM_MSG_TYPE_MIN = 0, ENUM_MSG_TYPE_REGIST_REQUEST, // 注册请求 ENUM_MSG_TYPE_REGIST_RESPOND, // 注册应答 ENUM_MSG_TYPE_LOGIN_REQUEST , // 登录请求 ENUM_MSG_TYPE_LOGIN_RESPOND , // 登录应答 ENUM_MSG_TYPE_FIND_USER_REQUEST, // 查找用户请求 ENUM_MSG_TYPE_FIND_USER_RESPOND, // 查找用户应答 ENUM_MSG_TYPE_ONLINE_USER_REQUEST, // 在线用户请求 ENUM_MSG_TYPE_ONLINE_USER_RESPOND, // 在线用户应答 ENUM_MSG_TYPE_ADD_FRIEND_REQUEST, // 添加好友请求 ENUM_MSG_TYPE_ADD_FRIEND_RESPOND, // 添加好友应答 ENUM_MSG_TYPE_ADD_FRIEND_AGREE_REQUEST, // 同意添加好友请求 ENUM_MSG_TYPE_ADD_FRIEND_AGREE_RESPOND, // 同意添加好友应答 ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST, // 刷新好友请求 ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND, // 刷新好友应答 ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST, // 删除好友请求 ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND, // 删除好友应答 ENUM_MSG_TYPE_CHAT_REQUEST, // 聊天请求 ENUM_MSG_TYPE_CHAT_RESPOND, // 聊天应答 ENUM_MSG_TYPE_MKDIR_REQUEST, // 创建文件夹请求 ENUM_MSG_TYPE_MKDIR_RESPOND, // 创建文件夹应答 ENUM_MSG_TYPE_MAX = 0x00ffffff }; struct PDU{ // 协议数据单元 uint uiPDULen ; // 协议总长度 uint uiMsgLen ; // 实际消息长度 uint uiMsgType ; // 消息类型 char caData[64]; // 参数 char caMsg[] ; // 实际消息 }; PDU* mkPDU(uint uiMsgType, uint uiMsgLen); #endif // PROTOCOL_H
2201_75373101/CloudFileManagementSystem
Client/protocol.h
C
unknown
1,649
#include <QMessageBox> #include "index.h" #include "reshandler.h" #include "client.h" ResHandler::ResHandler(QObject *parent) : QObject(parent) { } ResHandler::~ResHandler() { // delete pdu; } void ResHandler::regist() { bool ret; memcpy(&ret, pdu->caData, sizeof(bool)); if(ret) { QMessageBox::information(&Client::getInstance(), "提示", "注册成功"); } else { QMessageBox::information(&Client::getInstance(), "提示", "注册失败: 用户名或密码非法"); } } void ResHandler::login() { bool ret; memcpy(&ret, pdu->caData, sizeof(bool)); if(ret) { QMessageBox::information(&Client::getInstance(), "提示", "登录成功"); Index::getInstance().show(); Client::getInstance().hide(); } else { QMessageBox::information(&Client::getInstance(), "提示", "登录失败: 用户名或密码错误"); } } void ResHandler::findUser() { int ret; memcpy(&ret, pdu->caData, 32); if(ret == -1) { QMessageBox::information(&Index::getInstance(), "提示", "该用户不存在"); } else if(ret == 0) { QMessageBox::information(&Index::getInstance(), "提示", "该用户不在线"); } else if(ret == 1) { int res = QMessageBox::information(&Index::getInstance(), "提示", "该用户在线", "添加好友", "取消"); if(res == 0){ QString strCurName = Client::getInstance().m_strLoginName; char caTarName[32] = { '\0' }; memcpy(caTarName, pdu->caData + 32, 32); PDU* pdu = mkPDU(ENUM_MSG_TYPE_ADD_FRIEND_REQUEST, 0); memcpy(pdu->caData , strCurName.toStdString().c_str(), 32); memcpy(pdu->caData + 32, caTarName , 32); Client::getInstance().sendMsg(pdu); } } } void ResHandler::onlineUser(QString m_strLoginName) { QStringList userlist; char userName[32]; uint len = pdu->uiMsgLen / 32; for(uint i = 0; i < len; i++){ memcpy(userName, pdu->caMsg + i * 32, 32); if(QString(userName) == m_strLoginName) continue; userlist.append(QString(userName)); } Index::getInstance().getFriend()->getOnlineUser()->updateOnlineUserWigetList(userlist); } void ResHandler::addFriend() { int ret; memcpy(&ret, pdu->caData, sizeof(ret)); if(ret == -2) { QMessageBox::information(&Index::getInstance(), "提示", "对方已是好友"); } else if(ret == -1) { QMessageBox::information(&Index::getInstance(), "提示", "出现内部错误"); } else if(ret == 0) { QMessageBox::information(&Index::getInstance(), "提示", "对方不在线"); } } void ResHandler::addFriendRequest() { char caCurName[32] = { '\0' }; memcpy(caCurName, pdu->caData, 32); int ret = QMessageBox::question(&Index::getInstance(), "提示", QString("是否同意 '%1' 的好友请求?").arg(caCurName)); if(ret != QMessageBox::Yes) return; PDU* respdu = mkPDU(ENUM_MSG_TYPE_ADD_FRIEND_AGREE_REQUEST, 0); memcpy(respdu->caData, pdu->caData, 64); Client::getInstance().sendMsg(respdu); } void ResHandler::addFriendAgree() { QMessageBox::information(&Index::getInstance(), "提示", "添加成功"); Index::getInstance().getFriend()->flushFriend(); } void ResHandler::flushFriend() { QStringList friendlist; char userName[32]; uint len = pdu->uiMsgLen / 32; for(uint i = 0; i < len; i++){ memcpy(userName, pdu->caMsg + i * 32, 32); friendlist.append(QString(userName)); } Index::getInstance().getFriend()->updateFriendWigetList(friendlist); } void ResHandler::delFriend() { int ret; memcpy(&ret, pdu->caData, sizeof(ret)); if(ret == 1) { QMessageBox::information(&Index::getInstance(), "提示", "删除成功"); } else if(ret == -1) { QMessageBox::information(&Index::getInstance(), "提示", "对方不是好友"); } else if(ret == 0) { QMessageBox::information(&Index::getInstance(), "提示", "内部错误"); } Index::getInstance().getFriend()->flushFriend(); } void ResHandler::chatRequest() { Chat* c = Index::getInstance().getFriend()->m_pChat; if(c->isHidden()){ c->show(); } char caChatName[32] = { '\0' }; memcpy(caChatName, pdu->caData, 32); if(QString(caChatName) != Client::getInstance().m_strLoginName){ c->setChatName(caChatName); } c->updateShowContent(QString("%1: %2").arg(caChatName).arg((char*)pdu->caMsg)); } void ResHandler::mkDir() { bool ret; memcpy(&ret, pdu->caData, sizeof(bool)); if(ret){ QMessageBox::information(&Index::getInstance(), "提示", "文件夹创建成功"); }else{ QMessageBox::information(&Index::getInstance(), "提示", "文件夹创建失败"); } }
2201_75373101/CloudFileManagementSystem
Client/reshandler.cpp
C++
unknown
4,932
#ifndef RESHANDLER_H #define RESHANDLER_H #include <QObject> #include "protocol.h" class ResHandler : public QObject { Q_OBJECT public: explicit ResHandler(QObject *parent = nullptr); ~ResHandler(); PDU* pdu; void regist(); void login(); void findUser(); void onlineUser(QString loginName); void addFriend(); void addFriendRequest(); void addFriendAgree(); void flushFriend(); void delFriend(); void chatRequest(); void mkDir(); signals: }; #endif // RESHANDLER_H
2201_75373101/CloudFileManagementSystem
Client/reshandler.h
C++
unknown
531
QT += core gui network sql greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++11 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ mytcpserver.cpp \ mytcpsocket.cpp \ operatedb.cpp \ protocol.cpp \ reqhandler.cpp \ server.cpp HEADERS += \ mytcpserver.h \ mytcpsocket.h \ operatedb.h \ protocol.h \ reqhandler.h \ server.h FORMS += \ server.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target RESOURCES += \ config.qrc
2201_75373101/CloudFileManagementSystem
Server/Server.pro
QMake
unknown
1,219
#include "server.h" #include <QApplication> #include "operatedb.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); OperateDB::getInstance().connect(); Server::getInstance(); // w.show(); return a.exec(); }
2201_75373101/CloudFileManagementSystem
Server/main.cpp
C++
unknown
242
#include "mytcpserver.h" #include "mytcpsocket.h" MyTcpServer &MyTcpServer::getInstance() { static MyTcpServer instance; return instance; } void MyTcpServer::incomingConnection(qintptr handle) { qDebug() << "新的客户端连接"; // 每一个新的客户端连接都其tcpSocket将存入的列表中 MyTcpSocket* pTcpSocket = new MyTcpSocket; pTcpSocket->setSocketDescriptor(handle); m_tcpSocketList.append(pTcpSocket); connect(pTcpSocket, &MyTcpSocket::offline, this, &MyTcpServer::removeSocket); } void MyTcpServer::resend(char *tarName, PDU *pdu) { qDebug() << "查找转发目标:" << tarName; foreach(MyTcpSocket* pTcpSocket, m_tcpSocketList) { if(pTcpSocket->m_strLoginName == tarName) { pTcpSocket->write((char*)pdu, pdu->uiPDULen); qDebug() << "转发消息->" << "消息类型:" << pdu->uiMsgType << "PDU长度:" << pdu->uiPDULen << "消息长度:" << pdu->uiMsgLen << "PDU数据1:" << pdu->caData << "PDU数据2:" << pdu->caData + 32 << "消息内容:" << pdu->caMsg; return; } } qDebug() << "未找到目标:" << tarName; } void MyTcpServer::removeSocket(MyTcpSocket *mysocket) { m_tcpSocketList.removeOne(mysocket); mysocket->deleteLater(); mysocket = NULL; // 测试 qDebug() << m_tcpSocketList.size(); for(int i = 0; i < m_tcpSocketList.size(); i++) { qDebug() << m_tcpSocketList.at(i)->m_strLoginName; } } MyTcpServer::MyTcpServer() { }
2201_75373101/CloudFileManagementSystem
Server/mytcpserver.cpp
C++
unknown
1,639
#ifndef MYTCPSERVER_H #define MYTCPSERVER_H #include "mytcpsocket.h" #include <QObject> #include <QTcpServer> class MyTcpServer : public QTcpServer { Q_OBJECT public: // 返回单例模式下的静态实例 static MyTcpServer& getInstance(); void incomingConnection(qintptr handle); void resend(char* tarName, PDU* pdu); public slots: void removeSocket(MyTcpSocket* mysocket); private: // 单例模式 MyTcpServer(); MyTcpServer(const MyTcpServer& instance) = delete; MyTcpServer& operator = (const MyTcpServer&) = delete; // 连接的套接字列表 QList<MyTcpSocket*> m_tcpSocketList; }; #endif // MYTCPSERVER_H
2201_75373101/CloudFileManagementSystem
Server/mytcpserver.h
C++
unknown
675
#include <QString> #include "mytcpsocket.h" #include "protocol.h" #include "operatedb.h" #include "mytcpserver.h" MyTcpSocket::MyTcpSocket() { rh = new ReqHandler(); connect(this, &QTcpSocket::readyRead , this, &MyTcpSocket::recvMsg ); connect(this, &QTcpSocket::disconnected, this, &MyTcpSocket::clientOffline); } MyTcpSocket::~MyTcpSocket() { delete rh; } // 发送消息 void MyTcpSocket::sendMsg(PDU *pdu) { if(pdu == NULL) return; write((char*)pdu, pdu->uiPDULen); qDebug() << "发送消息->" << "消息类型:" << pdu->uiMsgType << "PDU长度:" << pdu->uiPDULen << "消息长度:" << pdu->uiMsgLen << "PDU数据1:" << pdu->caData << "PDU数据2:" << pdu->caData + 32 << "消息内容:" << pdu->caMsg; free(pdu); pdu = NULL; } PDU *MyTcpSocket::readPDU() { qDebug() << "readPDU 接收消息的长度:" << this->bytesAvailable(); uint uiPDULen = 0; this->read((char*)&uiPDULen, sizeof(uint)); // 读协议总长度 uint uiMsgLen = uiPDULen - sizeof(PDU); PDU* pdu = mkPDU(0, uiMsgLen); this->read((char*)pdu + sizeof(uint), uiPDULen - sizeof(uint)); // 读取除了总长度以外的剩余长度的内容 qDebug() << "\n接收消息->" << "消息类型:" << pdu->uiMsgType << "PDU长度:" << pdu->uiPDULen << "消息长度:" << pdu->uiMsgLen << "PDU数据1:" << pdu->caData << "PDU数据2:" << pdu->caData + 32 << "消息内容:" << pdu->caMsg; return pdu; } PDU *MyTcpSocket::handleReq(PDU *pdu) { PDU* resPdu = NULL; rh->pdu = pdu; switch(pdu->uiMsgType){ case ENUM_MSG_TYPE_REGIST_REQUEST: { qDebug() << "\n注册请求>>"; resPdu = rh->regist(); break; } case ENUM_MSG_TYPE_LOGIN_REQUEST: { qDebug() << "\n登录请求>>"; resPdu = rh->login(m_strLoginName); break; } case ENUM_MSG_TYPE_FIND_USER_REQUEST: { qDebug() << "\n查找用户请求>>"; resPdu = rh->findUser(); break; } case ENUM_MSG_TYPE_ONLINE_USER_REQUEST: { qDebug() << "\n在线用户请求>>"; resPdu = rh->onlineUser(); break; } case ENUM_MSG_TYPE_ADD_FRIEND_REQUEST: { qDebug() << "\n添加好友请求>>"; resPdu = rh->addFriend(); break; } case ENUM_MSG_TYPE_ADD_FRIEND_AGREE_REQUEST: { resPdu = rh->addFriendAgree(); break; } case ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST: { resPdu = rh->flushFriend(m_strLoginName); break; } case ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST: { qDebug() << "\n删除好友请求>>"; resPdu = rh->delFriend(); break; } case ENUM_MSG_TYPE_CHAT_REQUEST: { qDebug() << "\n聊天请求>>"; resPdu = rh->chat(); break; } case ENUM_MSG_TYPE_MKDIR_REQUEST: { qDebug() << "\n创建文件夹请求>>"; resPdu = rh->mkDir(); break; } default: break; } free(pdu) ; pdu = NULL; return resPdu; } // 接收消息 void MyTcpSocket::recvMsg() { QByteArray data = this->readAll(); buff.append(data); PDU* pdu = readPDU(); PDU* resPdu = handleReq(pdu); sendMsg(resPdu); } void MyTcpSocket::clientOffline() { OperateDB::getInstance().handleOffline(m_strLoginName.toStdString().c_str()); emit offline(this); }
2201_75373101/CloudFileManagementSystem
Server/mytcpsocket.cpp
C++
unknown
3,549
#ifndef MYTCPSOCKET_H #define MYTCPSOCKET_H #include "protocol.h" #include "reqhandler.h" #include <QObject> #include <QTcpSocket> class MyTcpSocket : public QTcpSocket { Q_OBJECT public: MyTcpSocket(); ~MyTcpSocket(); // 发送消息 void sendMsg(PDU* pdu); PDU* readPDU(); PDU* handleReq(PDU* pdu); QString m_strLoginName; ReqHandler* rh; public slots: // 接收消息 void recvMsg(); void clientOffline(); signals: void offline(MyTcpSocket* mysocket); }; #endif // MYTCPSOCKET_H
2201_75373101/CloudFileManagementSystem
Server/mytcpsocket.h
C++
unknown
539
#include "operatedb.h" #include <QDebug> #include <QSqlError> #include <QSqlQuery> OperateDB &OperateDB::getInstance() { static OperateDB instance; return instance; } OperateDB::OperateDB(QObject *parent) : QObject(parent) { m_db = QSqlDatabase::addDatabase("QMYSQL"); } // 连接数据库 void OperateDB::connect() { m_db.setHostName ("localhost"); m_db.setPort (3306 ); m_db.setUserName ("root" ); m_db.setPassword ("123456" ); m_db.setDatabaseName("ydj" ); if(m_db.open()){ qDebug() << "数据库连接成功"; } else{ qDebug() << "数据库连接失败" << m_db.lastError().text(); } } OperateDB::~OperateDB() { m_db.close(); } // 数据库处理注册请求 bool OperateDB::handleResgist(const char *name, const char *pwd) { if(name == NULL || pwd == NULL) { return false; } //判断用户是否存在 QString sql = QString("select * from user_info where name = '%1'").arg(name); qDebug() << "数据库-判断注册用户是否已存在->"; QSqlQuery q; if(!q.exec(sql) || q.next()) { return false; } //创建用户 sql = QString("insert into user_info(name, pwd) value('%1', '%2')").arg(name).arg(pwd); qDebug() << "数据库-注册用户->"; return q.exec(sql); } bool OperateDB::handleLogin(const char *name, const char *pwd) { if(name == NULL || pwd == NULL) { return false; } QString sql = QString("select * from user_info where name = '%1' and pwd = '%2'").arg(name).arg(pwd); QSqlQuery q; qDebug() << "数据库-查询登录用户是否存在"; if(!(q.exec(sql) && q.next())) { return false; } sql = QString("update user_info set online = 1 where name = '%1' and pwd = '%2'").arg(name).arg(pwd); qDebug() << "数据库-更新该用户的在线情况->上线"; return q.exec(sql); } void OperateDB::handleOffline(const char *name) { QString sql = QString("update user_info set online = 0 where name = '%1'").arg(name); qDebug() << "数据库-更新该用户的在线情况->下线"; QSqlQuery q; q.exec(sql); } int OperateDB::handleFindUser(const char *name) { QString sql = QString("select online from user_info where name = '%1'").arg(name); qDebug() << "数据库-查找该用户:" << sql; QSqlQuery q; q.exec(sql); if(q.next()){ return q.value(0).toInt(); // 返回0代表离线,1代表在线 } return -1; // -1代表不存在 } QStringList OperateDB::handleOnlineUser() { QString sql = QString("select name from user_info where online = 1"); qDebug() << "数据库-处理在线用户:" << sql; QSqlQuery q; q.exec(sql); QStringList res; while(q.next()) { res.append(q.value(0).toString()); } return res; // -1代表不存在 } int OperateDB::handleAddFriend(const char *caCurName, const char *caTarName) { if(caCurName == NULL || caTarName == NULL) return -1; QString sql = QString(R"( select * from friend where ( user_id = (select id from user_info where name = '%1') and friend_id = (select id from user_info where name = '%2') ) or ( friend_id = (select id from user_info where name = '%1') and user_id = (select id from user_info where name = '%2') ) )").arg(caCurName).arg(caTarName); qDebug() << "数据库-验证双方是否已是好友->"; qDebug() << sql; QSqlQuery q; if(!(q.exec(sql))) qDebug() << sql; if(q.next()) return -2; // 已经是好友 sql = QString("select online from user_info where name = '%1'").arg(caTarName); qDebug() << "数据库-验证应答方是否已在线->"; q.exec(sql); if(q.next()){ return q.value(0).toInt(); }else{ return -1; } } void OperateDB::handleAddFriendAgree(const char *caCurName, const char *caTarName) { if(caCurName == NULL || caTarName == NULL) return; QString sql = QString(R"( insert into friend(user_id, friend_id) select u1.id, u2.id from user_info u1, user_info u2 where u1.name = '%1' and u2.name = '%2' )").arg(caCurName).arg(caTarName); QSqlQuery q; q.exec(sql); } QStringList OperateDB::handleFlushFriend(const char *name) { QString sql = QString(R"( select name from user_info where id in ( select user_id from friend where friend_id = (select id from user_info where name = '%1') union select friend_id from friend where user_id = (select id from user_info where name = '%1') ) and online = 1 )").arg(name); qDebug() << "数据库-处理刷新好友:"; QSqlQuery q; q.exec(sql); QStringList res; while(q.next()) { res.append(q.value(0).toString()); } return res; // -1代表不存在 } int OperateDB::handleDelFriend(const char *caCurName, const char *caTarName) { if(caCurName == NULL || caTarName == NULL) return 0; QString sql = QString(R"( select * from friend where ( user_id = (select id from user_info where name = '%1') and friend_id = (select id from user_info where name = '%2') ) or ( friend_id = (select id from user_info where name = '%1') and user_id = (select id from user_info where name = '%2') ) )").arg(caCurName).arg(caTarName); qDebug() << "数据库-验证双方是否已是好友->"; QSqlQuery q; if(!(q.exec(sql))) qDebug() << sql; if(!(q.next())) return -1; // 不是好友 sql = QString(R"( delete from friend where ( user_id = (select id from user_info where name = '%1') and friend_id = (select id from user_info where name = '%2') ) or ( friend_id = (select id from user_info where name = '%1') and user_id = (select id from user_info where name = '%2') ) )").arg(caCurName).arg(caTarName); qDebug() << "数据库-删除双方好友关系->"; return q.exec(sql); }
2201_75373101/CloudFileManagementSystem
Server/operatedb.cpp
C++
unknown
7,215
#ifndef OPERATEDB_H #define OPERATEDB_H #include <QObject> #include <QSqlDatabase> class OperateDB : public QObject { Q_OBJECT public: QSqlDatabase m_db; //数据库对象 static OperateDB& getInstance(); // 连接数据库 void connect(); ~OperateDB(); bool handleResgist (const char* name, const char* pwd); // 处理注册请求 bool handleLogin (const char* name, const char* pwd); // 处理登录请求 void handleOffline (const char* name); // 处理下线 int handleFindUser(const char* name); // 处理查找用户请求 QStringList handleOnlineUser(); // 处理在线用户请求 int handleAddFriend (const char* caCurName, const char* caTarName); // 处理添加好友请求 void handleAddFriendAgree(const char* caCurName, const char* caTarName); // 处理同意添加好友请求 QStringList handleFlushFriend(const char* name); // 处理刷新好友请求 int handleDelFriend(const char* caCurName, const char* caTarName); // 处理删除好友请求 signals: private: // 单例模式 explicit OperateDB(QObject *parent = nullptr); OperateDB(const OperateDB& instance) = delete; OperateDB& operator=(const OperateDB&) = delete; }; #endif // OPERATEDB_H
2201_75373101/CloudFileManagementSystem
Server/operatedb.h
C++
unknown
1,318
#include "protocol.h" #include <stdlib.h> #include <string.h> PDU *mkPDU(uint uiMsgType, uint uiMsgLen) { PDU* pdu = (PDU*)malloc(sizeof (PDU) + uiMsgLen); if(pdu == NULL) { exit(1); } memset(pdu, 0, sizeof (PDU) + uiMsgLen); pdu->uiMsgLen = uiMsgLen; pdu->uiPDULen = uiMsgLen + sizeof(PDU); pdu->uiMsgType = uiMsgType; return pdu; }
2201_75373101/CloudFileManagementSystem
Server/protocol.cpp
C++
unknown
382
#ifndef PROTOCOL_H #define PROTOCOL_H typedef unsigned int uint; enum ENUM_MSG_TYPE{ // 消息类型 ENUM_MSG_TYPE_MIN = 0, ENUM_MSG_TYPE_REGIST_REQUEST, // 注册请求 ENUM_MSG_TYPE_REGIST_RESPOND, // 注册应答 ENUM_MSG_TYPE_LOGIN_REQUEST , // 登录请求 ENUM_MSG_TYPE_LOGIN_RESPOND , // 登录应答 ENUM_MSG_TYPE_FIND_USER_REQUEST, // 查找用户请求 ENUM_MSG_TYPE_FIND_USER_RESPOND, // 查找用户应答 ENUM_MSG_TYPE_ONLINE_USER_REQUEST, // 在线用户请求 ENUM_MSG_TYPE_ONLINE_USER_RESPOND, // 在线用户应答 ENUM_MSG_TYPE_ADD_FRIEND_REQUEST, // 添加好友请求 ENUM_MSG_TYPE_ADD_FRIEND_RESPOND, // 添加好友应答 ENUM_MSG_TYPE_ADD_FRIEND_AGREE_REQUEST, // 同意添加好友请求 ENUM_MSG_TYPE_ADD_FRIEND_AGREE_RESPOND, // 同意添加好友应答 ENUM_MSG_TYPE_FLUSH_FRIEND_REQUEST, // 刷新好友请求 ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND, // 刷新好友应答 ENUM_MSG_TYPE_DELETE_FRIEND_REQUEST, // 删除好友请求 ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND, // 删除好友应答 ENUM_MSG_TYPE_CHAT_REQUEST, // 聊天请求 ENUM_MSG_TYPE_CHAT_RESPOND, // 聊天应答 ENUM_MSG_TYPE_MKDIR_REQUEST, // 创建文件夹请求 ENUM_MSG_TYPE_MKDIR_RESPOND, // 创建文件夹应答 ENUM_MSG_TYPE_MAX = 0x00ffffff }; struct PDU{ // 协议数据单元 uint uiPDULen ; // 协议总长度 uint uiMsgLen ; // 实际消息长度 uint uiMsgType ; // 消息类型 char caData[64]; // 参数 char caMsg [ ]; // 实际消息 }; PDU* mkPDU(uint uiMsgType, uint uiMsgLen); #endif // PROTOCOL_H
2201_75373101/CloudFileManagementSystem
Server/protocol.h
C
unknown
1,653
#include <QDebug> #include <QDir> #include "operatedb.h" #include "reqhandler.h" #include "mytcpserver.h" ReqHandler::ReqHandler(QObject *parent) : QObject(parent) { } PDU *ReqHandler::regist() { char caName[32] = { '\0' }; char caPwd [32] = { '\0' }; memcpy(caName, pdu->caData , 32); memcpy(caPwd , pdu->caData + 32, 32); qDebug() << "注册请求->" << caName << "注册用户名:" << caName << "注册密码:" << caPwd; bool ret = OperateDB::getInstance().handleResgist(caName, caPwd); if(ret){ QDir dir; dir.mkdir(QString("%1/%2").arg(Server::getInstance().getRootRath()).arg(caName)); } qDebug() << "handleResgist ret:" << ret; PDU* resPdu = mkPDU(ENUM_MSG_TYPE_REGIST_RESPOND, 0); memcpy(resPdu->caData, &ret, sizeof(ret)); return resPdu; } PDU *ReqHandler::login(QString &m_strLoginName) { char caName[32] = { '\0' }; char caPwd [32] = { '\0' }; memcpy(caName, pdu->caData , 32); memcpy(caPwd , pdu->caData + 32, 32); qDebug() << "登录请求->" << "登录用户名:" << caName << "登录密码:" << caPwd; bool ret = OperateDB::getInstance().handleLogin(caName, caPwd); if(ret) { m_strLoginName = caName; } qDebug() << "登录处理结果:" << ret; PDU* resPdu = mkPDU(ENUM_MSG_TYPE_LOGIN_RESPOND, 0); memcpy(resPdu->caData, &ret, sizeof(ret)); return resPdu; } PDU *ReqHandler::findUser() { char caName[32] = { '\0' }; memcpy(caName, pdu->caData , 32); qDebug() << "寻找的用户名:" << caName; int ret = OperateDB::getInstance().handleFindUser(caName); qDebug() << "寻找用户处理结果->" << ret; PDU* resPdu = mkPDU(ENUM_MSG_TYPE_FIND_USER_RESPOND, 0); memcpy(resPdu->caData , &ret , 32); memcpy(resPdu->caData + 32, caName, 32); return resPdu; } PDU *ReqHandler::onlineUser() { QStringList res = OperateDB::getInstance().handleOnlineUser(); uint uiMsgLen = res.size() * 32; PDU* resPdu = mkPDU(ENUM_MSG_TYPE_ONLINE_USER_RESPOND, uiMsgLen); for(int i = 0; i < res.size(); i++) { memcpy(resPdu->caMsg + i * 32, res.at(i).toStdString().c_str(), 32); } return resPdu; } PDU *ReqHandler::addFriend() { char caCurName[32] = { '\0' }; char caTarName[32] = { '\0' }; memcpy(caCurName, pdu->caData , 32); memcpy(caTarName, pdu->caData + 32, 32); qDebug() << "添加好友->" << "发起请求方:" << caCurName << "应答请求方:" << caTarName; int ret = OperateDB::getInstance().handleAddFriend(caCurName, caTarName); qDebug() << "添加好友处理结果:" << ret; if(ret == 1){ MyTcpServer::getInstance().resend(caTarName, pdu); return NULL; } PDU* resPdu = mkPDU(ENUM_MSG_TYPE_ADD_FRIEND_RESPOND, 0); memcpy(resPdu->caData, &ret, sizeof(ret)); return resPdu; } PDU* ReqHandler::addFriendAgree() { char caCurName[32] = { '\0' }; char caTarName[32] = { '\0' }; memcpy(caCurName, pdu->caData , 32); memcpy(caTarName, pdu->caData + 32, 32); OperateDB::getInstance().handleAddFriendAgree(caCurName, caTarName); PDU* resPdu = mkPDU(ENUM_MSG_TYPE_ADD_FRIEND_AGREE_RESPOND, 0); MyTcpServer::getInstance().resend(caCurName, resPdu); return resPdu; } PDU *ReqHandler::flushFriend(QString &m_strLoginName) { QStringList res = OperateDB::getInstance().handleFlushFriend(m_strLoginName.toStdString().c_str()); uint uiMsgLen = res.size() * 32; PDU* resPdu = mkPDU(ENUM_MSG_TYPE_FLUSH_FRIEND_RESPOND, uiMsgLen); for(int i = 0; i < res.size(); i++) { memcpy(resPdu->caMsg + i * 32, res.at(i).toStdString().c_str(), 32); } return resPdu; } PDU *ReqHandler::delFriend() { char caCurName[32] = { '\0' }; char caTarName[32] = { '\0' }; memcpy(caCurName, pdu->caData , 32); memcpy(caTarName, pdu->caData + 32, 32); qDebug() << "删除好友->" << "删除方:" << caCurName << "被删除方:" << caTarName; int ret = OperateDB::getInstance().handleDelFriend(caCurName, caTarName); qDebug() << "删除好友处理结果:" << ret; PDU* resPdu = mkPDU(ENUM_MSG_TYPE_DELETE_FRIEND_RESPOND, 0); memcpy(resPdu->caData, &ret, sizeof(ret)); return resPdu; } PDU *ReqHandler::chat() { char caTarName[32] = { '\0' }; memcpy(caTarName, pdu->caData + 32, 32); PDU* respdu = mkPDU(ENUM_MSG_TYPE_CHAT_RESPOND, pdu->uiMsgLen); memcpy(respdu->caData, pdu->caData, 64); memcpy(respdu->caMsg , pdu->caMsg , pdu->uiMsgLen); MyTcpServer::getInstance().resend(caTarName, respdu); return respdu; } PDU *ReqHandler::mkDir() { char caDirName[32] = { '\0' }; memcpy(caDirName, pdu->caData , 32); PDU* respdu = mkPDU(ENUM_MSG_TYPE_MKDIR_RESPOND, 0); QString strNewPath = QString("%1/%2").arg(pdu->caMsg).arg(caDirName); QDir dir; bool res = false; if(!dir.exists(pdu->caMsg)){ //当前路径不存在 qDebug() << "当前路径:" << pdu->caMsg << "->(不存在)"; memcpy(respdu->caData, &res, sizeof(res)); return respdu; } if(dir.exists(strNewPath) || !dir.mkdir(strNewPath)){ //路径存在 qDebug() << "新建路径:" << strNewPath << "->(已经存在)"; memcpy(respdu->caData, &res, sizeof(res)); return respdu; } res = true; memcpy(respdu->caData, &res, sizeof(res)); qDebug() << "路径" << strNewPath << "->(创建成功)"; return respdu; }
2201_75373101/CloudFileManagementSystem
Server/reqhandler.cpp
C++
unknown
5,569
#ifndef REQHANDLER_H #define REQHANDLER_H #include <QObject> #include "protocol.h" #include "server.h" class ReqHandler : public QObject { Q_OBJECT public: PDU* pdu; explicit ReqHandler(QObject *parent = nullptr); PDU* regist (); PDU* login (QString &m_strLoginName); PDU* findUser (); PDU* onlineUser(); PDU* addFriend (); PDU* addFriendAgree(); PDU* flushFriend(QString &m_strLoginName); PDU* delFriend (); PDU* chat(); PDU* mkDir(); signals: }; #endif // REQHANDLER_H
2201_75373101/CloudFileManagementSystem
Server/reqhandler.h
C++
unknown
539
#include "server.h" #include "ui_server.h" #include "mytcpserver.h" #include <QFile> #include <QDebug> #include <QHostAddress> Server::Server(QWidget *parent): QWidget(parent), ui(new Ui::Server) { ui->setupUi(this); loadConfig(); MyTcpServer::getInstance().listen(QHostAddress(m_strIP), m_usPORT); } Server::~Server() { delete ui; } // 加载配置 void Server::loadConfig() { QFile file(":/server.config"); if(file.open(QIODevice::ReadOnly)) { QByteArray baData = file.readAll(); QString strData = QString(baData); QStringList strList = strData.split("\r\n"); this-> m_strIP = strList.at(0); this-> m_usPORT = strList.at(1).toUShort(); this-> m_strRootRath = strList.at(2); file.close(); qDebug() << "loadConfig ip:" << m_strIP << "port:" << m_usPORT<< "m_strRootRath:" <<m_strRootRath; } else { qDebug() << "打开配置失败"; } } Server &Server::getInstance() { static Server instance; return instance; } QString Server::getRootRath() { return m_strRootRath; }
2201_75373101/CloudFileManagementSystem
Server/server.cpp
C++
unknown
1,122
#ifndef SERVER_H #define SERVER_H #include <QWidget> #include <QTcpSocket> QT_BEGIN_NAMESPACE namespace Ui { class Server; } QT_END_NAMESPACE class Server : public QWidget { Q_OBJECT public: ~Server(); void loadConfig(); // 加载配置 static Server& getInstance(); QString getRootRath(); private: Server(QWidget *parent = nullptr); Ui::Server *ui ; // 服务器ui QString m_strIP ; // 服务器IP qint16 m_usPORT; // 服务器端口 QString m_strRootRath; }; #endif // SERVER_H
2201_75373101/CloudFileManagementSystem
Server/server.h
C++
unknown
530
End of preview. Expand in Data Studio

GitCode Code Dataset

Dataset Description

This dataset was compiled from code repositories hosted on GitCode, a code hosting platform in China backed by CSDN (China Software Developer Network). GitCode serves as a domestic alternative to GitHub, widely used by Chinese developers, students, and enterprises for hosting open-source projects and educational resources, making this dataset particularly valuable for training code models with Chinese language understanding and Chinese coding conventions.

Dataset Summary

Statistic Value
Total Files 48,142,567
Total Repositories 85,632
Total Size 40 GB (compressed Parquet)
Programming Languages 537
File Format Parquet with Zstd compression (34 files)

Key Features

  • Chinese code corpus: Contains code from over 85,000 repositories, many featuring Chinese comments, documentation, and variable names
  • Diverse language coverage: Spans 537 programming languages identified by go-enry (based on GitHub Linguist rules)
  • Rich metadata: Includes repository name, file path, detected language, license information, and file size
  • Open-source and educational projects: Includes code from individual developers, students, and Chinese enterprises
  • Quality filtered: Extensive filtering to remove vendor code, build artifacts, generated files, and low-quality content

Languages

The dataset includes 537 programming languages. The top 30 languages by file count:

Rank Language File Count
1 C++ 9,513,619
2 C 8,220,317
3 Java 5,362,924
4 Python 3,428,302
5 TypeScript 3,166,959
6 JavaScript 2,540,280
7 HTML 1,578,824
8 Kotlin 1,413,651
9 C# 1,232,638
10 Go 1,159,708
11 Rust 812,959
12 Dart 767,731
13 TSX 749,355
14 PHP 663,953
15 Shell 629,436
16 Vue 563,754
17 Makefile 471,588
18 CMake 460,428
19 CSS 381,628
20 Ruby 350,213
21 Objective-C 347,251
22 LLVM 297,591
23 Unix Assembly 291,826
24 Swift 206,725
25 Objective-C++ 160,526
26 Scala 157,367
27 QML 157,088
28 Lua 149,114
29 SCSS 141,661
30 GLSL 129,124

Licenses

The dataset includes files from repositories with various licenses. Repositories with restrictive licenses (CC-BY-ND variants, Commons Clause, SSPL) were excluded:

License File Count
unknown 23,567,463
apache-2.0 8,722,445
mit 7,743,613
gpl-2.0 3,528,526
agpl-3.0 2,300,580
lgpl 1,013,654
bsd-3-clause 528,980
gpl-3.0 305,332
public-domain 163,493
bsd-2-clause 94,426
bsd 69,967
isc 36,117
unlicense 28,411
cc0-1.0 26,799
mpl-2.0 9,459
Other licenses ~5,000

Dataset Structure

Data Fields

Field Type Description
code string Content of the source file (UTF-8 encoded)
repo_name string Name of the GitCode repository (format: username/repo)
path string Path of the file within the repository (relative to repo root)
language string Programming language as identified by go-enry
license string License of the repository (SPDX identifier or "unknown")
size int64 Size of the source file in bytes

Data Format

  • Format: Apache Parquet with Zstd compression
  • File Structure: 34 files (gitcode_0000.parquet to gitcode_0033.parquet)

Data Splits

All examples are in the train split. There is no validation or test split.

Example Data Point

{
    'code': '#!/bin/sh\n# defines variable\ngit=`ls -d */` && path=`pwd` && gitpath=$path/$git\n...',
    'repo_name': '00fly/git-auto-push',
    'path': 'all-in-one-cron-push.sh',
    'language': 'Shell',
    'license': 'apache-2.0',
    'size': 546
}

Dataset Creation

Pipeline Overview

The dataset was created through a multi-stage pipeline:

  1. User Discovery: Collecting usernames via GitCode API
  2. Repository Discovery: Fetching repository lists for each user via GitCode API
  3. Repository Cloning: Using Git partial clone with blob size filtering
  4. Content Extraction: Extracting and filtering source code files
  5. Parquet Generation: Writing filtered records to Parquet shards with Zstd compression

Language Detection

Programming languages are detected using go-enry, a Go port of GitHub's Linguist library. Only files classified as Programming or Markup language types are included (Data and Prose types are excluded).

License Detection

Licenses are detected by:

  1. Scanning for license files (LICENSE, LICENSE.txt, LICENSE.md, COPYING, etc.)
  2. Matching license text against known patterns (MIT, Apache 2.0, GPL variants, BSD, Creative Commons, etc.)
  3. Defaulting to "unknown" if no license can be detected

Blocked Licenses: The following restrictive licenses are excluded from the dataset:

  • cc-by-nd, cc-by-nd-2.0, cc-by-nd-3.0, cc-by-nd-4.0 (Creative Commons No-Derivatives)
  • commons-clause
  • sspl, sspl-1.0 (Server Side Public License)

File Filtering

Extensive filtering is applied to ensure data quality:

Size Limits

Limit Value
Max single file size 1 MB
Max line length 1,000 characters

Excluded Directories

  • Configuration: .git/, .github/, .gitlab/, .vscode/, .idea/
  • Vendor/Dependencies: node_modules/, vendor/, third_party/, bower_components/
  • Build Output: build/, dist/, out/, bin/, target/, __pycache__/, .next/, .nuxt/, coverage/, .nyc_output/

Excluded Files

  • Lock Files: package-lock.json, yarn.lock, pnpm-lock.yaml, Cargo.lock, go.sum, composer.lock, Gemfile.lock, poetry.lock, Pipfile.lock
  • Minified Files: Any file containing .min. in the name
  • Binary Files: .exe, .dll, .so, .dylib, .a, .o, .obj, .lib, .jar, .class, .pyc, .pyo, .wasm, .zip, .tar, .gz, .bz2, .7z, .rar, .png, .jpg, .jpeg, .gif, .bmp, .ico, .svg, .webp, .mp3, .mp4, .avi, .mov, .wav, .pdf, .doc, .docx, .xls, .xlsx, .ttf, .otf, .woff, .woff2, .eot

Content Filtering

  • UTF-8 Validation: Files must be valid UTF-8 encoded text
  • Binary Detection: Files detected as binary by go-enry are excluded
  • Generated Files: Files with generation markers in the first 500 bytes are excluded:
    • generated by, do not edit, auto-generated, autogenerated, automatically generated, @generated, <auto-generated, this file is generated
  • Empty Files: Files that are empty or contain only whitespace are excluded
  • Long Lines: Files with any line exceeding 1,000 characters are excluded
  • go-enry Filters: Additional filtering using go-enry's IsVendor(), IsImage(), IsDotFile(), and IsGenerated() functions
  • Documentation-only Repos: Repositories containing only documentation files (no actual code) are skipped

Source Data

All data originates from public repositories hosted on GitCode.

Considerations for Using the Data

Personal and Sensitive Information

The dataset may contain:

  • Email addresses in code comments or configuration files
  • API keys or credentials that were accidentally committed
  • Personal information in comments or documentation

Users should exercise caution and implement appropriate filtering when using this data.

Licensing Information

This dataset is a collection of source code from repositories with various licenses. Any use of all or part of the code gathered in this dataset must abide by the terms of the original licenses, including attribution clauses when relevant. The license field in each data point indicates the license of the source repository.

Downloads last month
93

Collection including nyuuzyou/gitcode-code