├── DownloadTool ├── Makefile ├── download │ ├── download.cpp │ ├── download.h │ └── mythunder.cpp ├── mythunder ├── pool │ ├── Makefile │ ├── config.h │ ├── threadpool.cpp │ └── threadpool.h ├── tags └── window │ ├── window.cpp │ └── window.h ├── FileCompress ├── FileCompress.hpp ├── Heap.hpp ├── Huffman.hpp ├── Makefile ├── config.hpp ├── file ├── main.cpp └── tags ├── README.md └── STL ├── .vs └── STL │ └── v14 │ └── .suo ├── Debug ├── STL.exe ├── STL.ilk └── STL.pdb ├── STL.sdf ├── STL.sln └── STL ├── Allocate.h ├── Construct.h ├── Debug ├── Main.obj ├── STL.Build.CppClean.log ├── STL.log ├── STL.tlog │ ├── CL.command.1.tlog │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── STL.lastbuildstate │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ └── link.write.1.tlog ├── main.obj.enc ├── vc140.idb └── vc140.pdb ├── Iterator.h ├── List.h ├── Main.cpp ├── STL.vcxproj ├── STL.vcxproj.filters ├── STL.vcxproj.user ├── TypeTraits.h ├── Uninitialized.h └── Vector.h /DownloadTool/Makefile: -------------------------------------------------------------------------------- 1 | DLT_BIN=mythunder 2 | DLT_SRC= download/mythunder.cpp download/download.cpp window/window.cpp pool/threadpool.cpp 3 | 4 | CC=g++ 5 | 6 | $(DLT_BIN):$(DLT_SRC) 7 | $(CC) -o $@ $^ -lpthread -lncurses -g 8 | 9 | 10 | .PYONY:clean 11 | clean: 12 | rm -rf $(DLT_BIN) index.html WeChat_2.2.0.37_Setup.exe WeChat_2.2.0.37_Setup.exe.config QQ_* Chrome* 13 | -------------------------------------------------------------------------------- /DownloadTool/download/download.cpp: -------------------------------------------------------------------------------- 1 | #include "download.h" 2 | 3 | /////////////////////////////////////////////////////////////////////////////////// 4 | // @ 定义全局变量 5 | 6 | // @ 当前正在下载的任务数 7 | int _CURDISPLAY = 1; 8 | pthread_mutex_t curDisplayLock = PTHREAD_MUTEX_INITIALIZER; 9 | 10 | // @ 窗口 11 | DownWindow dw; 12 | // @ 线程池 13 | Threadpool tp; 14 | 15 | 16 | /////////////////////////////////////////////////////////////////////////////////// 17 | // @ 方法实现 18 | 19 | // @ 基本使用方法 20 | void usage() { cout << "./downloadtool" << endl; } 21 | 22 | // @ 从sock所指向的文件读取一行到buf中(包括换行),buf容量有buf_len指定 23 | int GetLine(int sock, char *buf, int buf_len) 24 | { 25 | if(!buf || buf_len < 0) 26 | return -1; 27 | int i = 0; 28 | int n = 0; 29 | char c = '\0'; 30 | while(i < buf_len && c != '\n') 31 | { 32 | n = recv(sock, &c, 1, 0); 33 | if(n > 0) 34 | { 35 | if(c == '\r') 36 | { 37 | n = recv(sock, &c, 1, MSG_PEEK); 38 | if(n > 0 && c == '\n') // @ 如果遇到\r\n,就把两个字符替换成一个\n 39 | recv(sock, &c, 1, 0); 40 | else // @ 只有一个\n,直接写 41 | c = '\n'; 42 | } 43 | buf[i++] = c; 44 | } 45 | else // @ 读到文件尾 46 | { 47 | c = '\n'; 48 | } 49 | } 50 | buf[i] = '\0'; 51 | return i; 52 | } 53 | 54 | // @ 由一个请求路径,得到最后面的文件名 55 | string GetFilenameFromAddr(string reqAddr) 56 | { 57 | const char *addr = reqAddr.c_str(); 58 | assert(addr); 59 | 60 | int right = strlen(addr) - 1; 61 | while(right >= 0) 62 | { 63 | if('/' == addr[right]) 64 | return string(addr+right+1); 65 | 66 | --right; 67 | } 68 | } 69 | 70 | // @ 由一个url,得到该地址对应的 ip、域名(domain)和路径(addr) 71 | IpAndDomainAndAddr AnalyseUrl(string & url) 72 | { 73 | //assert("" != url); 74 | 75 | char str[128]; 76 | char tmp[30]; 77 | char ip[16]; 78 | bzero(str, sizeof(str)); 79 | bzero(tmp, sizeof(tmp)); 80 | bzero(ip, sizeof(ip)); 81 | strcpy(str, url.c_str()); 82 | 83 | IpAndDomainAndAddr da; // 用于保存url的信息 84 | 85 | int index = 0; 86 | int len = strlen(str); 87 | int domainBegin = 0; 88 | while(index < len) 89 | { 90 | if(str[index] == '/') 91 | { 92 | if(index + 1 < len && str[index + 1] == '/') 93 | { 94 | ++index; 95 | domainBegin = index + 1; 96 | } 97 | else 98 | { 99 | char domain[_DOMAIN_MAX]; 100 | bzero(domain, _DOMAIN_MAX); 101 | 102 | struct hostent *hent = new struct hostent; 103 | // @ 由domain得到ip 104 | hent = gethostbyname((const char *)memcpy(tmp, str+domainBegin, index - domainBegin)); 105 | memcpy(domain, str+domainBegin, (index - domainBegin)); 106 | da.m_ip = string(inet_ntop(AF_INET, *hent->h_addr_list, ip, 16)); 107 | da.m_domain = string(domain); 108 | da.m_addr = string(str+index); 109 | 110 | return da; 111 | } 112 | } 113 | 114 | ++index; 115 | } 116 | 117 | cout << "wrong url..." << endl; 118 | } 119 | 120 | // @ 给服务器发送请求报文 121 | // @ 参数意义: sockfd(连接服务器的文件描述符) 122 | // info(所请求的资源的信息, ip、domain、addr) 123 | // offset(请求相应报文从offset开始发送, 用来实现断点续传) 124 | void SendRequestGram(int sockfd, struct IpAndDomainAndAddr &info, int offset) 125 | { 126 | const char *addr = info.m_addr.c_str(); 127 | const char *domain = info.m_domain.c_str(); 128 | 129 | char range[_RANGE_MAX]; 130 | bzero(range, _RANGE_MAX); 131 | sprintf(range, "bytes=%d-", offset); 132 | 133 | char buffer[_REQUEST_MAX]; 134 | bzero(buffer, _REQUEST_MAX); 135 | 136 | // @ buffer内容是请求报文的内容 137 | sprintf(buffer, "%s %s %s\nHost: %s\nAccept: %s\nAccept-Encoding: %s\nAccept-Language: %s\nUser-Agent: %s\nRange: %s\nProxy-Connection: %s\n\n", 138 | "GET", addr, "HTTP/1.1", 139 | domain, 140 | "text/html, application/xhtml+xml, application/xml;q=0.9,image/webp,*/*;q=0.8", 141 | "gzip,deflate,sdch", 142 | "zh-CN,zh;q=0.8", 143 | "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0", 144 | range, 145 | "close"); 146 | #ifdef __DEBUG__ 147 | cout << "send buf : " << buffer << endl; 148 | #endif 149 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 150 | //sprintf(buffer, "%s %s %s\nHost: %s\nUser-Agent: %s\nRange: %s\n\n", "GET", addr, "HTTP/1.1", domain, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0", range); 151 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 152 | // @ 发送报文 153 | send(sockfd, buffer, strlen(buffer), 0); 154 | } 155 | 156 | // @ 清除sock所收到相应报文的头部信息 157 | void ClearHead(int sock) 158 | { 159 | char buf[_LINE_MAX]; 160 | int ret = 0; 161 | do 162 | { 163 | bzero(buf, _LINE_MAX); 164 | ret = GetLine(sock, buf, _LINE_MAX); // @ 只是读取,并不做处理 165 | }while(ret > 0 && 0 != strcmp(buf, "\n")); 166 | } 167 | 168 | // @ 从sockfd接收响应报文 169 | int RecvResponseGram(int sockfd) 170 | { 171 | char buf[_LINE_MAX]; 172 | bzero(buf, _LINE_MAX); 173 | int numChars = 0; 174 | int fileSize = 0; 175 | do 176 | { 177 | bzero(buf, _LINE_MAX); 178 | numChars = GetLine(sockfd, buf, _LINE_MAX); 179 | 180 | // @ 匹配到Content-Length: 这一行,拿出长度 181 | if(0 == strncasecmp(buf, "Content-Length: ", strlen("Content-Length: "))) 182 | { 183 | fileSize = atoi(buf+16); 184 | #ifdef __DEBUG__ 185 | cout << "ContentLength : " << fileSize << endl; 186 | #endif 187 | return fileSize; 188 | } 189 | }while(numChars > 0 && strcmp(buf, "\n") != 0); 190 | 191 | cout << "response gram error" << endl; 192 | 193 | exit(1); 194 | } 195 | 196 | // @ 由ip连接上远端服务器 197 | // @ 返回创建的socket文件描述符 198 | int ConnectServer(string & ip) 199 | { 200 | // @ connect to the server 201 | int sockfd = socket(AF_INET, SOCK_STREAM, 0); 202 | if(0 > sockfd) 203 | { 204 | #ifdef __DEBUG__ 205 | cout << "create socket error" << endl; 206 | #endif 207 | } 208 | 209 | struct sockaddr_in serAddr; 210 | serAddr.sin_family = AF_INET; 211 | inet_pton(AF_INET, ip.c_str(), (void *)&(serAddr.sin_addr)); 212 | serAddr.sin_port = htons(DEFAULT_PORT); 213 | 214 | if(-1 == connect(sockfd, (struct sockaddr *)&serAddr, socklen_t(sizeof(serAddr)))) 215 | { 216 | cout << "conncet error :(, please input url again :)" << endl; 217 | exit(1); 218 | } 219 | 220 | return sockfd; 221 | } 222 | 223 | 224 | // @ 下载并显示进度情况 225 | // @ 参数意义:sockfd(连接服务器的文件描述符) 226 | // localfd(要下载的文件对应的本地文件描述符) 227 | // configfd(要下载的配置文件描述符) 228 | // fileLeftSize(要下载的文件剩余大小,开始时是文件总大小) 229 | // offset(要下载的文件偏移,用来实现断点续传) 230 | void DownloadAndDisplay(int sockfd, string fileName, int fileLeftSize, int offset) 231 | { 232 | int localfd = 0; 233 | if((localfd = open(fileName.c_str(), O_WRONLY)) < 0) 234 | { 235 | cout << "open " << fileName << " error" << endl; 236 | exit(1); 237 | } 238 | 239 | // @ 得到配置文件的路径 --> ./ConfFileName.config 240 | char configPath[_FILENAME_MAX]; 241 | bzero(configPath, _FILENAME_MAX); 242 | sprintf(configPath, "./%s.config", fileName.c_str()); 243 | 244 | // @ 打开配置文件 245 | int configfd = 0; 246 | if ((configfd = open(configPath, O_RDWR)) < 0) 247 | { 248 | cout << "open " << configPath << " error" << endl; 249 | exit(1); 250 | } 251 | 252 | // @ 本地文件重定位到offset处 253 | lseek(localfd, offset, SEEK_SET); 254 | 255 | lseek(configfd, 0, SEEK_SET); 256 | 257 | // @ 得到配置文件中offset之前的长度,方便重定位到offset,把文件偏移写到配置文件 258 | int infoLen = 0; 259 | int c = '\0'; 260 | while(read(configfd, &c, 1) == 1) 261 | { 262 | ++infoLen; 263 | if('\n' == c) 264 | break; 265 | } 266 | 267 | char buf[_BUF_SIZE]; // @ 读写网络文件的临时缓冲区 268 | bzero(buf, _LINE_MAX); 269 | char offsetBuf[32]; 270 | bzero(offsetBuf, 32); 271 | 272 | // @ 进度条初始化 273 | char proBar[100]; 274 | char display[256]; 275 | //bzero(proBar, sizeof(proBar)); 276 | memset(proBar, ' ', sizeof(proBar)); 277 | memset(display, ' ', sizeof(display)); 278 | 279 | int hasCompletedPercent = ((float)(offset) / (float)(offset + fileLeftSize)) * 100; // @ 已完成的百分比 280 | float rate = 1.1; // @ 下载速率 281 | int spacing = 2; // @ 时间间隔 282 | 283 | // @ 记录时间 284 | int beginDown = time(NULL); 285 | int beginOnceRecv = beginDown; 286 | int endOnceRecv = 0; 287 | 288 | int rsz = 0; // @ 每次读到的数据个数 289 | int totalRead = offset; // @ 已经读到的总的字节数 290 | 291 | int moveGap = (fileLeftSize + offset) / 100; // @ 总文件的百分之一 292 | 293 | int gap = totalRead % moveGap; // how many characters begin to write to file 294 | 295 | int count = 0; 296 | 297 | // @ 已经达到了多少百分比,就初始化多少进度条 298 | while(hasCompletedPercent--) 299 | proBar[count++] = '*'; 300 | 301 | int myOrder = -1; 302 | pthread_mutex_lock(&curDisplayLock); 303 | myOrder = _CURDISPLAY++; 304 | pthread_mutex_unlock(&curDisplayLock); 305 | 306 | while(fileLeftSize > 0) 307 | { 308 | bzero(buf, _BUF_SIZE); 309 | rsz = recv(sockfd, buf, _BUF_SIZE, 0); 310 | if(rsz < 0 && (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN)) 311 | continue; 312 | 313 | write(localfd, buf, rsz); 314 | gap += rsz; 315 | 316 | totalRead += rsz; 317 | 318 | // @ 记录最近的一次写入信息,如果程序退出,从这个偏移开始下载 319 | bzero(offsetBuf, sizeof(offsetBuf)); 320 | sprintf(offsetBuf, "%d", totalRead); 321 | // @ 文件指针重定位到固定位置去写覆盖offset 322 | lseek(configfd, infoLen, SEEK_SET); 323 | // @ 把文件偏移写到配置文件 324 | write(configfd, offsetBuf, strlen(offsetBuf)); 325 | 326 | // @ 只有在读到了总文件的百分之一,才会去更改状态条 327 | if(gap >= moveGap && count < 100) // @ 每超过 1% 更新显示下载状况 328 | { 329 | endOnceRecv = time(NULL); 330 | spacing = endOnceRecv - beginOnceRecv; 331 | 332 | // @ 防止程序执行过快,导致时间间隔为0,除0会导致段错误 333 | if(0 == spacing) 334 | spacing = 1.2; 335 | 336 | rate = gap / spacing; 337 | beginOnceRecv = endOnceRecv; 338 | 339 | int percent = gap / moveGap; 340 | while(percent--) 341 | proBar[count++] = '*'; 342 | --count; 343 | 344 | //printf("[%-100s] [%d%% %.1fK/s %-ds <%s>\r", proBar, ++count, rate/1024, endOnceRecv - beginDown, fileName.c_str()); 345 | //fflush(stdout); 346 | 347 | sprintf(display, "[%-100s] [%d%% %.1fK/s %-ds <%s>\r", proBar, ++count, rate/1024, endOnceRecv-beginDown, fileName.c_str()); 348 | string downInfo(display); 349 | 350 | pthread_mutex_lock(&curDisplayLock); 351 | dw.put_str_to_win(dw.get_output(), myOrder, 1, downInfo); 352 | pthread_mutex_unlock(&curDisplayLock); 353 | dw.win_refresh(dw.get_output()); 354 | 355 | gap = gap % moveGap; 356 | } /* if(gap >= moveGap && count < 100) */ 357 | 358 | fileLeftSize -= rsz; 359 | } 360 | //cout << endl; 361 | } 362 | 363 | // @ 重新连接服务器并下载文件 364 | // 参数信息:ida(要下载的资源信息,ip、domain、addr) 365 | // offset(要下载的文件偏移量,开始时给0) 366 | void ReConnAndDown(struct IpAndDomainAndAddr & ida, int offset) 367 | { 368 | string ip = ida.m_ip; 369 | string domain = ida.m_domain; 370 | string addr = ida.m_addr; 371 | 372 | int sockfd = ConnectServer(ip); 373 | 374 | // @ 重新发送请求报文 375 | SendRequestGram(sockfd, ida, offset); 376 | 377 | // @ 解析响应报文 378 | int fileLeftSize = RecvResponseGram(sockfd); 379 | #ifdef __DEBUG__ 380 | cout << "in func ReConnServer, fileLeftSize : " << fileLeftSize << endl; 381 | #endif 382 | 383 | ClearHead(sockfd); 384 | 385 | // get local file name used for open it 386 | string fileName = GetFilenameFromAddr(addr); 387 | 388 | // @ 开始下载 389 | DownloadAndDisplay(sockfd, fileName, fileLeftSize, offset); 390 | 391 | //close(localfd); 392 | //close(configfd); 393 | } 394 | 395 | // @ 得到文件的后缀名(包括.号) 396 | // @ 参数意义:str(文件名) 397 | // len(文件名长度) 398 | // suffer(输出型参数,拿出后缀) 399 | bool GetSuffer(const char *str, int len, char *suffer) 400 | { 401 | #ifdef __DEBUG__ 402 | cout << "get in the GetSuffer" << endl; 403 | cout << "str : " << str << endl; 404 | cout << "len : " << len << endl; 405 | #endif 406 | 407 | if(NULL == str || 0 >= len) 408 | return false; 409 | int end = len - 1; 410 | while(end >= 0) 411 | { 412 | if(str[end] == '.') 413 | { 414 | strncpy(suffer, str + end, len - end); 415 | return true; 416 | } 417 | --end; 418 | } 419 | 420 | return false; 421 | } 422 | 423 | // @ 查看当前目录有没有含.config后缀的配置文件 424 | // @ 如果有,打开这个文件,把文件描述符放到fdq队列中,返回真 425 | // @ 如果没有,返回假 426 | bool HasConfigFile(queue & fdq) 427 | { 428 | DIR *dir; 429 | struct dirent *ptr; 430 | int fd = 0; 431 | char fileName[_FILENAME_MAX]; 432 | bzero(fileName, _FILENAME_MAX); 433 | 434 | dir = opendir("./"); 435 | // @ 每次从dir目录读一个文件到ptr中 436 | while((ptr = readdir(dir)) != NULL) 437 | { 438 | bzero(fileName, sizeof(fileName)); 439 | 440 | // @ 从ptr(struct dirent *类型)里取出文件名放到fileName中 441 | sprintf(fileName, "%s", ptr->d_name); 442 | 443 | char suffer[_FILENAME_MAX]; 444 | bzero(suffer, _FILENAME_MAX); 445 | bool ret = GetSuffer(fileName, strlen(fileName), suffer); 446 | if(!ret) 447 | continue; 448 | 449 | if(strncmp(suffer, ".config", strlen(".config")) == 0) 450 | { 451 | int fd = open(fileName, O_RDWR); 452 | assert(fd > 0); 453 | fdq.push(fd); 454 | } 455 | } 456 | 457 | return fdq.size() != 0; 458 | } 459 | 460 | void *ThreadDown(void *arg) 461 | { 462 | if(NULL == arg) 463 | { 464 | cout << "empty url..." << endl; 465 | pthread_exit(NULL); 466 | } 467 | 468 | string s = *(string *)arg; 469 | 470 | struct IpAndDomainAndAddr ida; 471 | string ip, addr, domain; 472 | 473 | char infoBreak[_BREAK_MAX]; 474 | bzero(infoBreak, _BREAK_MAX); 475 | 476 | ida = AnalyseUrl(*(string*)arg); 477 | string fileName = GetFilenameFromAddr(ida.m_addr); 478 | 479 | #ifdef __DEBUG__ 480 | cout << "ip : " << ida.m_ip << endl; 481 | cout << "domain : " << ida.m_domain << endl; 482 | cout << "addr : " << ida.m_addr << endl; 483 | #endif 484 | 485 | // @ config file 486 | char configPath[_FILENAME_MAX]; 487 | bzero(configPath, _FILENAME_MAX); 488 | sprintf(configPath, "./%s.config", fileName.c_str()); 489 | // @ 记录断点信息 490 | sprintf(infoBreak, "%s %s %s\n", ida.m_ip.c_str(), ida.m_domain.c_str(), ida.m_addr.c_str()); 491 | 492 | // @ 创建配置文件 493 | creat(configPath, S_IWUSR | S_IRUSR); 494 | int configfd = open(configPath, O_RDWR); 495 | int infoLen = strlen(infoBreak); // @ 断点信息长度,方便文件指针越过断点信息一行 重定位到offset处 496 | write(configfd, infoBreak, infoLen); // @ ip domain addr \n offset 497 | 498 | ip = ida.m_ip; 499 | domain = ida.m_domain; 500 | addr = ida.m_addr; 501 | 502 | // @ 连接服务器 503 | int sockfd = ConnectServer(ip); 504 | 505 | // @ 发送请求报文 506 | SendRequestGram(sockfd, ida, 0); 507 | 508 | // @ 解析响应报文 509 | int fileSize = RecvResponseGram(sockfd); 510 | 511 | if(fileSize == 0) 512 | { 513 | #ifdef __DEBUG__ 514 | cout << "nothing to story, input again :)" << endl; 515 | #endif 516 | exit(1); 517 | } 518 | 519 | // @ 忽略其他头部信息,定位到相应消息体 520 | ClearHead(sockfd); 521 | 522 | char localPath[_FILENAME_MAX]; 523 | bzero(localPath, _FILENAME_MAX); 524 | sprintf(localPath, "./%s", fileName.c_str()); 525 | 526 | // @ 创建一个和要下载的文件同名的本地文件 527 | creat(localPath, S_IWUSR | S_IRUSR); 528 | //int localfd = open(localPath, O_RDWR); 529 | 530 | // @ 开始下载任务 531 | DownloadAndDisplay(sockfd, fileName, fileSize, 0); 532 | 533 | remove(configPath); 534 | 535 | return NULL; 536 | } 537 | 538 | void BreakPointDown(queue & fdq) 539 | { 540 | while(!fdq.empty()) 541 | { 542 | int configfd = fdq.front(); 543 | fdq.pop(); 544 | 545 | string ip = ""; 546 | string domain = ""; 547 | string addr = ""; 548 | string offset = ""; 549 | char c = '\0'; 550 | int i = 0; 551 | 552 | // @ 从配置文件取出ip,重新连接服务器需要用到 553 | while(read(configfd, &c, 1) == 1) 554 | { 555 | if(' ' == c) 556 | break; 557 | ip += c; 558 | } 559 | 560 | // @ 从配置文件取出域名,在请求报文头部中Host:字段用到 561 | while(read(configfd, &c, 1) == 1) 562 | { 563 | if(' ' == c) 564 | break; 565 | domain += c; 566 | } 567 | 568 | // @ 从配置文件取出addr,因为需要打开本地下载文件,就需要知道文件名 569 | while(read(configfd, &c, 1) == 1) 570 | { 571 | if('\n' == c) 572 | break; 573 | addr += c; 574 | } 575 | 576 | // @ 从配置文件取出offset,在断点续传中Range:字段用到 577 | // exit loop when EOF 578 | while(read(configfd, &c, 1) == 1) 579 | { 580 | offset += c; 581 | } 582 | 583 | struct IpAndDomainAndAddr ida; 584 | ida.m_ip = ip; 585 | ida.m_domain = domain; 586 | ida.m_addr = addr; 587 | 588 | // @ 重新连接并且从上次离开处下载文件 589 | ReConnAndDown(ida, atoi(offset.c_str())); 590 | 591 | string confAddr = ida.m_addr + ".config"; 592 | string confName = GetFilenameFromAddr(confAddr); 593 | 594 | // @ 删除配置文件(下载完成以后,配置文件一定要删掉) 595 | remove(confName.c_str()); 596 | } 597 | } 598 | 599 | void *ThreadDisplayHeader(void *arg) 600 | { 601 | string display = "Welcome to Thunder"; 602 | int x = 0, y; 603 | 604 | while(1) 605 | { 606 | int max_y, screen, max_x; 607 | getmaxyx(dw.get_header(), max_y, screen); 608 | max_x = screen - display.size(); 609 | y = max_y/2-1; 610 | dw.clear_win_line(dw.get_header(), y, 1); 611 | dw.put_str_to_win(dw.get_header(), y, ++x%max_x, display); 612 | dw.win_refresh(dw.get_header()); 613 | usleep(100000); 614 | } 615 | 616 | return NULL; 617 | } 618 | 619 | -------------------------------------------------------------------------------- /DownloadTool/download/download.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#ifndef __DOWNLOAD_H__ 4 | //#define __DOWNLOAD_H__ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "../window/window.h" 29 | #include "../pool/threadpool.h" 30 | 31 | using namespace std; 32 | 33 | //#define __DEBUG__ 34 | #define DEFAULT_PORT 80 35 | const int _BUF_SIZE = 40960; 36 | const int _LINE_MAX = 4096; 37 | const int _REQUEST_MAX = 1024; 38 | const int _DOMAIN_MAX = 64; 39 | const int _BREAK_MAX = 256; 40 | const int _FILENAME_MAX = 64; 41 | const int _ADDR_MAX = 256; 42 | const int _RANGE_MAX = 64; 43 | 44 | 45 | //////////////////////////////////////////////////////////////////// 46 | struct Download 47 | { 48 | int m_fdCli; 49 | string m_url; 50 | }; 51 | 52 | struct IpAndDomainAndAddr 53 | { 54 | string m_ip; 55 | string m_domain; 56 | string m_addr; 57 | }; 58 | 59 | struct NameAndFd 60 | { 61 | string m_name; 62 | int m_fd; 63 | }; 64 | 65 | //////////////////////////////////////////////////////////////////// 66 | void usage(); 67 | 68 | int GetLine(int sock, char *buf, int buf_len); 69 | string GetFilenameFromAddr(string reqAddr); 70 | IpAndDomainAndAddr AnalyseUrl(string & url); 71 | void SendRequestGram(int sockfd, struct IpAndDomainAndAddr &info, int offset); 72 | void ClearHead(int sock); 73 | int RecvResponseGram(int sockfd); 74 | int ConnectServer(string & ip); 75 | void DownloadAndDisplay(int sockfd, string fileName, int fileLeftSize, int offset); 76 | void ReConnAndDown(struct IpAndDomainAndAddr & ida, int offset); 77 | bool GetSuffer(const char *str, int len, char *suffer); 78 | bool HasConfigFile(queue & fdq); 79 | void *ThreadDown(void *arg); 80 | void BreakPointDown(queue & fdq); 81 | void *ThreadDisplayHeader(void *arg); 82 | 83 | -------------------------------------------------------------------------------- /DownloadTool/download/mythunder.cpp: -------------------------------------------------------------------------------- 1 | #include "download.h" 2 | 3 | extern Threadpool tp; 4 | extern DownWindow dw; 5 | 6 | // @ 下载文件,默认端口号 80 7 | int main(int argc, char *argv[]) 8 | { 9 | if(1 != argc) 10 | { 11 | usage(); 12 | exit(1); 13 | } 14 | 15 | // @ 窗口初始化 16 | dw.init(); 17 | 18 | dw.draw_header(); 19 | dw.win_refresh(dw.get_header()); 20 | 21 | dw.draw_input(); 22 | dw.win_refresh(dw.get_input()); 23 | 24 | dw.draw_output(); 25 | dw.win_refresh(dw.get_output()); 26 | 27 | // @ 刚进入程序,首先看有没有配置文件 28 | queue fdq; 29 | bool hasconfig = HasConfigFile(fdq); 30 | 31 | // @ 创建一个线程用来刷新头部窗口 32 | pthread_t headTid; 33 | pthread_create(&headTid, NULL, ThreadDisplayHeader, NULL); 34 | // @ 有配置文件,开始断点续传 35 | if(hasconfig) 36 | BreakPointDown(fdq); 37 | 38 | ///////////////////////////////////////////////////////////////////////////////////////////////////// 39 | 40 | // @ 下面开始正常下载一个文件 41 | char *buf[128]; 42 | bzero(buf, sizeof(buf)); 43 | 44 | // @ 存储客户端的地址 45 | struct sockaddr_in client; 46 | socklen_t len = 0; 47 | string url; 48 | pthread_t tid; 49 | 50 | while(1) 51 | { 52 | // @ 初始化输入栏的提醒 53 | string input = "input url > "; 54 | dw.put_str_to_win(dw.get_input(), 1, 1, input); 55 | dw.win_refresh(dw.get_input()); 56 | 57 | dw.get_str_from_win(dw.get_input(), url); 58 | dw.clear_win_line(dw.get_input(), 1, 12); 59 | dw.win_refresh(dw.get_input()); 60 | 61 | #ifdef __DEBUG__ 62 | cout << "url : " << url << endl; 63 | #endif 64 | // url = "http://www.baidu.com/"; 65 | // http://sw.bos.baidu.com/sw-search-sp/software/84b5fcf50a3de/QQ_8.7.19083.0_setup.exe 66 | 67 | string *url_arg = new string(url); 68 | //pthread_create(&tid, NULL, ThreadDown, (void*)url_arg); 69 | tp.AddWorkToWorkQueue(ThreadDown, (void*)url_arg); 70 | 71 | } /* while(1) */ 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /DownloadTool/mythunder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/DownloadTool/mythunder -------------------------------------------------------------------------------- /DownloadTool/pool/Makefile: -------------------------------------------------------------------------------- 1 | test:Main.cpp threadpool.cpp 2 | g++ -o $@ $^ -lpthread -g 3 | 4 | .PHONY:clean 5 | clean: 6 | rm -rf test 7 | -------------------------------------------------------------------------------- /DownloadTool/pool/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#define __THREADPOOL__ 4 | 5 | 6 | // @ 配置线程池的线程个数 7 | const size_t CORE_NUM_OF_COMPUTER = 10; 8 | -------------------------------------------------------------------------------- /DownloadTool/pool/threadpool.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "threadpool.h" 3 | 4 | Threadpool::Threadpool(size_t threadNum /* = CORE_NUM_OF_COMPUTER */) 5 | :_taskQueue() 6 | ,_destroy(true) 7 | { 8 | pthread_mutex_init(&_taskQueueLock, NULL); // @ 初始化互斥锁 9 | pthread_cond_init(&_taskAvailable, NULL); // @ 初始化条件变量 10 | 11 | _threadId.reserve(threadNum); 12 | _threadId.insert(_threadId.begin(), threadNum, 0); // @ 初始化线程id 13 | 14 | for(int i = 0; i < threadNum; ++i) // @ 创建线程 15 | { 16 | pthread_create(&(this->_threadId[i]), NULL, ThreadRoutine, (void *)this); 17 | //usleep(500); 18 | } 19 | } 20 | 21 | Threadpool::~Threadpool() 22 | { 23 | _destroy = false; 24 | 25 | pthread_cond_broadcast(&_taskAvailable); // @ 唤醒所有等待线程,线程池要销毁了 26 | 27 | int maxNum = _threadId.size(); 28 | for(int i = 0; i < maxNum; ++i) // @ 等待所有线程退出,防止出现僵尸 29 | { 30 | pthread_join(_threadId[i], NULL); 31 | } 32 | 33 | // @ 销毁锁和条件变量 34 | pthread_mutex_destroy(&_taskQueueLock); 35 | pthread_cond_destroy(&_taskAvailable); 36 | } 37 | 38 | void Threadpool::AddWorkToWorkQueue(void *(*process) (void *arg), void *arg) 39 | { 40 | Task *tk = new Task(process, arg); // @ 构造一个任务 41 | 42 | pthread_mutex_lock(&_taskQueueLock); 43 | 44 | _taskQueue.push(tk); // @ 添加任务到任务队列中 45 | 46 | pthread_mutex_unlock(&_taskQueueLock); 47 | 48 | pthread_cond_signal(&_taskAvailable); // 唤醒一个线程 49 | // @ 如果没有线程阻塞在cond上,说明线程池所有线程都忙碌,这时候要往线程池中添加线程应该怎么添加??? 50 | } 51 | 52 | void *Threadpool::ThreadRoutine(void *arg) 53 | { 54 | #ifdef __THREADPOOL__ 55 | cout<<"starting thread 0x"<_taskQueueLock)); 64 | 65 | // @ 任务队列为空,线程阻塞 66 | while(tp->_destroy && tp->_taskQueue.size() == 0) 67 | { 68 | #ifdef __THREADPOOL__ 69 | cout<<"thread 0x"<_taskAvailable), &(tp->_taskQueueLock)); 72 | } 73 | 74 | if(tp->_destroy) 75 | { 76 | Task *tk = tp->_taskQueue.front(); // @ 线程取出一个任务去执行 77 | tp->_taskQueue.pop(); 78 | 79 | pthread_mutex_unlock(&(tp->_taskQueueLock)); 80 | 81 | (*(tk->_process)) (tk->_arg); 82 | 83 | delete tk; // @ 任务执行完后,销毁掉 84 | } 85 | else // @ 86 | { 87 | pthread_mutex_unlock(&(tp->_taskQueueLock)); 88 | #ifdef __THREADPOOL__ 89 | cout<<"thread 0x"< 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "config.h" 13 | 14 | using namespace std; 15 | 16 | 17 | 18 | // * 任务结构 19 | class Task 20 | { 21 | public: 22 | typedef void *(*pFun) (void *arg); 23 | 24 | Task(pFun process = NULL, void *arg = NULL) 25 | :_process(process) 26 | ,_arg(arg) 27 | {} 28 | 29 | 30 | pFun _process; // @ 该任务需要运行的函数 31 | void *_arg; // @ 该函数的参数 32 | }; 33 | 34 | class Threadpool 35 | { 36 | public: 37 | Threadpool(size_t threadNum = CORE_NUM_OF_COMPUTER); 38 | ~Threadpool(); 39 | void AddWorkToWorkQueue(void *(*process) (void *arg), void *arg); 40 | 41 | protected: 42 | static void *ThreadRoutine(void *arg); 43 | 44 | protected: 45 | vector _threadId; // @ 线程id向量 46 | queue _taskQueue; // @ 存放任务的队列 47 | pthread_mutex_t _taskQueueLock; // @ 往任务队列中添加或删除任务时,需要先加锁 48 | pthread_cond_t _taskAvailable; // @ 任务队列中有任务,需要唤醒一个线程 49 | bool _destroy; // @ 是否销毁线程池, ThreadRoutine要用到 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /DownloadTool/tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.9~svn20110310 // 7 | Add Test/1/header.cpp /^int Add(int x, int y)$/;" f 8 | AddWorkToWorkQueue pool/threadpool.cpp /^void Threadpool::AddWorkToWorkQueue(void *(*process) (void *arg), void *arg)$/;" f class:Threadpool 9 | AnalyseUrl download/download.cpp /^IpAndDomainAndAddr AnalyseUrl(string & url)$/;" f 10 | BreakPointDown download/download.cpp /^void BreakPointDown(queue & fdq)$/;" f 11 | CC Makefile /^CC=g++$/;" m 12 | CORE_NUM_OF_COMPUTER pool/config.h /^const size_t CORE_NUM_OF_COMPUTER = 10;$/;" v 13 | ClearHead download/download.cpp /^void ClearHead(int sock)$/;" f 14 | ConnectServer download/download.cpp /^int ConnectServer(string & ip)$/;" f 15 | DEFAULT_PORT download/download.h 34;" d 16 | DLT_BIN Makefile /^DLT_BIN=mythunder$/;" m 17 | DLT_SRC Makefile /^DLT_SRC= download\/mythunder.cpp download\/download.cpp window\/window.cpp pool\/threadpool.cpp$/;" m 18 | DownWindow window/window.cpp /^DownWindow::DownWindow()$/;" f class:DownWindow 19 | DownWindow window/window.h /^class DownWindow$/;" c 20 | Download download/download.h /^struct Download$/;" s 21 | DownloadAndDisplay download/download.cpp /^void DownloadAndDisplay(int sockfd, string fileName, int fileLeftSize, int offset)$/;" f 22 | G_BLOCK_SIZE window/window.h /^const int G_BLOCK_SIZE = 256;$/;" v 23 | GetFilenameFromAddr download/download.cpp /^string GetFilenameFromAddr(string reqAddr)$/;" f 24 | GetLine download/download.cpp /^int GetLine(int sock, char *buf, int buf_len)$/;" f 25 | GetSuffer download/download.cpp /^bool GetSuffer(const char *str, int len, char *suffer)$/;" f 26 | HasConfigFile download/download.cpp /^bool HasConfigFile(queue & fdq)$/;" f 27 | IpAndDomainAndAddr download/download.h /^struct IpAndDomainAndAddr$/;" s 28 | NameAndFd download/download.h /^struct NameAndFd$/;" s 29 | ReConnAndDown download/download.cpp /^void ReConnAndDown(struct IpAndDomainAndAddr & ida, int offset)$/;" f 30 | RecvResponseGram download/download.cpp /^int RecvResponseGram(int sockfd)$/;" f 31 | SendRequestGram download/download.cpp /^void SendRequestGram(int sockfd, struct IpAndDomainAndAddr &info, int offset)$/;" f 32 | Task pool/threadpool.h /^ Task(pFun process = NULL, void *arg = NULL)$/;" f class:Task 33 | Task pool/threadpool.h /^class Task$/;" c 34 | ThreadDisplayHeader download/download.cpp /^void *ThreadDisplayHeader(void *arg)$/;" f 35 | ThreadDown download/download.cpp /^void *ThreadDown(void *arg)$/;" f 36 | ThreadRoutine pool/threadpool.cpp /^void *Threadpool::ThreadRoutine(void *arg)$/;" f class:Threadpool 37 | Threadpool pool/threadpool.cpp /^Threadpool::Threadpool(size_t threadNum \/* = CORE_NUM_OF_COMPUTER *\/)$/;" f class:Threadpool 38 | Threadpool pool/threadpool.h /^class Threadpool$/;" c 39 | _ADDR_MAX download/download.h /^const int _ADDR_MAX = 256; $/;" v 40 | _BREAK_MAX download/download.h /^const int _BREAK_MAX = 256; $/;" v 41 | _BUF_SIZE download/download.h /^const int _BUF_SIZE = 40960;$/;" v 42 | _CURDISPLAY download/download.cpp /^int _CURDISPLAY = 1;$/;" v 43 | _DOMAIN_MAX download/download.h /^const int _DOMAIN_MAX = 64;$/;" v 44 | _FILENAME_MAX download/download.h /^const int _FILENAME_MAX = 64;$/;" v 45 | _LINE_MAX download/download.h /^const int _LINE_MAX = 4096;$/;" v 46 | _RANGE_MAX download/download.h /^const int _RANGE_MAX = 64;$/;" v 47 | _REQUEST_MAX download/download.h /^const int _REQUEST_MAX = 1024;$/;" v 48 | _arg pool/threadpool.h /^ void *_arg; \/\/ @ 该函数的参数$/;" m class:Task 49 | _destroy pool/threadpool.h /^ bool _destroy; \/\/ @ 是否销毁线程池, ThreadRoutine要用到$/;" m class:Threadpool 50 | _process pool/threadpool.h /^ pFun _process; \/\/ @ 该任务需要运行的函数$/;" m class:Task 51 | _taskAvailable pool/threadpool.h /^ pthread_cond_t _taskAvailable; \/\/ @ 任务队列中有任务,需要唤醒一个线程$/;" m class:Threadpool 52 | _taskQueue pool/threadpool.h /^ queue _taskQueue; \/\/ @ 存放任务的队列$/;" m class:Threadpool 53 | _taskQueueLock pool/threadpool.h /^ pthread_mutex_t _taskQueueLock; \/\/ @ 往任务队列中添加或删除任务时,需要先加锁$/;" m class:Threadpool 54 | _threadId pool/threadpool.h /^ vector _threadId; \/\/ @ 线程id向量$/;" m class:Threadpool 55 | clear_win_line window/window.cpp /^void DownWindow::clear_win_line(WINDOW* _win, int begin, int num)$/;" f class:DownWindow 56 | create_win window/window.cpp /^WINDOW* DownWindow::create_win(const int& hei,const int& wth, const int& y, const int& x)$/;" f class:DownWindow 57 | curDisplayLock download/download.cpp /^pthread_mutex_t curDisplayLock = PTHREAD_MUTEX_INITIALIZER;$/;" v 58 | draw_header window/window.cpp /^void DownWindow::draw_header()$/;" f class:DownWindow 59 | draw_input window/window.cpp /^void DownWindow::draw_input()$/;" f class:DownWindow 60 | draw_output window/window.cpp /^void DownWindow::draw_output()$/;" f class:DownWindow 61 | dw download/download.cpp /^DownWindow dw;$/;" v 62 | get_header window/window.h /^ WINDOW* get_header()$/;" f class:DownWindow 63 | get_input window/window.h /^ WINDOW* get_input()$/;" f class:DownWindow 64 | get_output window/window.h /^ WINDOW* get_output()$/;" f class:DownWindow 65 | get_str_from_win window/window.cpp /^void DownWindow::get_str_from_win(WINDOW* _win, string& _out)$/;" f class:DownWindow 66 | h1 Test/1/header.cpp /^int h1 = 1;$/;" v 67 | h2 Test/1/header.cpp /^int h2 = 2;$/;" v 68 | header window/window.h /^ WINDOW* header;$/;" m class:DownWindow 69 | init window/window.cpp /^void DownWindow::init()$/;" f class:DownWindow 70 | input window/window.h /^ WINDOW* input;$/;" m class:DownWindow 71 | lock window/window.h /^ pthread_mutex_t lock;$/;" m class:DownWindow 72 | m_addr download/download.h /^ string m_addr;$/;" m struct:IpAndDomainAndAddr 73 | m_domain download/download.h /^ string m_domain;$/;" m struct:IpAndDomainAndAddr 74 | m_fd download/download.h /^ int m_fd;$/;" m struct:NameAndFd 75 | m_fdCli download/download.h /^ int m_fdCli;$/;" m struct:Download 76 | m_ip download/download.h /^ string m_ip;$/;" m struct:IpAndDomainAndAddr 77 | m_name download/download.h /^ string m_name;$/;" m struct:NameAndFd 78 | m_url download/download.h /^ string m_url;$/;" m struct:Download 79 | main Test/1/test.cpp /^int main()$/;" f 80 | main Test/a.c /^int main()$/;" f 81 | main download/mythunder.cpp /^int main(int argc, char *argv[])$/;" f 82 | mutex Test/1/header.cpp /^pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;$/;" v 83 | output window/window.h /^ WINDOW* output;$/;" m class:DownWindow 84 | outputLock window/window.h /^ pthread_mutex_t outputLock;$/;" m class:DownWindow 85 | pFun pool/threadpool.h /^ typedef void *(*pFun) (void *arg);$/;" t class:Task 86 | put_str_to_win window/window.cpp /^void DownWindow::put_str_to_win(WINDOW* _win, int y, int x, const string& _str)$/;" f class:DownWindow 87 | std Test/a.c /^using namespace std;$/;" v 88 | tp download/download.cpp /^Threadpool tp;$/;" v 89 | usage download/download.cpp /^void usage() { cout << ".\/downloadtool" << endl; }$/;" f 90 | win_refresh window/window.cpp /^void DownWindow::win_refresh(WINDOW* _win)$/;" f class:DownWindow 91 | ~DownWindow window/window.cpp /^DownWindow::~DownWindow()$/;" f class:DownWindow 92 | ~Threadpool pool/threadpool.cpp /^Threadpool::~Threadpool()$/;" f class:Threadpool 93 | -------------------------------------------------------------------------------- /DownloadTool/window/window.cpp: -------------------------------------------------------------------------------- 1 | #include "window.h" 2 | #include 3 | 4 | /* 5 | * 窗口的构造函数 6 | * 初始化下载窗口类的部分成员 7 | * */ 8 | DownWindow::DownWindow() 9 | { 10 | header = NULL; 11 | input = NULL; 12 | output = NULL; 13 | } 14 | 15 | /* 16 | * 窗口的初始化 17 | * */ 18 | void DownWindow::init() 19 | { 20 | pthread_mutex_init(&lock, NULL); 21 | //pthread_mutex_init(&outputLock, NULL); 22 | 23 | setlocale(LC_ALL, ""); 24 | 25 | initscr(); 26 | } 27 | 28 | /* 29 | * 清除指定窗口的一行信息 30 | * */ 31 | void DownWindow::clear_win_line(WINDOW* _win, int begin, int num) 32 | { 33 | while(num-- > 0) 34 | { 35 | wmove(_win, begin++, 0); 36 | wclrtoeol(_win); 37 | } 38 | } 39 | 40 | /* 41 | * 创建一个窗口,在(y, x)位置开始,创建一个长wth,高hei的窗口 42 | * */ 43 | WINDOW* DownWindow::create_win(const int& hei,const int& wth, const int& y, const int& x) 44 | { 45 | WINDOW* _win = newwin(hei, wth, y, x); 46 | 47 | return _win; 48 | } 49 | 50 | /* 51 | * 刷新指定窗口 52 | * */ 53 | void DownWindow::win_refresh(WINDOW* _win) 54 | { 55 | box(_win, 0, 0); 56 | pthread_mutex_lock(&lock); 57 | wrefresh(_win); 58 | pthread_mutex_unlock(&lock); 59 | } 60 | 61 | /* 62 | * 画出头部窗口 63 | * */ 64 | void DownWindow::draw_header() 65 | { 66 | int hei = LINES*3/10; 67 | int wth = COLS; 68 | int y = 0; 69 | int x = 0; 70 | 71 | this->header = create_win(hei, wth, y,x); 72 | } 73 | 74 | /* 75 | * 画出输入窗口 76 | * */ 77 | void DownWindow::draw_input() 78 | { 79 | int hei = LINES*1/10; 80 | int wth = COLS; 81 | int y = (LINES*3/10) + 1; 82 | int x = 0; 83 | 84 | this->input = create_win(hei, wth, y, x); 85 | } 86 | 87 | /* 88 | * 画出输出窗口 89 | * */ 90 | void DownWindow::draw_output() 91 | { 92 | int hei = LINES*6/10; 93 | int wth = COLS; 94 | int y = (LINES*4/10) + 1; 95 | int x = 0; 96 | 97 | this->output = create_win(hei, wth, y, x); 98 | } 99 | 100 | /* 101 | * 往指定窗口的(y, x)处打印字符串_str 102 | * */ 103 | void DownWindow::put_str_to_win(WINDOW* _win, int y, int x, const string& _str) 104 | { 105 | //pthread_mutex_lock(&outputLock); 106 | mvwaddstr(_win, y, x, _str.c_str()); 107 | //pthread_mutex_unlock(&outputLock); 108 | } 109 | 110 | /* 111 | * 从指定窗口获取信息保存到_out中 112 | * */ 113 | void DownWindow::get_str_from_win(WINDOW* _win, string& _out) 114 | { 115 | char buf[G_BLOCK_SIZE]; 116 | memset(buf, '\0', sizeof(buf)); 117 | 118 | wgetnstr(_win, buf, sizeof(buf)); 119 | _out = buf; 120 | } 121 | 122 | /* 123 | * 窗口析构 124 | * */ 125 | DownWindow::~DownWindow() 126 | { 127 | pthread_mutex_destroy(&lock); 128 | //pthread_mutex_destroy(&outputLock); 129 | delwin(this->header); 130 | delwin(this->input); 131 | delwin(this->output); 132 | endwin(); 133 | } 134 | 135 | -------------------------------------------------------------------------------- /DownloadTool/window/window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | const int G_BLOCK_SIZE = 256; 11 | 12 | class DownWindow 13 | { 14 | public: 15 | DownWindow(); 16 | ~DownWindow(); 17 | void init(); 18 | WINDOW* create_win(const int& hei,const int& wth, const int& y, const int& x); 19 | 20 | void win_refresh(WINDOW* _win); 21 | void put_str_to_win(WINDOW* _win, int y, int x, const string& _str); 22 | void get_str_from_win(WINDOW* _win, string& _out); 23 | 24 | void clear_win_line(WINDOW* _win, int begin, int num); 25 | 26 | void draw_header(); 27 | void draw_input(); 28 | void draw_output(); 29 | 30 | WINDOW* get_header() 31 | { 32 | return this->header; 33 | } 34 | 35 | WINDOW* get_input() 36 | { 37 | return this->input; 38 | } 39 | 40 | WINDOW* get_output() 41 | { 42 | return this->output; 43 | } 44 | 45 | private: 46 | WINDOW* header; // @ 头部窗口的句柄 47 | WINDOW* input; // @ 输入窗口的句柄 48 | WINDOW* output; // @ 输出窗口的句柄 49 | pthread_mutex_t lock; // @ 刷新窗口时需要互斥访问窗口句柄 50 | }; 51 | -------------------------------------------------------------------------------- /FileCompress/FileCompress.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: FileCompress.hpp 3 | > Author: common 4 | > Mail: 1335289877@qq.com 5 | > Created Time: Чт. 26 мая 2016 23:53:40 6 | ************************************************************************/ 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "Huffman.hpp" 22 | #include "config.hpp" 23 | 24 | using namespace std; 25 | 26 | typedef long LongType; 27 | 28 | struct CharInfo 29 | { 30 | CharInfo(LongType count = 0) 31 | :_count(count) 32 | {} 33 | 34 | CharInfo(unsigned char ch, LongType count = 0) 35 | :_ch(ch) 36 | ,_count(count) 37 | {} 38 | 39 | bool operator<(CharInfo &rhs) 40 | { 41 | return _count < rhs._count; 42 | } 43 | 44 | CharInfo operator+(CharInfo &rhs) 45 | { 46 | return CharInfo(_count + rhs._count); 47 | } 48 | 49 | unsigned char _ch; // * 对应的字符 50 | LongType _count; // * 该字符出现的次数 51 | string _code; // * 该字符的Huffman编码 52 | }; 53 | 54 | 55 | class FileCompress 56 | { 57 | public: 58 | FileCompress() 59 | {} 60 | 61 | public: 62 | void Compress(const char *filename) 63 | { 64 | 65 | #ifdef __TIME__ 66 | clock_t start, finish; 67 | double duration; 68 | start = clock(); 69 | #endif /* __TIME__ */ 70 | 71 | //打开要压缩的文件 72 | FILE *fp_in = NULL; 73 | if((fp_in = fopen(filename, "r")) == NULL) 74 | perr_exit("open fp_in"); 75 | 76 | //读文件,统计字符信息(字符及其出现次数) 77 | char ch = '\0'; 78 | int rsz = 0; 79 | while((rsz = fread(&ch, 1, 1, fp_in))) //sz == 0 --> EOF 80 | { 81 | unsigned int index = (unsigned char)ch; 82 | _infos[index]._ch = ch; 83 | ++_infos[index]._count; 84 | 85 | } /* while */ //统计完成 86 | 87 | //根据统计信息_infos[256],生成 HuffmanTree 88 | HuffmanTree huffman(_infos, 256); //数组,数组长度 89 | 90 | #ifdef __DEBUG__ 91 | 92 | #ifdef __PRINT__ 93 | Print(huffman.GetRoot()); 94 | #endif /* __PRINT__ */ 95 | 96 | #endif /* __DEBUG__ */ 97 | 98 | //生成 HuffmanCode 99 | string code = ""; 100 | GeneralHuffmanCode(huffman.GetRoot(), code); 101 | 102 | int wsz = 0; //每次写入压缩文件时的返回值 -> 1 Byte 103 | int pos = 7; //如果编码中有1,每次需要左移的位数 104 | unsigned char buf = 0; //临时空间,只占一个字节,用来写入压缩文件 105 | ch = 0; //从待压缩文件读一个字节到ch中 106 | 107 | //建立新的文件,用来存放压缩内容 108 | FILE* fp_out = fopen(COMPRESS_FILE_NAME, "w+"); 109 | if(fp_out < 0) 110 | perr_exit("creat_open fp_out"); 111 | 112 | //真正的压缩从这里开始 113 | //读文件,对每一个字符定位到infos[],取到code,到8位,写到输出文件 114 | fseek(fp_in, 0, SEEK_SET); 115 | while((rsz = fread(&ch, 1, 1, fp_in))) //sz == 0 --> EOF 116 | { 117 | unsigned int index = (unsigned char)ch; 118 | 119 | string code = _infos[index]._code; //取到这个字符的哈夫曼编码 120 | const char *str = code.c_str(); 121 | 122 | for(; *str != '\0'; --pos, ++str) //依次查看这个编码中不为0的位 123 | { 124 | //如果不够一个字节,不能往文件中写,而是写道一个buf中,buf写满,才会往文件写 125 | if(pos < 0) //够八位,写到文件 126 | { 127 | if((wsz = fwrite(&buf, 1, 1, fp_out)) < 0) 128 | perr_exit("write fp_out"); 129 | 130 | pos = 7; //开始写下一个字节 131 | buf = 0; 132 | } if(*str == '0') //如果这个位为0,什么都不做,再读下一位 133 | continue; 134 | buf |= 0x1< 解压缩文件(与原文件相同) 181 | void UnCompress(const char *filename) 182 | { 183 | 184 | #ifdef __TIME__ 185 | clock_t start, finish; 186 | double duration; 187 | start = clock(); 188 | #endif /* __TIME__ */ 189 | 190 | //配置文件中记录的字符及其对应的个数,解压缩时构建哈夫曼树 191 | //creat(UNCOMPRESS_FILE_NAME,S_IRUSR | S_IWUSR); 192 | FILE* fp_un = fopen(filename, "w+"); // * 解压缩文件描述符 193 | if(fp_un == NULL) 194 | perr_exit("creat_open fp_un"); 195 | FILE* fp_com = fopen(COMPRESS_FILE_NAME, "r"); // * 压缩文件描述符 196 | FILE* fp_conf = fopen(CONF_NAME, "r"); // * 配置文件描述符 197 | 198 | char buf_line[2+MAX_DIG_OF_COUNT]; 199 | bzero(buf_line, sizeof(buf_line)); 200 | int count = 0; 201 | unsigned char ch = '\0'; 202 | Heap* > hp; 203 | while(ReadLine(fp_conf, buf_line)) //每次从配置文件读一行 204 | { 205 | if(strlen(buf_line) == 1) // * 说明只读到一个'\n' 206 | { 207 | bzero(buf_line, sizeof(buf_line)); 208 | ReadLine(fp_conf, buf_line); // * 接着拿到'\n'出现的次数 209 | count = atoi(buf_line+1); 210 | ch = '\n'; 211 | } 212 | else // * 正常地从配置文件中读到一个字符及其出现的次数 213 | { 214 | ch = buf_line[0]; 215 | count = atoi(buf_line+2); 216 | } 217 | bzero(buf_line, sizeof(buf_line)); 218 | hp.Push(new HuffmanTreeNode(CharInfo(ch, count))); // * 新建一个树节点,放到一个堆中(小堆) 219 | } 220 | 221 | HuffmanTree hft(hp); // ****** 由堆中的记录信息构建一个哈夫曼树 222 | 223 | ch = '\0'; 224 | int sz = 0; 225 | int pos = 7; 226 | int direction = 0; 227 | HuffmanTreeNode *cur = hft.GetRoot(); 228 | 229 | LongType totalChar = cur->_weight._count; // ****** 哈夫曼树的根节点存放的数据就是所有字符出现的总数,可以据此为解压缩的终止条件 230 | 231 | #ifdef __DEBUG__ 232 | cout<<"总共处理了 "<= 0) 241 | { 242 | direction = ch & (0x1 << pos); // * direction的0/1值是指导cur往左还是往右走的方向 243 | pos--; // * 下次取ch的下一个 1,就要少左移一位 244 | if(direction == 0) 245 | cur = cur->_left; 246 | else 247 | cur = cur->_right; 248 | 249 | if(cur && NULL == cur->_left && NULL == cur->_right) // ****** 找到一个叶子节点,说明之前读到的几个位是一个字符的哈夫曼编码, 写入解压缩文件中,并且cur再次从根节点开始往下走 250 | { 251 | fwrite(&cur->_weight._ch, 1, 1, fp_un); //得到某个字符,写入文件 252 | cur = hft.GetRoot(); 253 | if(--totalChar == 0) // ****** 哈夫曼的根节点记录了所有字符出现的总字节数,若写完了,就返回 254 | goto RET; 255 | } 256 | } 257 | } 258 | 259 | RET: 260 | fflush(fp_un); 261 | fclose(fp_conf); 262 | fclose(fp_un); 263 | fclose(fp_com); 264 | 265 | #ifdef __TIME__ 266 | finish = clock(); 267 | duration = (double)(finish-start); 268 | cout<<"UnCompress used "< 0); 298 | 299 | return false; 300 | } 301 | 302 | 303 | void GeneralHuffmanCode(HuffmanTreeNode *root, string code) 304 | { 305 | if(root == NULL) 306 | return; 307 | 308 | if(root->_left) 309 | GeneralHuffmanCode(root->_left, code+"0"); 310 | 311 | if(root->_right) 312 | GeneralHuffmanCode(root->_right, code+"1"); 313 | 314 | if(root->_left == NULL && root->_right == NULL) //PreOrder 315 | _infos[root->_weight._ch]._code = code; //Huffman Code还是记录到_infos里面,Huffman Tree只是充当一个找到编码(路径)和这个叶子节点在_infos的下标 316 | } 317 | 318 | 319 | protected: 320 | CharInfo _infos[256]; 321 | }; 322 | -------------------------------------------------------------------------------- /FileCompress/Heap.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Heap.hpp 3 | > Author: common 4 | > Mail: 1335289877@qq.com 5 | > Created Time: Чт. 26 мая 2016 12:13:33 6 | ************************************************************************/ 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | template //T --> HTNode 15 | class Heap //小堆 16 | { 17 | public: 18 | Heap() 19 | {} 20 | 21 | Heap(T *array, int len) //array element type --> HTNode * 22 | { 23 | _array.reserve(len); 24 | 25 | for(int i = 0; i < len; ++i) 26 | _array.push_back(array[i]); 27 | 28 | //建堆 29 | for(int root = _array.size()/2 - 1; root >= 0; --root) 30 | AdjustDown(root); 31 | } 32 | 33 | void AdjustDown(int root) 34 | { 35 | int parent = root; 36 | int child = 2*parent + 1; 37 | 38 | int len = _array.size(); 39 | while(child < len) 40 | { 41 | if(child+1 < len && ((_array[child+1]->_weight) < (_array[child]->_weight))) 42 | ++child; 43 | 44 | if((_array[child]->_weight) < (_array[parent]->_weight)) 45 | { 46 | swap(_array[parent], _array[child]); 47 | 48 | parent = child; 49 | child = 2*parent + 1; 50 | } 51 | else 52 | break; 53 | } 54 | } 55 | 56 | bool Empty() 57 | { 58 | return _array.size() == 0; 59 | } 60 | 61 | int Size() 62 | { 63 | return _array.size(); 64 | } 65 | 66 | void Push(const T& val) 67 | { 68 | _array.push_back(val); 69 | 70 | //AdjustUp 71 | int child = _array.size() - 1; 72 | int parent = (child-1) / 2; 73 | while(child > 0) 74 | { 75 | if((_array[child]->_weight) < (_array[parent]->_weight)) 76 | { 77 | swap(_array[parent], _array[child]); 78 | } 79 | child = parent; 80 | parent = (child-1) / 2; 81 | } 82 | } 83 | 84 | void Pop() 85 | { 86 | swap(_array[0], _array[_array.size()-1]); 87 | _array.pop_back(); 88 | AdjustDown(0); 89 | } 90 | 91 | T Top() 92 | { 93 | assert(_array.size()); 94 | return _array[0]; 95 | } 96 | 97 | 98 | protected: 99 | vector _array; 100 | }; 101 | -------------------------------------------------------------------------------- /FileCompress/Huffman.hpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Huffman.hpp 3 | > Author: common 4 | > Mail: 1335289877@qq.com 5 | > Created Time: Чт. 26 мая 2016 19:25:02 6 | ************************************************************************/ 7 | #pragma once 8 | 9 | #include 10 | #include "Heap.hpp" 11 | using namespace std; 12 | 13 | template // T --> CharInfo 14 | struct HuffmanTreeNode 15 | { 16 | HuffmanTreeNode(T weight = 0, struct HuffmanTreeNode *left = NULL, struct HuffmanTreeNode *right = NULL) 17 | :_weight(weight), 18 | _left(left), 19 | _right(right) 20 | {} 21 | 22 | 23 | T _weight; 24 | struct HuffmanTreeNode *_left; 25 | struct HuffmanTreeNode *_right; 26 | 27 | }; 28 | 29 | template // T --> CharInfo 30 | class HuffmanTree 31 | { 32 | typedef struct HuffmanTreeNode HTNode; 33 | 34 | public: 35 | HuffmanTree(T *arr, int len) 36 | { 37 | Heap hp; 38 | 39 | for(int i = 0; i < len; ++i) 40 | { 41 | if(arr[i]._count == 0) //arr[i]->_weight._ch 该字符没有出现过 42 | continue; 43 | 44 | hp.Push(new HTNode(arr[i])); //创建一个新的树节点,插入到堆中 45 | } 46 | 47 | _root = CreateTree(hp); 48 | } 49 | 50 | HuffmanTree(Heap &hp) 51 | { 52 | _root = CreateTree(hp); 53 | } 54 | 55 | HTNode* CreateTree(Heap &hp) 56 | { 57 | while(hp.Size() > 1) // * 当最后只有一个数字或者没有数字时,退出 58 | { 59 | HTNode *pmin1 = hp.Top(); //最小值1 60 | hp.Pop(); 61 | HTNode *pmin2 = hp.Top(); //最小值2 62 | hp.Pop(); 63 | 64 | T tmp = (pmin1->_weight) + (pmin2->_weight); 65 | HTNode *parent = new HTNode(tmp, pmin1, pmin2); 66 | 67 | hp.Push(parent); 68 | } 69 | 70 | return hp.Top(); 71 | } 72 | 73 | HTNode* GetRoot() 74 | { 75 | return _root; 76 | } 77 | 78 | protected: 79 | HTNode *_root; 80 | }; 81 | -------------------------------------------------------------------------------- /FileCompress/Makefile: -------------------------------------------------------------------------------- 1 | FileCompress:main.cpp 2 | g++ main.cpp -o FileCompress -g 3 | 4 | .PHONY:clean 5 | clean: 6 | rm -rf FileCompress compressFile compress.conf uncompressFile 7 | -------------------------------------------------------------------------------- /FileCompress/config.hpp: -------------------------------------------------------------------------------- 1 | /********************************************************************************************* 2 | > File Name: config.hpp 3 | > Author: common 4 | > Mail: yp_abc2015@163.com 5 | > Created Time: 2016-06-04 Сб. 23:31:02 6 | > Explanation : 7 | ********************************************************************************************/ 8 | #pragma once 9 | 10 | #include 11 | 12 | #include "FileCompress.hpp" 13 | #include "Huffman.hpp" 14 | using namespace std; 15 | 16 | #define __DEBUG__ 17 | //#define __PRINT__ 18 | #define __TIME__ 19 | 20 | const unsigned int MAX_DIG_OF_COUNT = 10; 21 | const char *FILE_NAME = "file"; 22 | const char *COMPRESS_FILE_NAME = "compressFile"; 23 | const char *CONF_NAME = "compress.conf"; 24 | const char *UNCOMPRESS_FILE_NAME = "uncompressFile"; 25 | 26 | void perr_exit(const char *str) 27 | { 28 | perror("str"); 29 | exit(1); 30 | } 31 | 32 | #ifdef __DEBUG__ 33 | template 34 | void Print(HuffmanTreeNode *root) 35 | { 36 | cout<<"文件中出现的所有字符的次数"<* > q; 39 | q.push(root); 40 | while(!q.empty()) 41 | { 42 | HuffmanTreeNode *tmp = q.front(); 43 | q.pop(); 44 | cout<_weight._ch<<':'; 45 | cout<_weight._count<_left) 47 | q.push(tmp->_left); 48 | if(tmp->_right) 49 | q.push(tmp->_right); 50 | } 51 | 52 | cout< File Name: Main.cpp 3 | > Author: common 4 | > Mail: 1335289877@qq.com 5 | > Created Time: Чт. 26 мая 2016 12:56:43 6 | ************************************************************************/ 7 | 8 | #include 9 | #include "FileCompress.hpp" 10 | #include "config.hpp" 11 | 12 | using namespace std; 13 | 14 | 15 | void TestCompress() 16 | { 17 | FileCompress fc; 18 | fc.Compress(FILE_NAME); 19 | } 20 | 21 | void TestUnCompress() 22 | { 23 | FileCompress fc; 24 | fc.UnCompress(UNCOMPRESS_FILE_NAME); 25 | } 26 | 27 | 28 | int main() 29 | { 30 | TestCompress(); 31 | 32 | TestUnCompress(); 33 | 34 | return 0; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /FileCompress/tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.9~svn20110310 // 7 | AdjustDown Heap.hpp /^ void AdjustDown(int root)$/;" f class:Heap 8 | COMPRESS_FILE_NAME config.hpp /^const char *COMPRESS_FILE_NAME = "compressFile";$/;" v 9 | CONF_NAME config.hpp /^const char *CONF_NAME = "compress.conf";$/;" v 10 | CharInfo FileCompress.hpp /^ CharInfo(LongType count = 0)$/;" f struct:CharInfo 11 | CharInfo FileCompress.hpp /^ CharInfo(unsigned char ch, LongType count = 0)$/;" f struct:CharInfo 12 | CharInfo FileCompress.hpp /^struct CharInfo$/;" s 13 | Compress FileCompress.hpp /^ void Compress(const char *filename)$/;" f class:FileCompress 14 | CreateTree Huffman.hpp /^ HTNode* CreateTree(Heap &hp)$/;" f class:HuffmanTree 15 | Empty Heap.hpp /^ bool Empty()$/;" f class:Heap 16 | FILE_NAME config.hpp /^const char *FILE_NAME = "file";$/;" v 17 | FileCompress FileCompress.hpp /^ FileCompress()$/;" f class:FileCompress 18 | FileCompress FileCompress.hpp /^class FileCompress$/;" c 19 | GeneralHuffmanCode FileCompress.hpp /^ void GeneralHuffmanCode(HuffmanTreeNode *root, string code)$/;" f class:FileCompress 20 | GetRoot Huffman.hpp /^ HTNode* GetRoot()$/;" f class:HuffmanTree 21 | HTNode Huffman.hpp /^ typedef struct HuffmanTreeNode HTNode;$/;" t class:HuffmanTree typeref:struct:HuffmanTree::HuffmanTreeNode 22 | Heap Heap.hpp /^ Heap()$/;" f class:Heap 23 | Heap Heap.hpp /^ Heap(T *array, int len) \/\/array element type --> HTNode *$/;" f class:Heap 24 | Heap Heap.hpp /^class Heap \/\/小堆$/;" c 25 | HuffmanTree Huffman.hpp /^ HuffmanTree(Heap &hp)$/;" f class:HuffmanTree 26 | HuffmanTree Huffman.hpp /^ HuffmanTree(T *arr, int len)$/;" f class:HuffmanTree 27 | HuffmanTree Huffman.hpp /^class HuffmanTree$/;" c 28 | HuffmanTreeNode Huffman.hpp /^ HuffmanTreeNode(T weight = 0, struct HuffmanTreeNode *left = NULL, struct HuffmanTreeNode *right = NULL)$/;" f struct:HuffmanTreeNode 29 | HuffmanTreeNode Huffman.hpp /^struct HuffmanTreeNode$/;" s 30 | LongType FileCompress.hpp /^typedef long LongType;$/;" t 31 | MAX_DIG_OF_COUNT config.hpp /^const unsigned int MAX_DIG_OF_COUNT = 10;$/;" v 32 | Pop Heap.hpp /^ void Pop()$/;" f class:Heap 33 | Print config.hpp /^void Print(HuffmanTreeNode *root)$/;" f 34 | Push Heap.hpp /^ void Push(const T& val)$/;" f class:Heap 35 | ReadLine FileCompress.hpp /^ bool ReadLine(FILE *fp, char *buf_line)$/;" f class:FileCompress 36 | Size Heap.hpp /^ int Size()$/;" f class:Heap 37 | TestCompress main.cpp /^void TestCompress()$/;" f 38 | TestUnCompress main.cpp /^void TestUnCompress()$/;" f 39 | Top Heap.hpp /^ T Top()$/;" f class:Heap 40 | UNCOMPRESS_FILE_NAME config.hpp /^const char *UNCOMPRESS_FILE_NAME = "uncompressFile";$/;" v 41 | UnCompress FileCompress.hpp /^ void UnCompress(const char *filename)$/;" f class:FileCompress 42 | __DEBUG__ config.hpp 16;" d 43 | __TIME__ config.hpp 18;" d 44 | _array Heap.hpp /^ vector _array;$/;" m class:Heap 45 | _ch FileCompress.hpp /^ unsigned char _ch; \/\/ * 对应的字符$/;" m struct:CharInfo 46 | _code FileCompress.hpp /^ string _code; \/\/ * 该字符的Huffman编码$/;" m struct:CharInfo 47 | _count FileCompress.hpp /^ LongType _count; \/\/ * 该字符出现的次数$/;" m struct:CharInfo 48 | _infos FileCompress.hpp /^ CharInfo _infos[256];$/;" m class:FileCompress 49 | _left Huffman.hpp /^ struct HuffmanTreeNode *_left;$/;" m struct:HuffmanTreeNode typeref:struct:HuffmanTreeNode::HuffmanTreeNode 50 | _right Huffman.hpp /^ struct HuffmanTreeNode *_right;$/;" m struct:HuffmanTreeNode typeref:struct:HuffmanTreeNode::HuffmanTreeNode 51 | _root Huffman.hpp /^ HTNode *_root;$/;" m class:HuffmanTree 52 | _weight Huffman.hpp /^ T _weight;$/;" m struct:HuffmanTreeNode 53 | main main.cpp /^int main()$/;" f 54 | operator + FileCompress.hpp /^ CharInfo operator+(CharInfo &rhs)$/;" f struct:CharInfo 55 | operator < FileCompress.hpp /^ bool operator<(CharInfo &rhs)$/;" f struct:CharInfo 56 | perr_exit config.hpp /^void perr_exit(const char *str)$/;" f 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project 2 | 3 | FileCompress是在Linux中开发的,所以只有一些头文件和源文件,可以把要压缩的文件拷贝至工程根目录下,按照指定的命名格式命名文件, 4 | 运行程序,会在工程根目录下生成压缩文件。 (文件命名格式在 config.hpp中,修改相应的文件名就可以了) 5 | 6 | STL实现平台是Windows下Visual Studio 2015,容器中的STL是开发时的整个工程,可以整体下载下来,在不低于VS2015版本中可直接运行。 7 | 8 | DownloadTool是仿照迅雷实现的一个下载工具,使用ncurses库简单实现了一个界面。使用时,需要make,生成mythunder可执行文件, 9 | 运行该文件,在相应的url输入栏输入要下载资源的链接,在显示窗口可显示各个文件的下载情况,该工具支持断点续传。 10 | -------------------------------------------------------------------------------- /STL/.vs/STL/v14/.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/.vs/STL/v14/.suo -------------------------------------------------------------------------------- /STL/Debug/STL.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/Debug/STL.exe -------------------------------------------------------------------------------- /STL/Debug/STL.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/Debug/STL.ilk -------------------------------------------------------------------------------- /STL/Debug/STL.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/Debug/STL.pdb -------------------------------------------------------------------------------- /STL/STL.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL.sdf -------------------------------------------------------------------------------- /STL/STL.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "STL", "STL\STL.vcxproj", "{8C075BCB-A775-4A7A-802D-C99BB407D599}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Debug|x64.ActiveCfg = Debug|x64 17 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Debug|x64.Build.0 = Debug|x64 18 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Debug|x86.ActiveCfg = Debug|Win32 19 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Debug|x86.Build.0 = Debug|Win32 20 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Release|x64.ActiveCfg = Release|x64 21 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Release|x64.Build.0 = Release|x64 22 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Release|x86.ActiveCfg = Release|Win32 23 | {8C075BCB-A775-4A7A-802D-C99BB407D599}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /STL/STL/Allocate.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Allocate.h -------------------------------------------------------------------------------- /STL/STL/Construct.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Construct.h -------------------------------------------------------------------------------- /STL/STL/Debug/Main.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/Main.obj -------------------------------------------------------------------------------- /STL/STL/Debug/STL.Build.CppClean.log: -------------------------------------------------------------------------------- 1 | e:\vs 有关\projects\stl\stl\debug\vc140.pdb 2 | e:\vs 有关\projects\stl\stl\debug\vc140.idb 3 | e:\vs 有关\projects\stl\debug\stl.ilk 4 | e:\vs 有关\projects\stl\debug\stl.exe 5 | e:\vs 有关\projects\stl\debug\stl.pdb 6 | e:\vs 有关\projects\stl\stl\debug\stl.tlog\cl.command.1.tlog 7 | e:\vs 有关\projects\stl\stl\debug\stl.tlog\cl.read.1.tlog 8 | e:\vs 有关\projects\stl\stl\debug\stl.tlog\cl.write.1.tlog 9 | e:\vs 有关\projects\stl\stl\debug\stl.tlog\link.command.1.tlog 10 | e:\vs 有关\projects\stl\stl\debug\stl.tlog\link.read.1.tlog 11 | e:\vs 有关\projects\stl\stl\debug\stl.tlog\link.write.1.tlog 12 | -------------------------------------------------------------------------------- /STL/STL/Debug/STL.log: -------------------------------------------------------------------------------- 1 |  Main.cpp 2 | STL.vcxproj -> E:\VS 有关\Projects\STL\Debug\STL.exe 3 | -------------------------------------------------------------------------------- /STL/STL/Debug/STL.tlog/CL.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/STL.tlog/CL.command.1.tlog -------------------------------------------------------------------------------- /STL/STL/Debug/STL.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/STL.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /STL/STL/Debug/STL.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/STL.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /STL/STL/Debug/STL.tlog/STL.lastbuildstate: -------------------------------------------------------------------------------- 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v140:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit 2 | Debug|Win32|E:\VS 有关\Projects\STL\| 3 | -------------------------------------------------------------------------------- /STL/STL/Debug/STL.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/STL.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /STL/STL/Debug/STL.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/STL.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /STL/STL/Debug/STL.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/STL.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /STL/STL/Debug/main.obj.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/main.obj.enc -------------------------------------------------------------------------------- /STL/STL/Debug/vc140.idb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/vc140.idb -------------------------------------------------------------------------------- /STL/STL/Debug/vc140.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Debug/vc140.pdb -------------------------------------------------------------------------------- /STL/STL/Iterator.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Iterator.h -------------------------------------------------------------------------------- /STL/STL/List.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/List.h -------------------------------------------------------------------------------- /STL/STL/Main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Main.cpp -------------------------------------------------------------------------------- /STL/STL/STL.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {8C075BCB-A775-4A7A-802D-C99BB407D599} 23 | STL 24 | 8.1 25 | 26 | 27 | 28 | Application 29 | true 30 | v140 31 | MultiByte 32 | 33 | 34 | Application 35 | false 36 | v140 37 | true 38 | MultiByte 39 | 40 | 41 | Application 42 | true 43 | v140 44 | MultiByte 45 | 46 | 47 | Application 48 | false 49 | v140 50 | true 51 | MultiByte 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | Level3 75 | Disabled 76 | true 77 | _SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 78 | 79 | 80 | true 81 | 82 | 83 | 84 | 85 | Level3 86 | Disabled 87 | true 88 | 89 | 90 | true 91 | 92 | 93 | 94 | 95 | Level3 96 | MaxSpeed 97 | true 98 | true 99 | true 100 | 101 | 102 | true 103 | true 104 | true 105 | 106 | 107 | 108 | 109 | Level3 110 | MaxSpeed 111 | true 112 | true 113 | true 114 | 115 | 116 | true 117 | true 118 | true 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /STL/STL/STL.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 41 | 42 | 源文件 43 | 44 | 45 | -------------------------------------------------------------------------------- /STL/STL/STL.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /STL/STL/TypeTraits.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/TypeTraits.h -------------------------------------------------------------------------------- /STL/STL/Uninitialized.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Uninitialized.h -------------------------------------------------------------------------------- /STL/STL/Vector.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Muyip/Project/aebca6fab066a3cdb55c97544ef44644cdb22ebd/STL/STL/Vector.h --------------------------------------------------------------------------------