private static void Main(string[] args) { if (args.Length >= 2) { try { string[] options = args.Where(x => x.StartsWith("-")).ToArray(); args = args.Skip(options.Length).Take(args.Length - options.Length).ToArray(); if (options.Contains("-r", StringComparer.InvariantCultureIgnoreCase)) { if (args.Length < 3) { PrintUsage(); return; } DtPaths = args.Take(args.Length - 2).ToArray(); string lspath = args[DtPaths.Length]; string patchFolder = args.Last(); lsFile = new LSFile(lspath); Logstream = new StreamWriter("log.txt"); PatchArchive("resource", patchFolder); PatchArchive("resource(us_en)", patchFolder); PatchArchive("resource(us_fr)", patchFolder); PatchArchive("resource(us_sp)", patchFolder); lsFile.WorkingSource.Close(); } else { DtPaths = args.Take(args.Length - 1).ToArray(); string lspath = args[DtPaths.Length]; lsFile = new LSFile(lspath); Logstream = new StreamWriter("log.txt"); Unpack_Resource("resource"); lsFile.WorkingSource.Close(); } } catch (Exception x) { Console.WriteLine(x.Message); Logstream.WriteLine(x.Message); Logstream.Close(); throw; } } if (args.Length == 1) { Unpack_update(args[0]); } else { PrintUsage(); } Logstream.Close(); }
private void ProcessLink(string name, LSFile file) { String[] segments = name.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries); // we should have 2 segments if (segments.Length == 2) { file.LinkPath = segments[1].Trim(); } }
private static void Main(string[] args) { if (args.Length >= 2) { try { string[] options = args.Where(x => x.StartsWith("-")).ToArray(); args = args.Skip(options.Length).Take(args.Length - options.Length).ToArray(); if (options.Contains("-r", StringComparer.InvariantCultureIgnoreCase)) { if (args.Length < 3) { PrintUsage(); return; } DtPaths = args.Take(args.Length - 2).ToArray(); string lspath = args[DtPaths.Length]; string patchFolder = args.Last(); lsFile = new LSFile(lspath); Logstream = new StreamWriter("log.txt"); PatchArchive("resource", patchFolder); PatchArchive("resource(us_en)",patchFolder); PatchArchive("resource(us_fr)", patchFolder); PatchArchive("resource(us_sp)", patchFolder); lsFile.WorkingSource.Close(); } else { DtPaths = args.Take(args.Length - 1).ToArray(); string lspath = args[DtPaths.Length]; lsFile = new LSFile(lspath); Logstream = new StreamWriter("log.txt"); Unpack_Resource("resource"); lsFile.WorkingSource.Close(); } } catch (Exception x) { Console.WriteLine(x.Message); Logstream.WriteLine(x.Message); Logstream.Close(); throw; } } if (args.Length == 1) Unpack_update(args[0]); else PrintUsage(); Logstream.Close(); }
/// <summary> /// 拷贝单个设备文件到本地路径,返回新的本地路径。 /// </summary> public string CopySingleFile(Device device, LSFile file, string targetPath, IAsyncResult asyn) { if (!file.HasPermission) { if (!this.UpgradeFilePermission(device, file.FullPath)) { return(string.Empty); } } var res = this.CopySingleFile(device, file.FullPath, targetPath, asyn); return(res); }
private static void Main(string[] args) { if (args.Length >= 2) { try { string[] options = args.Where(x => x.StartsWith("-")).ToArray(); args = args.Skip(options.Length).Take(args.Length - options.Length).ToArray(); if (options.Contains("-r", StringComparer.InvariantCultureIgnoreCase)) { if (args.Length < 3) { PrintUsage(); return; } DtPaths = args.Take(args.Length - 2).ToArray(); string lspath = args[DtPaths.Length]; string patchFolder = args.Last(); lsFile = new LSFile(lspath); manager = new ResourceManager(DtPaths, lsFile); manager.BuildPartitions(patchFolder); } else { DtPaths = args.Take(args.Length - 1).ToArray(); string lspath = args[DtPaths.Length]; lsFile = new LSFile(lspath); manager = new ResourceManager(DtPaths, lsFile); manager.UnpackAll("content"); } if (lsFile != null) { lsFile.WorkingSource.Close(); } } catch (Exception x) { Console.WriteLine(x.Message); throw; } } else if (args.Length == 0) { PrintUsage(); } }
public ResourceCollection[] LoadRFFiles(string[] rfFiles) { //Loading LS File LogHelper.Info(string.Format("Loading LS File '{0}'", _lsFilePath)); LSFile lsFile = new LSFile(_lsFilePath); //Sorting Resource files Array.Sort(rfFiles, new CustomStringComparer()); //Loading RF Files ResourceCollection[] resCols = new ResourceCollection[rfFiles.Length]; for (int i = 0; i < rfFiles.Length; i++) { LogHelper.Debug(string.Format("Loading RF File '{0}'", rfFiles[i])); resCols[i] = LoadRFFile(rfFiles[i], lsFile); } return(resCols); }
private LSFile ProcessLine(string line) { if (!line.IsValid()) { return(null); } var m = Regex.Match(line.TrimStart("OKAY").Trim(), LS_PATTERN_EX, RegexOptions.Compiled); if (!m.Success) { return(null); } LSFile file = new LSFile(); file.Name = m.Groups[9].Value; file.Permission = m.Groups[1].Value; var sized = m.Groups[4].Value.Trim(); file.Size = sized.ToSafeInt(); //folder file.IsFolder = false; switch (file.Permission[0]) { case 'b': file.Type = "Block"; break; case 'c': file.Type = "Character"; break; case 'd': /* 遇到一个recovery模式的手机,文件夹也有大小,切大小为4096,此处临时修改为此方案,以后根据测试情况在看 */ file.Type = "Directory"; if (!sized.IsValid() || file.Size == 4096) { file.IsFolder = true; } break; case 'l': file.Type = "Link"; ProcessLink(file.Name, file); break; case 's': file.Type = "Socket"; break; case 'p': file.Type = "FIFO"; break; case '-': default: file.Type = "File"; break; } //datetime String date1 = m.Groups[5].Value.Trim(); String date2 = m.Groups[6].Value.Trim(); String date3 = m.Groups[7].Value.Trim(); String time = m.Groups[8].Value.Trim(); string datestr = String.Format("{0}-{1}-{2} {3}", date1, date2.PadLeft(2, '0'), date3, time); try { var date = DateTime.ParseExact(datestr, "yyyy-MM-dd HH:mm", CultureInfo.CurrentCulture); file.CreateDate = date; } catch (Exception ex) { LoggerManagerSingle.Instance.Error(ex, string.Format("can not convert '{0}' to datetime.", datestr)); } //link file //return return(file); }
public ResourceCollection LoadRFFile(string rfFilePath, LSFile lsFile) { string region = Utils.GetRegionFromFilename(rfFilePath); PatchFileItem currentPackedPatchFile = null; //Create new ResourceCollection ResourceCollection resCol = new ResourceCollection("data" + region); //Use temp folder instead of patch folder string tempRF = _TempFolder + Path.GetFileName(rfFilePath); File.Copy(rfFilePath, tempRF, true); //Load RF file RFFile rfFile = new RFFile(tempRF); string[] pathParts = new string[20]; LSEntry[] offsetParts = new LSEntry[20]; ResourceItem[] pathPartsRes = new ResourceItem[20]; foreach (ResourceEntry rEntry in rfFile.ResourceEntries) { if (rEntry == null || string.IsNullOrEmpty(rEntry.EntryString)) { continue; } if (IsJunkEntry(rEntry)) { continue; } //Figuring out the path of the entry pathParts[rEntry.FolderDepth - 1] = rEntry.EntryString; Array.Clear(pathParts, rEntry.FolderDepth, pathParts.Length - (rEntry.FolderDepth)); //New ResourceItem object ResourceItem rItem = new ResourceItem(resCol, rEntry.EntryString, rEntry.OffInPack, (uint)rEntry.CmpSize, (uint)rEntry.DecSize, rEntry.Packed, string.Join(string.Empty, pathParts)); //For Treeview pathPartsRes[rEntry.FolderDepth - 1] = rItem; Array.Clear(pathPartsRes, rEntry.FolderDepth, pathPartsRes.Length - (rEntry.FolderDepth)); if (rEntry.FolderDepth == 1) { resCol.Nodes.Add(rItem); } else { pathPartsRes[rEntry.FolderDepth - 2].Nodes.Add(rItem); } LSEntry fileEntry = null; PatchFileItem patchItem = null; if (rEntry.Packed) { //Check if part of the patch/mod patchItem = _PatchFileList.GetPatchFileItem(rItem.AbsolutePath); if (patchItem != null) { if (patchItem.Packed) { currentPackedPatchFile = patchItem; } } //Part of LS else { currentPackedPatchFile = null; string crcPath = rItem.AbsolutePath.TrimEnd('/') + (rEntry.Directory ? "/packed" : ""); uint crc = calc_crc(crcPath); lsFile.Entries.TryGetValue(crc, out fileEntry); if (fileEntry == null) { rItem.Source = FileSource.NotFound; } else { lsFile.Entries.Remove(crc); rItem.Source = FileSource.LS; } } } //Check if part of the patch/mod if (currentPackedPatchFile != null && rItem.AbsolutePath.StartsWith(currentPackedPatchFile.AbsolutePath)) { rItem.Source = FileSource.Patch; } else if (patchItem != null) { rItem.Source = FileSource.Patch; } //Part of LS else { currentPackedPatchFile = null; offsetParts[rEntry.FolderDepth - 1] = fileEntry; Array.Clear(offsetParts, rEntry.FolderDepth, offsetParts.Length - (rEntry.FolderDepth)); if (!rItem.AbsolutePath.EndsWith("/")) { rItem.LSEntryInfo = offsetParts.LastOrDefault(x => x != null); if (rItem.LSEntryInfo == null) { rItem.Source = FileSource.NotFound; } else { rItem.Source = FileSource.LS; } } } rItem.PatchItem = currentPackedPatchFile; if (rItem.Source != FileSource.NotFound) { for (int i = 0; i < pathParts.Length; i++) { if (pathParts[i] != null) { string folder = string.Join(string.Empty, pathParts, 0, i); if (!resCol.Resources.ContainsKey(folder)) { continue; } if (rItem.Source == FileSource.LS && resCol.Resources[folder].Source == FileSource.Patch) { resCol.Resources[folder].Source = rItem.Source; } else if (resCol.Resources[folder].Source == FileSource.NotFound) { resCol.Resources[folder].Source = rItem.Source; } } } } rItem.OriginalFlags = rEntry.Flags; resCol.Resources.Add(rItem.RelativePath, rItem); } rfFile.WorkingSource.Close(); rfFile.CompressedSource.Close(); if (File.Exists(tempRF)) { File.Delete(tempRF); } if (File.Exists(tempRF + ".dec")) { File.Delete(tempRF + ".dec"); } LogHelper.Info(string.Format("{0} entries: {1}", resCol.ResourceName, resCol.Resources.Count)); return(resCol); }