找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19448|回复: 0

windows下的yum

[复制链接]
发表于 2017-4-30 23:05:41 | 显示全部楼层 |阅读模式
本帖最后由 happy886rr 于 2017-4-30 23:11 编辑

windows下的yum诞生了。完全借鉴linux yum的操作体验,大部分用法都进行了兼容移植。强大的缓存机制,一般查询都不需要任何网络。正真将包管理引入windows下,一个包的安装、移除、更新,各种管理机制都做了最大限度的实现。鉴于目前BCN的云目录结构,一些特殊功能,暂时无法对接,不过它已经把yum的体验带到了win下。
YUM.EXE 1.0 (YUM TOOL BY HAPPY)
下载:
图片存为a.zip解压即是。

摘要:
======================================================
YUM.EXE 第三方包管理工具,完全移植LINUX的包管理模式,包括开关、用户体验都做了
极为精细的移植。独创YUM云序列号,每个第三方拥有唯一的云序列YUM-SN, 针对RAR类
型的包,会自动解压安装到YUM.INI配置的本地目录。总之,你把它当做WINDOWS下的YUM
用就对了。

强大的缓存体系,将访问BCN服务器的次数控制到非常苛刻的地步。自带第三方列表,查
询信息都不需要任何网络,后期将推出单机版完全脱网工作。

备注:几乎实现了LINUX下YUM 70%的功能,但是鉴于BCN的目录架构,很多更奇异的功能
暂时不会开放。
======================================================

用法:
-----------------------------------------------------------------------------
yum [option] [package name]...
-----------------------------------------------------------------------------
  -i, install
              Install the package
  -u, update
              Update the package
  -c, clean
              Clean the package cache
  -f, info
              Show the package info
  -s, search
              Search the package
  -l, list
              List the package, type "installed" for installed infomation
  -r, remove
              Remove the package
  -h, help
              Show help information
-----------------------------------------------------------------------------

示例:
-----------------------------------------------------------------------------
yum install sed
yum install sed 4.3
yum install sed*
yum list im*
yum list *ti
yum install 0001
yum remove sed
yum update sed
yum clean sed
yum info s*
yum serach "计算"
...
-----------------------------------------------------------------------------
同时配备了缩写开关
yum -i sed 4.3     ==>   yum install sed 4.3
yum -r sed 4.3     ==>   yum remove  sed 4.3
...
-----------------------------------------------------------------------------
功能强大到无与伦比,比如我要下载msys版sed
yum install sed msys

下载happy版本的choice高仿版
yum install choice happy

移除一个已经安装的sed包
yum remove sed

清除sed包缓存
yum clean sed

列举当前安装的第三方
yum list installed

查看一个包的信息,Cracker这是一个很有名的压缩文件密码破解器。
yum info Cracker

更新astyle包,astyle非常智能的代码格式化工具。
yum update astyle
-----------------------------------------------------------------------------

配置:
-----------------------------------------------------------------------------
关于yum.ini的配置方法

[url ]
;这里是yum的下载源地址,可以是任意的服务器地址,只要搭建了yum源,均可支持yum
yumsurl = http://batch-cn.qiniudn.com/tool/

[dir]
;这里是安装目录,支持环境变量扩展,比如 rootdir = %SystemRoot%\system32\
rootdir = .\
;这里是包缓存目录
cachedir = .\

[setting]
;安装完后是否保留安装包
keepcache = 1

-----------------------------------------------------------------------------


