把游戏项目迁移到IOS64 上面又出现了自动寻路无效的BUG,在XCode Console中有提示AStarpath异常,
Bad date/time format in the zip file
文章来自播客 http://blog.csdn.net/huutu文章来自播客 http://blog.csdn.net/huutu
我们从谷歌下载到DotnetZip的源代码,然后在整个项目中搜索异常信息,定位到文件 Shared.cs 文章来自播客 http://blog.csdn.net/huutu
文章来自播客 http://blog.csdn.net/huutu
internal static DateTime PackedToDateTime(Int32 packedDateTime) { // workitem 7074 & workitem 7170 if (packedDateTime == 0xFFFF || packedDateTime == 0) return new System.DateTime(1995, 1, 1, 0, 0, 0, 0); // return a fixed date when none is supplied. Int16 packedTime = unchecked((Int16)(packedDateTime & 0x0000ffff)); Int16 packedDate = unchecked((Int16)((packedDateTime & 0xffff0000) >> 16)); int year = 1980 + ((packedDate & 0xFE00) >> 9); int month = (packedDate & 0x01E0) >> 5; int day = packedDate & 0x001F; int hour = (packedTime & 0xF800) >> 11; int minute = (packedTime & 0x07E0) >> 5; //int second = packedTime & 0x001F; int second = (packedTime & 0x001F) * 2; // validation and error checking. // this is not foolproof but will catch most errors. if (second >= 60) { minute++; second = 0; } if (minute >= 60) { hour++; minute = 0; } if (hour >= 24) { day++; hour = 0; } DateTime d = System.DateTime.Now; bool success= false; try { d = new System.DateTime(year, month, day, hour, minute, second, 0); success= true; } catch (System.ArgumentOutOfRangeException) { if (year == 1980 && (month == 0 || day == 0)) { try { d = new System.DateTime(1980, 1, 1, hour, minute, second, 0); success= true; } catch (System.ArgumentOutOfRangeException) { try { d = new System.DateTime(1980, 1, 1, 0, 0, 0, 0); success= true; } catch (System.ArgumentOutOfRangeException) { } } } // workitem 8814 // my god, I can't believe how many different ways applications // can mess up a simple date format. else { try { while (year < 1980) year++; while (year > 2030) year--; while (month < 1) month++; while (month > 12) month--; while (day < 1) day++; while (day > 28) day--; while (minute < 0) minute++; while (minute > 59) minute--; while (second < 0) second++; while (second > 59) second--; d = new System.DateTime(year, month, day, hour, minute, second, 0); success= true; } catch (System.ArgumentOutOfRangeException) { } } } if (!success) { string msg = String.Format("y({0}) m({1}) d({2}) h({3}) m({4}) s({5})", year, month, day, hour, minute, second); throw new ZipException(String.Format("Bad date/time format in the zip file. ({0})", msg)); } // workitem 6191 //d = AdjustTime_Reverse(d); d = DateTime.SpecifyKind(d, DateTimeKind.Local); return d; }文章来自播客 http://blog.csdn.net/huutu
文章来自播客 http://blog.csdn.net/huutu
作为一个ZIP库,自然而然是需要读取文件中存储的时间信息的,但是我们这里用来作为读取AStarPath保存的寻路信息,那ZIP中的时间数据对我们来说一点用处没有,所以
我们也不用管为什么会抛出异常,直接返回一个时间,我这里就返回现在时间吧! 文章来自播客 http://blog.csdn.net/huutu
修改后的函数
internal static DateTime PackedToDateTime(Int32 packedDateTime) { return System.DateTime.Now; // workitem 7074 & workitem 7170 if (packedDateTime == 0xFFFF || packedDateTime == 0) return new System.DateTime(1995, 1, 1, 0, 0, 0, 0); // return a fixed date when none is supplied. Int16 packedTime = unchecked((Int16)(packedDateTime & 0x0000ffff)); Int16 packedDate = unchecked((Int16)((packedDateTime & 0xffff0000) >> 16)); int year = 1980 + ((packedDate & 0xFE00) >> 9); int month = (packedDate & 0x01E0) >> 5; int day = packedDate & 0x001F; int hour = (packedTime & 0xF800) >> 11; int minute = (packedTime & 0x07E0) >> 5; //int second = packedTime & 0x001F; int second = (packedTime & 0x001F) * 2; // validation and error checking. // this is not foolproof but will catch most errors. if (second >= 60) { minute++; second = 0; } if (minute >= 60) { hour++; minute = 0; } if (hour >= 24) { day++; hour = 0; } DateTime d = System.DateTime.Now; bool success= false; try { d = new System.DateTime(year, month, day, hour, minute, second, 0); success= true; } catch (System.ArgumentOutOfRangeException) { if (year == 1980 && (month == 0 || day == 0)) { try { d = new System.DateTime(1980, 1, 1, hour, minute, second, 0); success= true; } catch (System.ArgumentOutOfRangeException) { try { d = new System.DateTime(1980, 1, 1, 0, 0, 0, 0); success= true; } catch (System.ArgumentOutOfRangeException) { } } } // workitem 8814 // my god, I can't believe how many different ways applications // can mess up a simple date format. else { try { while (year < 1980) year++; while (year > 2030) year--; while (month < 1) month++; while (month > 12) month--; while (day < 1) day++; while (day > 28) day--; while (minute < 0) minute++; while (minute > 59) minute--; while (second < 0) second++; while (second > 59) second--; d = new System.DateTime(year, month, day, hour, minute, second, 0); success= true; } catch (System.ArgumentOutOfRangeException) { } } } if (!success) { string msg = String.Format("y({0}) m({1}) d({2}) h({3}) m({4}) s({5})", year, month, day, hour, minute, second); throw new ZipException(String.Format("Bad date/time format in the zip file. ({0})", msg)); } // workitem 6191 //d = AdjustTime_Reverse(d); d = DateTime.SpecifyKind(d, DateTimeKind.Local); return d; }文章来自播客 http://blog.csdn.net/huutu
文章来自播客 http://blog.csdn.net/huutu
http://download.csdn.net/detail/cp790621656/8481557