private CopyEntry ReadCopyEntry() { CopyEntry result = default(CopyEntry); result.SrcPosition = reader.ReadInt32(); result.Size = reader.ReadInt32(); result.DestPosition = reader.ReadInt32(); return(result); }
private static void ApplyCopyEntry(Stream targetFileStream, CopyEntry entry) { targetFileStream.Seek(entry.SrcPosition, SeekOrigin.Begin); int num = 0; int num2 = entry.Size; do { int num3 = targetFileStream.Read(buffer, num, num2); num2 -= num3; num += num3; }while (num2 > 0); targetFileStream.Seek(entry.DestPosition, SeekOrigin.Begin); targetFileStream.Write(buffer, 0, entry.Size); targetFileStream.Flush(); }
private void ApplyEntries(int curEntryIndex, int numEntries) { for (int i = curEntryIndex; i < numEntries; i++) { JournalEntryType journalEntryType = (JournalEntryType)reader.ReadByte(); switch (journalEntryType) { case JournalEntryType.Resize: { string path3 = reader.ReadString(); Stream targetFileStream3 = fileSystem.OpenFileStream(path3); ResizeEntry entry3 = ReadResizeEntry(); ApplyResizeEntry(targetFileStream3, entry3); break; } case JournalEntryType.Write: { string path2 = reader.ReadString(); Stream targetFileStream2 = fileSystem.OpenFileStream(path2); WriteEntry entry2 = ReadWriteEntry(); ApplyWriteEntry(targetFileStream2, entry2); break; } case JournalEntryType.Copy: { string path = reader.ReadString(); Stream targetFileStream = fileSystem.OpenFileStream(path); CopyEntry entry = ReadCopyEntry(); ApplyCopyEntry(targetFileStream, entry); break; } default: throw new CorruptionException("Unhandled entry type: " + journalEntryType); } curEntryIndex++; SetCurEntryIndex(curEntryIndex); } }
public void ParseJCDFile(string jcdFile, string classpath, string java_home) { // load file XmlDocument doc = new XmlDocument(); doc.Load(new XmlTextReader(jcdFile)); // target XmlNode targetNode = doc[en.jcd][en.target]; if (target == null && targetNode != null) { // only set once in top-level package target = ((XmlElement)targetNode).GetAttribute("name"); } // java_home XmlNode jdkNode = doc[en.jcd][en.jdk]; if (jdkNode != null) { java_home = JCDParserResults.JDKToJAVA_HOME(((XmlElement)jdkNode).GetAttribute("version")); } XmlNode java_homeNode = doc[en.jcd][en.java_home]; if (java_homeNode != null) { java_home = ((XmlElement)java_homeNode).GetAttribute("path"); } java_home = java_home.ToLower(); // only set once in top-level package if (component_java_home == null) { component_java_home = java_home; } // classpath XmlNode classpathParentNode = doc[en.jcd][en.classpath]; if (classpathParentNode != null) { classpath = ""; XmlNodeList classpathNodes = classpathParentNode.ChildNodes; foreach (XmlNode classpathNode in classpathNodes) { if (classpathNode.LocalName == en.path) { classpath += ((XmlElement)classpathNode).GetAttribute("value") + ";"; } } classpath = classpath.TrimEnd(new char[] { ';' }); classpath = Environment.ExpandEnvironmentVariables(classpath); } classpath = classpath.ToLower(); // services XmlNode servicesParentNode = doc[en.jcd][en.services]; if (servicesParentNode != null) { foreach (XmlNode serviceNode in servicesParentNode.ChildNodes) { if (serviceNode.LocalName == en.service) { ServiceEntry e = new ServiceEntry(); XmlNode taskJdkNode = serviceNode[en.jdk]; XmlNode taskJava_HomeNode = serviceNode[en.java_home]; XmlNode taskClasspathParentNode = serviceNode[en.classpath]; if (taskJava_HomeNode != null) { e.java_home = ((XmlElement)taskJava_HomeNode).GetAttribute("path"); } else if (taskJdkNode != null) { e.java_home = JCDParserResults.JDKToJAVA_HOME(((XmlElement)taskJdkNode).GetAttribute("version")); } else { e.java_home = java_home; } e.classpath = classpath; if (taskClasspathParentNode != null) { XmlNodeList classpathNodes = taskClasspathParentNode.ChildNodes; e.classpath = ""; foreach (XmlNode classpathNode in classpathNodes) { if (classpathNode.LocalName == en.path) { e.classpath += ((XmlElement)classpathNode).GetAttribute("value") + ";"; } } e.classpath = e.classpath.TrimEnd(new char[] { ';' }); e.classpath = Environment.ExpandEnvironmentVariables(e.classpath); } e.service = ((XmlElement)serviceNode).GetAttribute("name"); e.version = ((XmlElement)serviceNode).GetAttribute("version"); serviceList.Add(e); } } } // compilation tasks XmlNode complistParentNode = doc[en.jcd][en.complist]; if (complistParentNode != null) { XmlNodeList complistTaskNodes = complistParentNode.ChildNodes; foreach (XmlNode complistTaskNode in complistTaskNodes) { if (complistTaskNode.NodeType == XmlNodeType.Comment) { continue; } string taskTool = complistTaskNode.LocalName; XmlNode taskJdkNode = complistTaskNode[en.jdk]; string taskJava_Home = (taskJdkNode != null) ? JCDParserResults.JDKToJAVA_HOME(((XmlElement)taskJdkNode).GetAttribute("version")) : java_home; XmlNode taskJava_HomeNode = complistTaskNode[en.java_home]; taskJava_Home = (taskJava_HomeNode != null) ? ((XmlElement)taskJava_HomeNode).GetAttribute("path") : taskJava_Home; XmlNode taskClasspathParentNode = complistTaskNode[en.classpath]; string taskClasspath = classpath; if (taskClasspathParentNode != null) { taskClasspath = ""; XmlNodeList classpathNodes = taskClasspathParentNode.ChildNodes; foreach (XmlNode classpathNode in classpathNodes) { if (classpathNode.LocalName == en.path) { taskClasspath += ((XmlElement)classpathNode).GetAttribute("value") + ";"; } } taskClasspath = taskClasspath.TrimEnd(new char[] { ';' }); taskClasspath = Environment.ExpandEnvironmentVariables(taskClasspath); } Complist.ComplistKey ck = new Complist.ComplistKey(taskTool, taskJava_Home, taskClasspath); Complist complist = null; foreach (Complist cl in complists) { if (cl.complistKey.Equals(ck)) { complist = cl; } } if (complist == null) { complist = new Complist(ck); complists.Add(complist); } XmlNodeList complistFileNodes = complistTaskNode.ChildNodes; foreach (XmlNode complistFileNode in complistFileNodes) { if (complistFileNode.LocalName != en.file) { continue; } string filename = DepackageFilename(((XmlElement)complistFileNode).GetAttribute("name")); complist.files.Add(filename); } } } // nested packages XmlNode nestedPackageParentNode = doc[en.jcd][en.nestedPackages]; if (nestedPackageParentNode != null) { XmlNodeList nestedPackageNodes = nestedPackageParentNode.ChildNodes; foreach (XmlNode nestedPackageNode in nestedPackageNodes) { if (nestedPackageNode.LocalName != en.package) { continue; } string packageDescriptorName = ((XmlElement)nestedPackageNode).GetAttribute("descriptor"); //check if the package descriptor is in the same directory as the parent string packageDirectory = Path.Combine(Path.GetPathRoot(jcdFile), Path.GetDirectoryName(jcdFile)); string packageFileName = Path.Combine(packageDirectory, packageDescriptorName); //if not, check in sibling pkg directory if (!File.Exists(packageFileName)) { int lastDirectoryPos = packageDirectory.LastIndexOfAny(new char[] { '\\', '/' }); if (lastDirectoryPos > -1) { string packageDirectoryParent = packageDirectory.Substring(0, lastDirectoryPos + 1); packageDirectory = Path.Combine(packageDirectoryParent, "pkg"); packageFileName = Path.Combine(packageDirectory, packageDescriptorName); } } if (!File.Exists(packageFileName)) { throw new Exception("Package descriptor, " + packageDescriptorName + ", not found"); } this.ParseJCDFile(packageFileName, classpath, java_home); } } XmlNode jarIncludesNode = doc[en.jcd][en.jarIncludes]; if (jarIncludesNode != null) { // product files XmlNode productFilesParentNode = jarIncludesNode[en.productFiles]; if (productFilesParentNode != null) { XmlNodeList productFileNodes = productFilesParentNode.ChildNodes; foreach (XmlNode productFileNode in productFileNodes) { if (productFileNode.LocalName == en.file) { CopyEntry ce = new CopyEntry(); string filename = DepackageFilename(((XmlElement)productFileNode).GetAttribute("name")); ce.from = "%BuildPath%\\" + Path.GetExtension(filename).TrimStart(new char[] { '.' }) + Path.DirectorySeparatorChar + filename; XmlNode packageNode = productFileNode[en.package]; if (packageNode != null) { string packagePath = ((XmlElement)packageNode).GetAttribute("name"); ce.to = packagePath.Replace('.', '\\'); } copyList.Add(ce); } else if (productFileNode.LocalName == en.manifest) { XmlElement manifestFileNode = (XmlElement)productFileNode[en.file]; string filename = DepackageFilename(manifestFileNode.GetAttribute("name")); manifest = "%BuildPath%\\" + Path.GetExtension(filename).TrimStart(new char[] { '.' }) + Path.DirectorySeparatorChar + filename; } } } // library files XmlNodeList libraryNodes = jarIncludesNode.ChildNodes; foreach (XmlNode libraryNode in libraryNodes) { if (libraryNode.LocalName != en.library) { continue; } string libraryPath = libraryNode[en.path].GetAttribute("value"); XmlNodeList fileNodes = libraryNode.ChildNodes; foreach (XmlNode fileNode in fileNodes) { if (fileNode.LocalName != en.file) { continue; } CopyEntry ce = new CopyEntry(); string filename = ((XmlElement)fileNode).GetAttribute("name"); ce.from = Path.Combine(libraryPath, filename); ce.to = Path.GetDirectoryName(filename); copyList.Add(ce); } } } // packageSteps XmlNode packageStepsParentNode = doc[en.jcd][en.packageSteps]; if (packageStepsParentNode != null) { XmlNodeList packageSteps = packageStepsParentNode.ChildNodes; foreach (XmlNode packageStep in packageSteps) { string packageStepName = ((XmlElement)packageStep).GetAttribute("name"); packageStepList.Add(packageStepName); } } }
public bool OnActionItemClicked(ActionMode mode, IMenuItem item) { var listView = FragmentManager.FindFragmentById <GroupListFragment>(Resource.Id.list_fragment).ListView; var checkedItemPositions = listView.CheckedItemPositions; List <IStructureItem> checkedItems = new List <IStructureItem>(); for (int i = 0; i < checkedItemPositions.Size(); i++) { if (checkedItemPositions.ValueAt(i)) { checkedItems.Add(((PwGroupListAdapter)ListAdapter).GetItemAtPosition(checkedItemPositions.KeyAt(i))); } } //shouldn't happen, just in case... if (!checkedItems.Any()) { return(false); } Handler handler = new Handler(); switch (item.ItemId) { case Resource.Id.menu_delete: DeleteMultipleItems task = new DeleteMultipleItems((GroupBaseActivity)Activity, App.Kp2a.GetDb(), checkedItems, new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity)), App.Kp2a); task.Start(); break; case Resource.Id.menu_move: var navMove = new NavigateToFolderAndLaunchMoveElementTask(checkedItems.First().ParentGroup, checkedItems.Select(i => i.Uuid).ToList(), ((GroupBaseActivity)Activity).IsSearchResult); ((GroupBaseActivity)Activity).StartTask(navMove); break; case Resource.Id.menu_copy: var copyTask = new CopyEntry((GroupBaseActivity)Activity, App.Kp2a, (PwEntry)checkedItems.First(), new GroupBaseActivity.RefreshTask(handler, ((GroupBaseActivity)Activity))); ProgressTask pt = new ProgressTask(App.Kp2a, Activity, copyTask); pt.Run(); break; case Resource.Id.menu_navigate: NavigateToFolder navNavigate = new NavigateToFolder(checkedItems.First().ParentGroup, true); ((GroupBaseActivity)Activity).StartTask(navNavigate); break; case Resource.Id.menu_edit: GroupEditActivity.Launch(Activity, checkedItems.First().ParentGroup, (PwGroup)checkedItems.First()); break; default: return(false); } listView.ClearChoices(); ((BaseAdapter)ListAdapter).NotifyDataSetChanged(); if (_mode != null) { mode.Finish(); } return(true); }