原创代码
  1. /*
  2. THE YUM TOOL, COPYRIGHT@2017~2019 BY HAPPY, VERSION 1.0
  3. YUM.EXE
  4. -----------------------------------------------------------------

  5. _   _       _      _    |  The Batch Online Yum Tool,
  6. \ | |     | \    / |   |  Copyright@2017~2019 By Happy, yum.exe
  7. \ \| |_   _| |\  /| |   |  Type "help" for help informaiton .\n\
  8. \_| | | | | | \/ | |   |
  9.    | | |_| | |\  /| |   |  Version 1.0 (2017-04-30 20:32 UTC)
  10.   _/ |\__'_|_| VV |_|   |  Officil http://www.bathome.net/thread-
  11. |__/                   |  43961-1-1.html

  12. -----------------------------------------------------------------
  13.                          .    .7     .,;;;::
  14.                          v;   7u      ..:;UMBM7::,,,.
  15.                          ;,   ;,    .       .BMsr7r7vL7r,
  16.                          ,    ,    ;0         ER7uuLLJ1SKKU;
  17.    .:xJx;.              .  ;      ;B.         .B7JSSu33FUPGRZL,
  18.        :uDBGs:.       :   .  :.rP..            BRiJaS11UHUHKOOOP;
  19.           :FMBRZJr.   PU.r7,MBMBM0;            uMU:LaaUFHGPHUKEORX:
  20.              7OMBMOPr.M1:MWRBOWMBBBMWi      31  BMx;71PaXKDEEP00WRBP:
  21.                ;3RBOsZX:sBOKUaWBMBBBMBMc,.:aM,  ;BOsrrJPXZEWORDDERRMR3
  22.                  .7rir,EMRDXRR3;rJRBBMBMa::.     xBELrr7UXEGGZDEDDWORMWi
  23.                    :  DMXBMBDu::.,:3OBBBBP:       JBKvrirx1KEWZZZEZKPRRRF:
  24.                   .,.GBuSRiLF3Us:.i:iDBMBMF        LBD7;ric2GDWEZ0EKXXWWRDJ
  25.                   irGBWURS.:1ZPEGc:. :MBMBM;        MBMrii;L2ZDOGZZEKDGWWOW0.
  26.                   :7BRaOBK. .sHPMU  ..aBBMBJ;::7x   .MBKir7:r3KDOEZED0ZZWDOWR:
  27.                   uLSZXBL. ,,i1ZMH ,,.sRRBMa::r7     BRMcii7:ruKDOZEDWEGEGDOGRr
  28.                  ,2EKxB7    , ;EB: .  vPBMBu         MMMJr;ir:iJKWOEDDOEWDGGOEOi
  29.                  JRBMRM      : 3P   ..;HRBBu        iBMB2ii;ii:;LZOOZGDGEODOWD0Dr
  30.                   :0GZu       :;; ..;ir1RMBF.r7    .BBBDBi:;;ii:;vEOWZOGDDOWWZZ0Dr
  31.                       :.      .r.;::.;7URBR0    .rKBMB2LMW::;iii:7JDODGOEWEWWOKE0W:
  32.                        .       . :   ,7PBMWZ;;uOBMBRBZr;cMK:;;;irr11WWODWDWGOOGZGKH
  33.                               .  .  ,:vDMRZMODMBMWMBRL:;:rGS::r277U0SODODWGWDODDE0FO
  34.                               c ..,:LrPMOSKOORBMXKBDLir:::;22:H    LKKWGWGWDOWWEDDPua
  35.                              .xr:::i:cRJsL1R0DMBEPXvir..:,..:7U:    3EZDGODWGOGWEWD7,3
  36.                              G: r   ,JWGxrOMDRRRRDOG1;7SWRBPHMBMBJ; ;KEPOGWDWDDGDZWs ::    7
  37.                             ;B: .   ;MWOaGRRMMGRRROBMBMBMBMBMBBBBBMBPSZPZDDOGOEDDZKU. c  .7B
  38.                            ;MM7 :.;,1; 7RBRORWRRBMRDBBBMMMRZZERMBMBMBUPXGGWGOWDGWPUUR1xJ:,.
  39.                            7MBi::r71r  .7ZOEBORMRMRGMMWBMWSKGRRRMBMBMK1ZZWEDDOZOZXJSMBWa0Xc   U:
  40.                            ;BBc.7r.s:  ;J1MORDMMBM0DBMMMBHEGMMBMBW0OBS1ZEGWEWEDDZHJaBMBMOMBMF:.:
  41.                          rvUMBM7:i:rKcxS1EMMWOWMOPGBMBO1RBMBMBRMMs :.rHGKWGDEDEEXK3URBMBMBMMMB7
  42.                          MMMBOBMOSucZMMORMBWRMWDRRBMO7   RBBBMRRB;   ,ZGZGODDKWPZHF..;c3WBBMMWBWa
  43.                          MMBMBMBMMJv;uMBBBMEDBMRu7Lcr     iRMBRBMB7Z . OKDGOZ0KKKPJ      ;2BMBZB0:
  44.                          MBMBMBE  ,:: .SBMBRMMBMWSL..        OBRBMBM  .OEKDGGPKXXH7        ,WMBO3M
  45.                        .0BMBMW:  :rr.    :OBBBORMBM7         rsOMBMO   :ZEZEKXXKUG,          RMMuBr
  46.                       ;PRBBMD   .i:         :FRMOMBM.        2MMBRO    ;EZDHZHZSHu           cBJRMU
  47.                     7OBBBBMX    i,          L7DBMBMR        :BMBMBZ    ;ZOZ0HXHH2.           ,.rMB;
  48.                   sMBBWHs:     :       ;iLaMH:ZOBMM        ZBMO7,OB    .OOEPHaPS:          . .7BBM
  49.             ,cJ7LXMBMs               ,rZuH3:.rMBB:       7MBBBD  .u    aWOXXSPXL          O. XMBM.
  50.            7BOBM0M2.                       cxOBM     7BMBMBBBJ        .GWZX1KO         ;.,a OMBR
  51.            :  :;,                  i7vSJrFMRMBWX     .L:Far           :OE0UaIF         .X ; OMBs
  52.                                   HMBMBMHMBML                         vEKSaZ;          R  iBBB.
  53.                                   v    Pai.                          .EESSQ          rr uBMr
  54.                                        .                             ;DHDF;           L WBR
  55.                                                                     .SRGA:          ::OBx
  56.                                                                     .;DX.          .WGB;
  57.                                                                     ;DW:          SGB.
  58.                                                                    ;SM           ;XZ;
  59.                                                                    :J            B;
  60.                                                                    :            ;
  61. */
  62. #include   <stdio.h>
  63. #include  <stdlib.h>
  64. #include  <string.h>
  65. #include <windows.h>
  66. #include <wininet.h>
  67. #include <shlwapi.h>
  68. #include<shellapi.h>
  69. #include  <direct.h>
  70. #include   <conio.h>
  71. #include    <time.h>
  72. #include    <math.h>
  73. #include      <io.h>
  74. #pragma comment(lib, "wininet.lib")
  75. #pragma comment(lib, "shlwapi.lib")

  76. /*************宏量定义*************/
  77. #define SAFE_SIZE  512
  78. #define FILE_EXIST 0
  79. #define FILE_EREAD 4

  80. //定义帮助说明
  81. #define HELP_INFORMATION "\
  82. Usage: yum [option] [package name]...\n\
  83. \n\
  84.   -i, install\n\
  85.               Install the package\n\
  86.   -u, update\n\
  87.               Update the package\n\
  88.   -c, clean\n\
  89.               Clean the package cache\n\
  90.   -f, info\n\
  91.               Show the package info\n\
  92.   -s, search\n\
  93.               Search the package\n\
  94.   -l, list\n\
  95.               List the package, type "installed" for installed infomation\n\
  96.   -r, remove\n\
  97.               Remove the package\n\
  98.   -h, help\n\
  99.               Show help information\n\
  100. \n\
  101. Version 1.0 2017-04-30 20:32 UTC\n\
  102. Officil: www.bathome.net/thread-43961-1-1.html\n"

  103. #define SEARCH_HEAD "\
  104. =================================================================\n\
  105. NAME                 VERSION                  YUM-SN        SIZE\n\
  106. ================================================================="

  107. #define SEARCH_LOGO "\
  108. -----------------------------------------------------------------\n\
  109. \n\
  110. _   _       _      _    |  The Batch Online Yum Tool,\n\
  111. \\ | |     | \\    / |   |  Copyright@2017~2019 By Happy, yum.exe\n\
  112. \\ \\| |_   _| |\\  /| |   |  Type "help" for help informaiton .\n\
  113. \\_| | | | | | \\/ | |   |\n\
  114.    | | |_| | |\\  /| |   |  Version 1.0 (2017-04-30 20:32 UTC)\n\
  115.   _/ |\\__'_|_| VV |_|   |  Officil http://www.bathome.net/thread-\n\
  116. |__/                   |  43961-1-1.html\n\
  117. \n\
  118. -----------------------------------------------------------------\n\n"

  119. /*************全局变量*************/
  120. //分配读取配置容器
  121. static char yumsURL[SAFE_SIZE];
  122. static char inifDIR[SAFE_SIZE];
  123. static char rootDIR[SAFE_SIZE];
  124. static char rootENV[SAFE_SIZE];
  125. static char exeFullPath[SAFE_SIZE];
  126. static char keepCACHE[SAFE_SIZE];

  127. //列举正则容器
  128. static char resLIST[SAFE_SIZE];
  129. //第三方下载地址容器
  130. static char yumURL[SAFE_SIZE];
  131. //第三方下载目录容器
  132. static char binPATH[SAFE_SIZE];
  133. //解压工具UNRAR容器
  134. static char unrarPATH[SAFE_SIZE];
  135. static char unrarDURL[SAFE_SIZE];

  136. //搜索关键词
  137. static char keywords[SAFE_SIZE];

  138. //分配缓存区、行容器
  139. static char LCache[SAFE_SIZE*2];

  140. //分配表格容器
  141. static char tmpp[6][SAFE_SIZE];

  142. //Shell命令行容器
  143. static char unrarCMD[SAFE_SIZE];

  144. //进度条变量
  145. static char proGRESS[64]= {0};
  146. clock_t preTime;
  147. ULONG preProgress;

  148. /*************类型定义*************/
  149. typedef HRESULT (WINAPI *PGETA)(LPUNKNOWN,LPCSTR,LPCSTR,DWORD,LPBINDSTATUSCALLBACK);
  150. PGETA PgetUrlToFileA;

  151. /*************功能函数*************/
  152. //判断纯数字
  153. BOOL isPureNumber(const char* nstr)
  154. {
  155.         char* p=(char*)nstr;
  156.         while('0'<=*p && *p<='9')
  157.         {
  158.                 p++;
  159.         }
  160.         return (*p=='\0')?TRUE:FALSE;
  161. }
  162. //子串查找忽略大小写
  163. const char* stristr(const char* str, const char* subStr)
  164. {
  165.         int len = strlen(subStr);
  166.         if(len == 0)
  167.         {
  168.                 return NULL;
  169.         }

  170.         while(*str)
  171.         {
  172.                 if(_strnicmp(str, subStr, len) == 0)
  173.                 {
  174.                         return str;
  175.                 }
  176.                 str++;
  177.         }
  178.         return NULL;
  179. }
  180. //删除目录树
  181. BOOL RemoveDirectoryTreeA(const char* lpszPath)
  182. {
  183.         SHFILEOPSTRUCT FileOp;
  184.         FileOp.fFlags = FOF_SILENT | FOF_NOCONFIRMATION;
  185.         FileOp.hNameMappings = NULL;
  186.         FileOp.hwnd = NULL;
  187.         FileOp.lpszProgressTitle = NULL;
  188.         FileOp.pFrom = lpszPath;
  189.         FileOp.pTo = NULL;
  190.         FileOp.wFunc = FO_DELETE;
  191.         return (SHFileOperationA(&FileOp)==0)?TRUE:FALSE;
  192. }
  193. //遍历目录
  194. void ListInstalledPackage(const char* inpath)
  195. {
  196.         struct _finddata_t data;
  197.         long hnd=_findfirst(inpath, &data);

  198.         if(hnd<0)
  199.         {
  200.                 fprintf(stdout, "Not install any packages");
  201.                 return;
  202.         }

  203.         int nRet=(hnd<0)?-1:1;

  204.         while(nRet>=0)
  205.         {
  206.                 if(data.attrib==_A_SUBDIR && strcmp(data.name, ".")!=0 && strcmp(data.name, "..")!=0)
  207.                 {
  208.                         fprintf(stdout, "Already installed package "%s"\n\n", data.name);
  209.                 }
  210.                 else
  211.                 {
  212.                         char* ep=strrchr(data.name, '.');
  213.                         if(ep!=NULL && stricmp(ep, ".exe")==0)
  214.                         {
  215.                                 *ep='\0';
  216.                                 fprintf(stdout, "Already installed package "%s"\n\n", data.name);
  217.                         }
  218.                 }
  219.                 nRet=_findnext(hnd, &data);
  220.         }
  221.         _findclose(hnd);
  222. }
  223. //进度回调
  224. class DownloadProgress :public IBindStatusCallback
  225. {
  226. public:
  227.         HRESULT __stdcall QueryInterface(const IID &, void **)
  228.         {
  229.                 return E_NOINTERFACE;
  230.         }
  231.         ULONG STDMETHODCALLTYPE AddRef(void)
  232.         {
  233.                 return 1;
  234.         }
  235.         ULONG STDMETHODCALLTYPE Release(void)
  236.         {
  237.                 return 1;
  238.         }
  239.         HRESULT STDMETHODCALLTYPE OnStartBinding(DWORD dwReserved, IBinding *pib)
  240.         {
  241.                 return E_NOTIMPL;
  242.         }
  243.         virtual HRESULT STDMETHODCALLTYPE GetPriority(LONG *pnPriority)
  244.         {
  245.                 return E_NOTIMPL;
  246.         }
  247.         virtual HRESULT STDMETHODCALLTYPE OnLowResource(DWORD reserved)
  248.         {
  249.                 return S_OK;
  250.         }
  251.         virtual HRESULT STDMETHODCALLTYPE OnStopBinding(HRESULT hresult, LPCWSTR szError)
  252.         {
  253.                 return E_NOTIMPL;
  254.         }
  255.         virtual HRESULT STDMETHODCALLTYPE GetBindInfo(DWORD *grfBINDF, BINDINFO *pbindinfo)
  256.         {
  257.                 return E_NOTIMPL;
  258.         }
  259.         virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
  260.         {
  261.                 return E_NOTIMPL;
  262.         }
  263.         virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(REFIID riid, IUnknown *punk)
  264.         {
  265.                 return E_NOTIMPL;
  266.         }
  267.         virtual HRESULT __stdcall OnProgress(ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
  268.         {
  269.                 if (ulProgressMax != 0)
  270.                 {

  271.                         //进度百分数
  272.                         int downloadSpeed, restTime;
  273.                         int i=(int)ulProgress * 100.0 / (int)ulProgressMax;
  274.                         int j=i/2, disTime=(int)(clock()-preTime);
  275.                         if(disTime > 100)
  276.                         {
  277.                                 downloadSpeed=((int)ulProgress-(int)preProgress) * CLOCKS_PER_SEC / disTime / 1000;
  278.                                 restTime=(downloadSpeed!=0) ?((int)ulProgressMax-(int)ulProgress) / downloadSpeed :99999;
  279.                                 preProgress=ulProgress, preTime+=disTime;
  280.                         }
  281.                         else if(i <100)
  282.                         {
  283.                                 return S_OK;
  284.                         }

  285.                         if(i==100)
  286.                         {
  287.                                 downloadSpeed=restTime=0;
  288.                         }

  289.                         for(int n=1; n<=j; n++)
  290.                         {
  291.                                 proGRESS[n]='=';
  292.                         }

  293.                         //显示进度百分比
  294.                         fprintf(stdout, "\r%s%3d%%, %3dKB/s   ", proGRESS, i, downloadSpeed);
  295.                         fflush(stdout);
  296.                 }
  297.                 return S_OK;
  298.         }
  299. };
  300. //搜索函数
  301. int SearchStr(int iargc, char** iargv, char* inifile, int optionSN)
  302. {
  303.         FILE* fp=fopen(inifile, "r");
  304.         if(fp==NULL)
  305.         {
  306.                 fprintf(stdout, "Can not read yum settings.");
  307.                 exit(1);
  308.         }

  309.         BOOL kMARK=FALSE, sMARK=FALSE;
  310.         int mode=0, yumSN=0, kLEN=strlen(iargv[2]), kpmode=atoi(keepCACHE);

  311.         if(iargv[2][0]=='*')
  312.         {
  313.                 //匹配任意位置
  314.                 mode=1;
  315.                 strcpy(keywords, iargv[2]+1);

  316.         }
  317.         else if(iargv[2][kLEN-1]=='*')
  318.         {
  319.                 //匹配首部位置
  320.                 mode=2;
  321.                 strcpy(keywords, iargv[2]);
  322.                 keywords[kLEN-1]='\0';
  323.         }
  324.         else if(isPureNumber(iargv[2]))
  325.         {
  326.                 //匹配YUM-SN
  327.                 mode=3;
  328.                 yumSN=atoi(iargv[2]);
  329.         }
  330.         else
  331.         {
  332.                 //匹配全字
  333.                 mode=0;
  334.                 strcpy(keywords, iargv[2]);
  335.         }

  336.         if(optionSN==2)
  337.         {
  338.                 fprintf(stdout, "%s\n", SEARCH_HEAD);
  339.         }

  340.         int i=0;
  341.         while(!feof(fp))
  342.         {
  343.                 //读入标准行
  344.                 fgets(LCache, SAFE_SIZE*2, fp);

  345.                 //辅助指针
  346.                 char* Line=LCache;

  347.                 while(*Line!='\n' && *Line!='\0')
  348.                 {
  349.                         Line++;
  350.                 }
  351.                 *Line='\0';

  352.                 //指针回首
  353.                 Line=LCache;

  354.                 //过滤行TAB缩进或前空格
  355.                 while(*Line=='\t'|| *Line==' ')
  356.                 {
  357.                         Line++;
  358.                 }

  359.                 if(!kMARK)
  360.                 {
  361.                         if(stristr(Line, "[table]")==Line)
  362.                         {
  363.                                 kMARK=TRUE;
  364.                                 continue;
  365.                         }
  366.                 }

  367.                 if(!kMARK || *Line==';' || *Line=='\0')
  368.                 {
  369.                         continue;
  370.                 }

  371.                 //行计数器
  372.                 i++;

  373.                 //开启search开关
  374.                 if(optionSN==4 && stristr(Line, keywords))
  375.                 {
  376.                         sMARK=TRUE;
  377.                 }

  378.                 char* textstrp=NULL;

  379.                 if(textstrp=strtok(Line, " "))
  380.                 {
  381.                         strcpy(tmpp[0], textstrp);
  382.                 }

  383.                 for(int j=1; j<=5; j++)
  384.                 {
  385.                         if(textstrp=strtok(NULL, " "))
  386.                         {
  387.                                 strcpy(tmpp[j], textstrp);
  388.                         }
  389.                         else
  390.                         {
  391.                                 tmpp[j][0]=0;
  392.                         }
  393.                 }

  394.                 if(
  395.                     (optionSN==4 && sMARK==TRUE)                    ||
  396.                     (mode==0 && stricmp(tmpp[0], keywords)==0)      ||
  397.                     (mode==1 && stristr(tmpp[0], keywords))         ||
  398.                     (mode==2 && stristr(tmpp[0], keywords)==tmpp[0])||
  399.                     (mode==3 && atoi(tmpp[1]+1)==yumSN)
  400.                 )
  401.                 {
  402.                         if(iargc>3 && stristr(tmpp[2], iargv[3])==NULL)
  403.                         {
  404.                                 continue;
  405.                         }

  406.                         //开启list开关
  407.                         if(optionSN==2)
  408.                         {
  409.                                 //打印搜索结果
  410.                                 fprintf(stdout, "%-20.20s %-24.24s %s     %7s\n", tmpp[0], tmpp[2], tmpp[1], tmpp[4]);
  411.                                 continue;
  412.                         }

  413.                         //开启info开关
  414.                         if(optionSN==5||optionSN==4)
  415.                         {
  416.                                 //打印搜索结果
  417.                                 fprintf(stdout, "\nNAME       :%s\nYUMSN      :%s\nVERSION    :%s\nCOMPRESS   :%s\nSIZE       :%s\nDESCRIPTION:%s\n\n", tmpp[0], tmpp[1], tmpp[2], tmpp[3], tmpp[4], tmpp[5]);
  418.                                 sMARK=FALSE;
  419.                                 continue;
  420.                         }

  421.                         if (optionSN==1)
  422.                         {
  423.                                 //进度回调入口
  424.                                 DownloadProgress progress;
  425.                                 IBindStatusCallback* callback=(IBindStatusCallback*)&progress;

  426.                                 //进度归零
  427.                                 memset(proGRESS, ' ', 51);
  428.                                 proGRESS[0]='[', proGRESS[51]=']';

  429.                                 preTime=clock();
  430.                                 preProgress=(ULONG)0;

  431.                                 //判断文件压缩类型
  432.                                 int pressTYPE=atoi(tmpp[3]+1);

  433.                                 strcpy(yumURL, yumsURL);
  434.                                 strcat(yumURL, tmpp[2]);
  435.                                 strcat(yumURL, "/");
  436.                                 strcat(yumURL, tmpp[0]);
  437.                                 if(pressTYPE==0)
  438.                                 {
  439.                                         strcat(yumURL, ".exe");
  440.                                 }
  441.                                 else
  442.                                 {
  443.                                         strcat(yumURL, ".rar");
  444.                                 }

  445.                                 strcpy(binPATH, rootDIR);
  446.                                 strcat(binPATH, tmpp[0]);


  447.                                 if(pressTYPE==0)
  448.                                 {
  449.                                         strcat(binPATH, ".exe");
  450.                                 }
  451.                                 else
  452.                                 {
  453.                                         strcat(binPATH, ".rar");
  454.                                 }

  455.                                 //显示下载信息
  456.                                 fprintf(stdout, "Download package "%s" ...\n", tmpp[0]);

  457.                                 //调用下载函数
  458.                                 if (PgetUrlToFileA(NULL, yumURL, binPATH, 0, static_cast<IBindStatusCallback*>(&progress)) != S_OK)
  459.                                 {
  460.                                         //进度归零
  461.                                         memset(proGRESS, ' ', 51);
  462.                                         proGRESS[0]='[', proGRESS[51]=']';

  463.                                         preTime=clock();
  464.                                         preProgress=(ULONG)0;

  465.                                         strcpy(yumURL, yumsURL);
  466.                                         strcat(yumURL, tmpp[0]);
  467.                                         if(pressTYPE==0)
  468.                                         {
  469.                                                 strcat(yumURL, ".exe");
  470.                                         }
  471.                                         else
  472.                                         {
  473.                                                 strcat(yumURL, ".rar");
  474.                                         }

  475.                                         if (PgetUrlToFileA(NULL, yumURL, binPATH, 0, static_cast<IBindStatusCallback*>(&progress)) != S_OK)
  476.                                         {
  477.                                                 fprintf(stdout, "Download "%s" error.\n\n", tmpp[0]);
  478.                                                 continue;
  479.                                         }

  480.                                 }

  481.                                 fprintf(stdout, "\n");

  482.                                 if(pressTYPE==1)
  483.                                 {

  484.                                         if(unrarPATH[0]=='\0')
  485.                                         {
  486.                                                 strcpy(unrarPATH, rootDIR);
  487.                                                 strcat(unrarPATH, "unrar.exe");
  488.                                         }

  489.                                         if(_access(unrarPATH, FILE_EXIST)!=0)
  490.                                         {
  491.                                                 strcpy(unrarDURL, yumsURL);
  492.                                                 strcat(unrarDURL, "unrar.exe");
  493.                                                 if (PgetUrlToFileA(NULL, unrarDURL, unrarPATH, 0, 0) != S_OK)
  494.                                                 {
  495.                                                         fprintf(stdout, "Can not download the unrar tool, can not extract the package "%s".\n", tmpp[0]);
  496.                                                         exit(1);
  497.                                                 }
  498.                                         }

  499.                                         strcpy(unrarCMD, "x -o+ -y ");
  500.                                         strcat(unrarCMD, binPATH);
  501.                                         strcat(unrarCMD, " ");
  502.                                         strcat(unrarCMD, rootDIR);
  503.                                         fprintf(stdout, "Installation package "%s" ...\n\n", tmpp[0]);
  504.                                         ShellExecuteA(GetConsoleWindow(), "runas", unrarPATH, unrarCMD, "", SW_HIDE);

  505.                                         //删除安装包
  506.                                         if(kpmode==0)
  507.                                         {
  508.                                                 remove(binPATH);
  509.                                         }
  510.                                 }
  511.                                 else
  512.                                 {
  513.                                         fprintf(stdout, "\n");
  514.                                 }

  515.                                 if(mode==0)
  516.                                 {
  517.                                         return 0;
  518.                                 }

  519.                         }
  520.                 }
  521.         }

  522.         fclose(fp);

  523.         return 0;
  524. }

  525. /*************MAIN函数*************/
  526. int main(int argc, char** argv)
  527. {
  528.         if(argc==2)
  529.         {
  530.                 if(stricmp(argv[1], "help")==0 || stricmp(argv[1], "-h")==0)
  531.                 {
  532.                         fprintf(stdout, HELP_INFORMATION);
  533.                         return 0;
  534.                 }
  535.         }

  536.         if(argc<3)
  537.         {
  538.                 //展示LOGO
  539.                 fprintf(stdout, SEARCH_LOGO);
  540.                 //帮助指南
  541.                 fprintf(stdout, "Type "yum help" for help information .\n");
  542.                 return 1;
  543.         }

  544.         //设置开关模式变量
  545.         int optionSN=0;

  546.         if(stricmp(argv[1], "install")==0 || stricmp(argv[1], "update")==0 || stricmp(argv[1], "-i")==0 || stricmp(argv[1], "-u")==0)
  547.         {
  548.                 optionSN=1;
  549.         }
  550.         else if(stricmp(argv[1], "list")==0 || stricmp(argv[1], "-l")==0)
  551.         {
  552.                 optionSN=2;
  553.                 if(stricmp(argv[2], "installed")==0)
  554.                 {
  555.                         optionSN=7;
  556.                 }
  557.         }
  558.         else if(stricmp(argv[1], "remove")==0 || stricmp(argv[1], "-r")==0)
  559.         {
  560.                 optionSN=3;
  561.         }
  562.         else if(stricmp(argv[1], "search")==0 || stricmp(argv[1], "-s")==0)
  563.         {
  564.                 optionSN=4;
  565.         }
  566.         else if(stricmp(argv[1], "info"  )==0 || stricmp(argv[1], "-f")==0)
  567.         {
  568.                 optionSN=5;
  569.         }
  570.         else if(stricmp(argv[1], "clean" )==0 || stricmp(argv[1], "-c")==0)
  571.         {
  572.                 optionSN=6;
  573.         }
  574.         else
  575.         {
  576.                 //展示LOGO
  577.                 fprintf(stdout, SEARCH_LOGO);
  578.                 fprintf(stdout, "Type "yum help" for help information .\n");
  579.                 return 1;
  580.         }

  581.         //装载DLL模块
  582.         HMODULE hLib=LoadLibraryW(L"URLMON");
  583.         if(hLib==NULL)
  584.         {
  585.                 fprintf(stdout, "Load urlmon library error");
  586.                 return 1;
  587.         }

  588.         //过小红伞本地查杀
  589.         PgetUrlToFileA=(PGETA)GetProcAddress(hLib, "URLDownloadToFileA");

  590.         //获取可执行文件所在目录
  591.         GetModuleFileNameA(NULL, exeFullPath, SAFE_SIZE);
  592.         char *p=strrchr(exeFullPath, '\\');
  593.         *(++p)='\0';

  594.         //获取配置文件yum.ini路径
  595.         strcpy(inifDIR, exeFullPath);
  596.         strcat(inifDIR, ".\\yum.ini");

  597.         if(_access(inifDIR, FILE_EREAD)!=0)
  598.         {
  599.                 fprintf(stdout, "Can not read yum ini.\n");
  600.                 return 1;
  601.         }

  602.         //获取配置键值yumsurl
  603.         GetPrivateProfileStringA("url", "yumsurl", "non", yumsURL, SAFE_SIZE, inifDIR);
  604.         if(strcmp(yumsURL, "non")==0)
  605.         {
  606.                 fprintf(stdout, "Needs yum url.\n");
  607.                 return 1;
  608.         }
  609.         else
  610.         {
  611.                 if(strrchr(yumsURL, '/')+1 != '\0')
  612.                 {
  613.                         strcat(yumsURL, "/");
  614.                 }
  615.         }

  616.         //获取配置键值rootdir
  617.         GetPrivateProfileStringA("dir", "rootdir", "non", rootDIR, SAFE_SIZE, inifDIR);
  618.         if(strcmp(rootDIR, "non")==0)
  619.         {
  620.                 strcpy(rootDIR, exeFullPath);
  621.         }
  622.         else
  623.         {
  624.                 ExpandEnvironmentStringsA(rootDIR, rootENV,SAFE_SIZE);
  625.                 if(strchr(rootENV, ':')==NULL)
  626.                 {
  627.                         strcpy(rootDIR, exeFullPath);
  628.                         strcat(rootDIR, rootENV);
  629.                 }
  630.                 else
  631.                 {
  632.                         strcpy(rootDIR, rootENV);
  633.                 }

  634.                 //判断根目录是否存在
  635.                 if(!PathIsDirectory(rootDIR))
  636.                 {
  637.                         fprintf(stdout, "The root directory "%s" does not exist.\n", rootDIR);
  638.                         return 1;
  639.                 }

  640.                 strcat(rootDIR, ".\");
  641.         }

  642.         //获取配置键值keepcache
  643.         GetPrivateProfileStringA("setting", "keepcache", "non", keepCACHE, SAFE_SIZE, inifDIR);
  644.         if(strcmp(keepCACHE, "non")==0)
  645.         {
  646.                 strcpy(keepCACHE, "0");
  647.         }

  648.         //展示LOGO
  649.         if(optionSN!=2)
  650.         {
  651.                 fprintf(stdout, SEARCH_LOGO);
  652.         }

  653.         //删除包命令
  654.         if(optionSN==3)
  655.         {
  656.                 fprintf(stdout, "Remove package "%s" ...\n", argv[2]);

  657.                 BOOL isREMOVE=TRUE;
  658.                 char tmpT[SAFE_SIZE]= {0};

  659.                 strcpy(tmpT, rootDIR);
  660.                 strcat(tmpT, argv[2]);

  661.                 //删除包目录树
  662.                 if(PathIsDirectory(tmpT))
  663.                 {
  664.                         if(!RemoveDirectoryTreeA(tmpT))
  665.                         {
  666.                                 isREMOVE=FALSE;
  667.                         }
  668.                 }

  669.                 strcat(tmpT, ".exe");
  670.                 if(_access(tmpT, FILE_EXIST)==0)
  671.                 {
  672.                         if(remove(tmpT)!=0)
  673.                         {
  674.                                 isREMOVE=FALSE;
  675.                         }
  676.                 }

  677.                 char* tp=strrchr(tmpT, '.');

  678.                 if(isREMOVE)
  679.                 {
  680.                         fprintf(stdout, "The package "%s" has been removed.\n", argv[2]);
  681.                 }
  682.                 else
  683.                 {
  684.                         fprintf(stdout, "The package "%s" remove failed.\n", argv[2]);
  685.                 }

  686.                 return 0;
  687.         }

  688.         if(optionSN==6)
  689.         {
  690.                 fprintf(stdout, "Clean package "%s"'s cache ...\n", argv[2]);

  691.                 char tmpT[SAFE_SIZE]= {0};
  692.                 strcpy(tmpT, rootDIR);
  693.                 strcat(tmpT, argv[2]);
  694.                 strcat(tmpT, ".rar");
  695.                 remove(tmpT);
  696.                 return 0;
  697.         }

  698.         if(optionSN==7)
  699.         {
  700.                 strcpy(resLIST, rootDIR);
  701.                 strcat(resLIST, ".\\*");
  702.                 ListInstalledPackage(resLIST);
  703.                 return 0;
  704.         }

  705.         //调用核心函数
  706.         SearchStr(argc, argv, inifDIR, optionSN);

  707.         return 0;
  708. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 04:50 , Processed in 0.031062 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表