private static JSONArray Cache_Git_Repo(string repo_url) { //EXAMPLE: https://api.github.com/repos/dsisco11/SR_Plugin_Loader/git/trees/master?recursive=1 string url = String.Format("{0}/git/trees/master?recursive=1", repo_url.TrimEnd(new char[] { '\\', '/' })); string jsonStr = null; if (!remote_file_cache.ContainsKey(url)) { // Fetch repo information //jsonStr = webClient.DownloadString(url); jsonStr = GetString(url); if (jsonStr == null || jsonStr.Length <= 0) { return(null); } remote_file_cache.Add(url, ENCODING.GetBytes(jsonStr)); SLog.Debug("Cached repository: {0}", url); } else { jsonStr = ENCODING.GetString(remote_file_cache[url]); } // Parse the json response from GitHub var git = SimpleJSON.JSON.Parse(jsonStr); var tree = git["tree"].AsArray; return(tree); }
/// <summary> /// Converts the part into the byte array to be spent to the service. /// </summary> public byte[] toByteArray() { /* Construct the header. */ StringBuilder header = new StringBuilder(); header.Append("Content-Disposition: form-data; name=\"" + field + '\"'); if (filename != null) { header.Append("; filename=\"" + filename + '\"'); } header.Append("\r\n"); if (type != null) { header.Append("Content-Type: " + type + "\r\n"); } header.Append("\r\n"); /* Assemble the whole part. */ MemoryStream buf = new MemoryStream(); byte[] headerBytes = ENCODING.GetBytes(header.ToString()); buf.Write(headerBytes, 0, headerBytes.Length); buf.Write(content, 0, content.Length); return(buf.ToArray()); }
/// <summary> /// /// </summary> /// <param name="repo_url"></param> /// <returns>JSONArray holding all of the repository master branch entries</returns> private static IEnumerator Cache_Git_Repo_Async(string repo_url) { //EXAMPLE: https://api.github.com/repos/dsisco11/SR_Plugin_Loader/git/trees/master?recursive=1 string ghurl = Extract_Repository_URL_From_Github_URL(repo_url.TrimEnd(new char[] { '\\', '/' })); string url = String.Format("{0}/git/trees/master?recursive=1", ghurl); byte[] buf = null; string jsonStr = null; if (!remote_file_cache.ContainsKey(url)) { // Fetch repo information //jsonStr = webClient.DownloadString(url); IEnumerator iter = GetAsync(url); while (iter.MoveNext()) { yield return(null); } if (iter.Current == null) { yield return(null); yield break; } buf = iter.Current as byte[]; if (buf == null || buf.Length <= 0) { yield return(null); yield break; } jsonStr = ENCODING.GetString(buf); if (jsonStr == null || jsonStr.Length <= 0) { yield return(null); yield break; } //Check again just to make sure, because async methods could screw us up here. if (!remote_file_cache.ContainsKey(url)) { remote_file_cache.Add(url, ENCODING.GetBytes(jsonStr)); } remote_file_cache[url] = ENCODING.GetBytes(jsonStr); SLog.Debug("Cached repository: {0}", repo_url); } else { jsonStr = ENCODING.GetString(remote_file_cache[url]); //PLog.Info("CACHE: {0}", jsonStr); //DebugHud.Log(remote_file_cache.ToLogString()); } // Parse the json response from GitHub var git = SimpleJSON.JSON.Parse(jsonStr); var tree = git["tree"].AsArray; yield return(tree); yield break; }
private void GetCHK(BinaryWriter bw, CHKToken cHKToken, TOKENTYPE tOKENTYPE) { byte[] tokenbyte; if (tOKENTYPE == TOKENTYPE.NULL) { tokenbyte = System.Text.Encoding.ASCII.GetBytes(cHKToken.code.PadRight(4, ' ')); } else { tokenbyte = System.Text.Encoding.ASCII.GetBytes(tOKENTYPE.ToString().PadRight(4, ' ')); } //에디터로부터 CHK데이터를 가져오는 함수 switch (tOKENTYPE) { case TOKENTYPE.NULL: bw.Write(cHKToken.bytes); break; case TOKENTYPE.ENCD: bw.Write(tokenbyte); bw.Write((int)4); bw.Write(ENCODING.CodePage); break; case TOKENTYPE.VER: bw.Write(tokenbyte); bw.Write((int)2); bw.Write(VER); break; case TOKENTYPE.TYPE: bw.Write(tokenbyte); bw.Write((int)4); bw.Write(TYPE); break; case TOKENTYPE.IVE2: bw.Write(tokenbyte); bw.Write((int)2); bw.Write(IVE2); break; case TOKENTYPE.VCOD: bw.Write(tokenbyte); bw.Write(VCOD.Length); bw.Write(VCOD); break; case TOKENTYPE.IOWN: bw.Write(tokenbyte); bw.Write(IOWN.Length); bw.Write(IOWN); break; case TOKENTYPE.OWNR: //TODO:스타트로케이션 확인 후 IOWN수정해야됨. OWNR = (byte[])IOWN.Clone(); bool[] pexist = new bool[8]; for (int i = 0; i < UNIT.Count; i++) { if (UNIT[i].unitID == 214) { pexist[UNIT[i].player] = true; } } for (int i = 0; i < 8; i++) { if (!pexist[i]) { OWNR[i] = 0; } } bw.Write(tokenbyte); bw.Write(OWNR.Length); bw.Write(OWNR); break; case TOKENTYPE.SIDE: bw.Write(tokenbyte); bw.Write(SIDE.Length); bw.Write(SIDE); break; case TOKENTYPE.COLR: bw.Write(tokenbyte); bw.Write(COLR.Length); bw.Write(COLR); break; case TOKENTYPE.CRGB: bw.Write(tokenbyte); bw.Write(32); for (int i = 0; i < 8; i++) { bw.Write(CRGB[i].R); bw.Write(CRGB[i].G); bw.Write(CRGB[i].B); } bw.Write(CRGBIND); break; case TOKENTYPE.UNIT: bw.Write(tokenbyte); bw.Write(UNIT.Count * 36); for (int i = 0; i < UNIT.Count; i++) { bw.Write(UNIT[i].unitclass); bw.Write(UNIT[i].X); bw.Write(UNIT[i].Y); bw.Write(UNIT[i].unitID); bw.Write(UNIT[i].linkFlag); bw.Write(UNIT[i].validstatusFlag); bw.Write(UNIT[i].validunitFlag); bw.Write(UNIT[i].player); bw.Write(UNIT[i].hitPoints); bw.Write(UNIT[i].shieldPoints); bw.Write(UNIT[i].energyPoints); bw.Write(UNIT[i].resoruceAmount); bw.Write(UNIT[i].hangar); bw.Write(UNIT[i].stateFlag); bw.Write(UNIT[i].unused); bw.Write(UNIT[i].linkedUnit); } break; case TOKENTYPE.ERA: bw.Write(tokenbyte); bw.Write((int)2); bw.Write((ushort)TILETYPE); break; case TOKENTYPE.DIM: bw.Write(tokenbyte); bw.Write((int)4); bw.Write((ushort)WIDTH); bw.Write((ushort)HEIGHT); break; case TOKENTYPE.TILE: bw.Write(tokenbyte); bw.Write((int)WIDTH * HEIGHT * 2); for (int i = 0; i < WIDTH * HEIGHT; i++) { bw.Write(TILE[i]); } break; case TOKENTYPE.MTXM: bw.Write(tokenbyte); bw.Write((int)WIDTH * HEIGHT * 2); for (int i = 0; i < WIDTH * HEIGHT; i++) { bw.Write(MTXM[i]); } break; case TOKENTYPE.DD2: bw.Write(tokenbyte); bw.Write((int)DD2.Count * 8); for (int i = 0; i < DD2.Count; i++) { bw.Write(DD2[i].ID); bw.Write(DD2[i].X); bw.Write(DD2[i].Y); bw.Write(DD2[i].PLAYER); bw.Write(DD2[i].FLAG); } break; case TOKENTYPE.THG2: bw.Write(tokenbyte); DDDTHG2.AddRange(THG2); bw.Write((int)DDDTHG2.Count * 10); for (int i = 0; i < DDDTHG2.Count; i++) { bw.Write(DDDTHG2[i].ID); bw.Write(DDDTHG2[i].X); bw.Write(DDDTHG2[i].Y); bw.Write(DDDTHG2[i].PLAYER); bw.Write(DDDTHG2[i].UNUSED); bw.Write(DDDTHG2[i].FLAG); } break; case TOKENTYPE.MASK: bw.Write(tokenbyte); bw.Write((int)MASK.Length); bw.Write(MASK); break; case TOKENTYPE.STRx: bw.Write(tokenbyte); { int strptrlen = stringDatas.Count * 4 + 4; MemoryStream memory = new MemoryStream(); BinaryWriter tbw = new BinaryWriter(memory); uint[] strptr = new uint[stringDatas.Count]; for (int i = 0; i < stringDatas.Count; i++) { byte[] bytes = ENCODING.GetBytes(stringDatas[i].CodeString); strptr[i] = (uint)((uint)tbw.BaseStream.Position + strptrlen); tbw.Write(bytes); tbw.Write((byte)0); } bw.Write((uint)(tbw.BaseStream.Length + strptrlen)); bw.Write((uint)stringDatas.Count); for (int i = 0; i < stringDatas.Count; i++) { bw.Write(strptr[i]); } bw.Write(memory.ToArray()); tbw.Close(); memory.Close(); } //long strptrstart = bw.BaseStream.Position; //bw.Write((uint)0); //long ptrpos = bw.BaseStream.Position; //for (int i = 0; i < stringDatas.Count; i++) //{ // bw.Write((uint)0); //} //long endpos = bw.BaseStream.Position; //bw.BaseStream.Position = strptrstart; //bw.Write((uint)endpos - strptrstart); //for (int i = 0; i < stringDatas.Count; i++) //{ // bw.Write(strptr[i]); //} //bw.BaseStream.Position = endpos; break; case TOKENTYPE.SPRP: bw.Write(tokenbyte); bw.Write((int)4); bw.Write((ushort)SCEARIONAME.ResultIndex); bw.Write((ushort)SCEARIODES.ResultIndex); break; case TOKENTYPE.FORC: bw.Write(tokenbyte); bw.Write((int)20); bw.Write(FORCE); bw.Write((ushort)FORCENAME[0].ResultIndex); bw.Write((ushort)FORCENAME[1].ResultIndex); bw.Write((ushort)FORCENAME[2].ResultIndex); bw.Write((ushort)FORCENAME[3].ResultIndex); bw.Write(FORCEFLAG); break; case TOKENTYPE.MRGN: bw.Write(tokenbyte); bw.Write((int)5100); for (int i = 0; i < 255; i++) { LocationData locationData = LocationDatas.SingleOrDefault(x => x.INDEX == (i + 1)); if (locationData == null) { bw.Write(new byte[20]); } else { bw.Write(locationData.L); bw.Write(locationData.T); bw.Write(locationData.R); bw.Write(locationData.B); bw.Write((ushort)locationData.STRING.ResultIndex); bw.Write(locationData.FLAG); } } break; case TOKENTYPE.UPRP: bw.Write(tokenbyte); bw.Write((int)UPRP.Length * 20); for (int i = 0; i < UPRP.Length; i++) { bw.Write(UPRP[i].STATUSVALID); bw.Write(UPRP[i].POINTVALID); bw.Write(UPRP[i].PLAYER); bw.Write(UPRP[i].HITPOINT); bw.Write(UPRP[i].SHIELDPOINT); bw.Write(UPRP[i].ENERGYPOINT); bw.Write(UPRP[i].RESOURCE); bw.Write(UPRP[i].HANGAR); bw.Write(UPRP[i].STATUSFLAG); bw.Write(UPRP[i].UNUSED); } break; case TOKENTYPE.UPUS: bw.Write(tokenbyte); bw.Write((int)UPUS.Length); bw.Write(UPUS); break; case TOKENTYPE.WAV: bw.Write(tokenbyte); bw.Write((int)WAV.Length * 4); for (int i = 0; i < WAV.Length; i++) { bw.Write(WAV[i].ResultIndex); } break; case TOKENTYPE.SWNM: bw.Write(tokenbyte); bw.Write((int)SWNM.Length * 4); for (int i = 0; i < SWNM.Length; i++) { bw.Write(SWNM[i].ResultIndex); } break; case TOKENTYPE.PUNI: bw.Write(tokenbyte); bw.Write((int)5700); for (int i = 0; i < 12; i++) { bw.Write(PUNI.UNITENABLED[i]); } bw.Write(PUNI.DEFAULT); for (int i = 0; i < 12; i++) { bw.Write(PUNI.USEDEFAULT[i]); } break; case TOKENTYPE.PUPx: bw.Write(tokenbyte); bw.Write((int)2318); for (int i = 0; i < 12; i++) { bw.Write(PUPx.MAXLEVEL[i]); } for (int i = 0; i < 12; i++) { bw.Write(PUPx.STARTLEVEL[i]); } bw.Write(PUPx.DEFAULTMAXLEVEL); bw.Write(PUPx.DEFAULTSTARTLEVEL); for (int i = 0; i < 12; i++) { bw.Write(PUPx.USEDEFAULT[i]); } break; case TOKENTYPE.PTEx: bw.Write(tokenbyte); bw.Write((int)1672); for (int i = 0; i < 12; i++) { bw.Write(PTEx.MAXLEVEL[i]); } for (int i = 0; i < 12; i++) { bw.Write(PTEx.STARTLEVEL[i]); } bw.Write(PTEx.DEFAULTMAXLEVEL); bw.Write(PTEx.DEFAULTSTARTLEVEL); for (int i = 0; i < 12; i++) { bw.Write(PTEx.USEDEFAULT[i]); } break; case TOKENTYPE.UNIx: bw.Write(tokenbyte); bw.Write((int)4168); for (int i = 0; i < 228; i++) { bw.Write(UNIx.USEDEFAULT[i]); } for (int i = 0; i < 228; i++) { bw.Write(UNIx.HIT[i]); } for (int i = 0; i < 228; i++) { bw.Write(UNIx.SHIELD[i]); } for (int i = 0; i < 228; i++) { bw.Write(UNIx.ARMOR[i]); } for (int i = 0; i < 228; i++) { bw.Write(UNIx.BUILDTIME[i]); } for (int i = 0; i < 228; i++) { bw.Write(UNIx.MIN[i]); } for (int i = 0; i < 228; i++) { bw.Write(UNIx.GAS[i]); } for (int i = 0; i < 228; i++) { bw.Write((ushort)UNIx.STRING[i].ResultIndex); } for (int i = 0; i < 130; i++) { bw.Write(UNIx.DMG[i]); } for (int i = 0; i < 130; i++) { bw.Write(UNIx.BONUSDMG[i]); } break; case TOKENTYPE.UPGx: bw.Write(tokenbyte); bw.Write((int)794); for (int i = 0; i < 61; i++) { bw.Write(UPGx.USEDEFAULT[i]); } bw.Write((byte)0); for (int i = 0; i < 61; i++) { bw.Write(UPGx.BASEMIN[i]); } for (int i = 0; i < 61; i++) { bw.Write(UPGx.BONUSMIN[i]); } for (int i = 0; i < 61; i++) { bw.Write(UPGx.BASEGAS[i]); } for (int i = 0; i < 61; i++) { bw.Write(UPGx.BONUSGAS[i]); } for (int i = 0; i < 61; i++) { bw.Write(UPGx.BASETIME[i]); } for (int i = 0; i < 61; i++) { bw.Write(UPGx.BONUSTIME[i]); } break; case TOKENTYPE.TECx: bw.Write(tokenbyte); bw.Write((int)396); for (int i = 0; i < 44; i++) { bw.Write(TECx.USEDEFAULT[i]); } for (int i = 0; i < 44; i++) { bw.Write(TECx.MIN[i]); } for (int i = 0; i < 44; i++) { bw.Write(TECx.GAS[i]); } for (int i = 0; i < 44; i++) { bw.Write(TECx.BASETIME[i]); } for (int i = 0; i < 44; i++) { bw.Write(TECx.ENERGY[i]); } break; case TOKENTYPE.TRIG: bw.Write(tokenbyte); bw.Write((int)2400 * TRIG.Count); for (int i = 0; i < TRIG.Count; i++) { for (int c = 0; c < 16; c++) { bw.Write(TRIG[i].conditions[c].locid); bw.Write(TRIG[i].conditions[c].player); bw.Write(TRIG[i].conditions[c].amount); bw.Write(TRIG[i].conditions[c].unitid); bw.Write(TRIG[i].conditions[c].comparison); bw.Write(TRIG[i].conditions[c].condtype); bw.Write(TRIG[i].conditions[c].restype); bw.Write(TRIG[i].conditions[c].flags); bw.Write(TRIG[i].conditions[c].maskflag); } for (int a = 0; a < 64; a++) { bw.Write(TRIG[i].actions[a].locid1); bw.Write(TRIG[i].actions[a].strid); bw.Write(TRIG[i].actions[a].wavid); bw.Write(TRIG[i].actions[a].time); bw.Write(TRIG[i].actions[a].player1); bw.Write(TRIG[i].actions[a].player2); bw.Write(TRIG[i].actions[a].unitid); bw.Write(TRIG[i].actions[a].acttype); bw.Write(TRIG[i].actions[a].amount); bw.Write(TRIG[i].actions[a].flags); bw.Write(TRIG[i].actions[a].padding); bw.Write(TRIG[i].actions[a].maskflag); } bw.Write(TRIG[i].exeflag); bw.Write(TRIG[i].playerlist); bw.Write(TRIG[i].trigindex); } break; case TOKENTYPE.MBRF: bw.Write(tokenbyte); bw.Write((int)2400 * MBRF.Count); for (int i = 0; i < MBRF.Count; i++) { for (int c = 0; c < 16; c++) { bw.Write(MBRF[i].conditions[c].locid); bw.Write(MBRF[i].conditions[c].player); bw.Write(MBRF[i].conditions[c].amount); bw.Write(MBRF[i].conditions[c].unitid); bw.Write(MBRF[i].conditions[c].comparison); bw.Write(MBRF[i].conditions[c].condtype); bw.Write(MBRF[i].conditions[c].restype); bw.Write(MBRF[i].conditions[c].flags); bw.Write(MBRF[i].conditions[c].maskflag); } for (int a = 0; a < 64; a++) { bw.Write(MBRF[i].actions[a].locid1); bw.Write(MBRF[i].actions[a].strid); bw.Write(MBRF[i].actions[a].wavid); bw.Write(MBRF[i].actions[a].time); bw.Write(MBRF[i].actions[a].player1); bw.Write(MBRF[i].actions[a].player2); bw.Write(MBRF[i].actions[a].unitid); bw.Write(MBRF[i].actions[a].acttype); bw.Write(MBRF[i].actions[a].amount); bw.Write(MBRF[i].actions[a].flags); bw.Write(MBRF[i].actions[a].padding); bw.Write(MBRF[i].actions[a].maskflag); } bw.Write(MBRF[i].exeflag); bw.Write(MBRF[i].playerlist); bw.Write(MBRF[i].trigindex); } break; } }