1 module dco.checkInfo; 2 3 import std.file; 4 import std..string; 5 import std.process; 6 import std.stdio; 7 import std.datetime; 8 import std.exception; 9 10 import dco.readConfigs; 11 import dco.globalInfo; 12 import dco.operateFile; 13 14 15 bool checkArgs(string[] args) 16 { 17 string c; 18 size_t p; 19 bool bDFile =false; 20 readConfig(".\\dco.ini"); 21 foreach(int i,arg;args) 22 { 23 if(i == 0) continue; 24 c = toLower(arg); 25 p = c.indexOf('-'); 26 if(p == -1 || c.indexOf(".d") != -1) 27 { 28 if(c.indexOf("of") != -1) 29 { 30 bAssignTarget = true; 31 strTargetName = c[(c.indexOf("of")+1)..$]; 32 } 33 else 34 { 35 if(strTargetName == "") 36 { 37 strTargetName = c[0..$-1].idup; 38 } 39 } 40 strDFile ~= " "; 41 strDFile ~= c; 42 bDFile = true; 43 } 44 else 45 { 46 c = c[p+1 .. $]; 47 } 48 49 if(c == "h" || c == "help")//toLower(args[1]) 50 { 51 bHelp = true; 52 } 53 else if(c == "version") 54 { 55 bVersion = true; 56 } 57 else if(c == "force") 58 { 59 bForce = true; 60 } 61 else if(strPackageName !="") 62 { 63 if(c == strPackageName || c == strPackageName ~ "lib") 64 { 65 bAssignTarget = true; 66 bBuildSpecialLib = true; 67 strTargetTypeSwitch = " -" ~ targetTypeDefault; 68 strTargetName = c ~ ".lib"; 69 } 70 } 71 else if(c == "ini" || c == "init") 72 { 73 bInitINI = true; 74 } 75 } 76 return bDFile; 77 } 78 79 bool CheckBinFolderAndCopy() 80 { 81 if(checkIsUpToDate()) 82 { 83 writeln(strTargetName ~ " file is up to date."); 84 return false; 85 } 86 return true; 87 } 88 89 bool checkIsUpToDate() 90 { 91 getTargetInfo(); 92 if(exists(strTargetFileName)) 93 { 94 targetTime = getTargetTime(strTargetFileName); 95 96 if(strTargetFileName.indexOf("dco.exe") != -1) 97 { 98 if(!checkIsUpToDate(strDCEnvFile ,targetTime)) 99 { 100 auto files = dirEntries(".","dco.{exe,ini}",SpanMode.shallow); 101 foreach(d;files) 102 { 103 string strcopy ="copy " ~ d ~ " " ~ strDCEnv; 104 writeln(strcopy); 105 auto pid = enforce(spawnShell(strcopy.dup()),"spawnShell(strcopy.dup()) is err!"); 106 if (wait(pid) != 0) 107 { 108 writeln("copy failed."); 109 } 110 } 111 //copy(strTargetFileName,strDCEnvFile); 112 } 113 } 114 115 bool bUpToDate = (targetTime >= sourceLastUpdateTime); 116 117 if(!bUpToDate || bForce) 118 { 119 removeExe(strTargetFileName); 120 } 121 return bUpToDate; 122 } 123 124 return false; 125 } 126 127 SysTime getTargetTime(string strPathFile) 128 { 129 return DirEntry(strPathFile).timeLastModified; 130 } 131 132 void removeExe(string strPathExe) 133 { 134 if(!findStr(strPathExe,targetExt)) return; 135 if(exists(strPathExe)) 136 { 137 auto pid = enforce(spawnShell("del " ~ strPathExe.dup()),"del " ~ strPathExe.dup() ~ " Err"); 138 if (wait(pid) != 0) 139 { 140 writeln(strPathExe ~ ", remove failed!"); 141 return; 142 } 143 else 144 { 145 writeln(strPathExe ~ ", remove ok!"); 146 } 147 } 148 } 149 150 bool checkIsUpToDate(string strPathFile,SysTime targettime) 151 { 152 if(!exists(strPathFile)) return false; 153 auto testFile = DirEntry(strPathFile); 154 auto createTime = testFile.timeLastModified; 155 156 return (targettime <= createTime); 157 }