private void Add_Button_Click(object sender, RoutedEventArgs e) { XmlNode element = configLangCombo.SelectedItem as XmlNode; string langSelected = element.Attributes.GetNamedItem("name").Value.ToString(); string resolutionSelected = resolutionCombo.Text.ToString(); string id = element.Attributes.GetNamedItem("id").Value.ToString(); id = id.Replace('-', '_'); bool canAdd = validateAddParams(langSelected, resolutionSelected); if (!canAdd) { System.Windows.MessageBox.Show("Language-DPI is already present in the list"); return; } string folderName = id + "-" + resolutionSelected; string directoryPath = ("/res/contents/" + folderName); if (canAdd && currentProj != null) { ProjectItem contents = ResourceManagerUtil.getContentFolder(currentProj); ResourceManagerUtil.addProjectFolder(folderName, contents); } }
/// <summary> /// Sub menu click Handler for CopyTo/MoveTo /// </summary> private void subMenu_Click(object sender, RoutedEventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { string[] destNameArray = mi.Header.ToString().Split(','); ExpandoObject expObj = ResourceManagerUtil.getExpandoObj(); //destNameArray[0].Equals("default_All") ? destNameArray[0] : GetProperty(expando, (ResourceManagerUtil.GetProperty(expObj, destNameArray[0]) as string)); string expStoredName = (destNameArray[0].Equals("default_All") ? destNameArray[0] : (ResourceManagerUtil.GetProperty(expObj, destNameArray[0]) as string)); string[] expStoredNameArray = expStoredName.Split('_'); string destName = (expStoredNameArray[0] + "_" + (expStoredNameArray[1].Equals("All") ? expStoredNameArray[1] : expStoredNameArray[1].ToUpper()) + "-" + destNameArray[1].Trim()); MenuItem cm = mi.Parent as MenuItem; string opt = cm.Header.ToString();//Either copy to or move to selected ProjectItem contentsDirItems = ResourceManagerUtil.getContentFolder(currProj); string[] srcHierarchy = parentSelected.Split('/'); Boolean isAllConf = false;//since All Configuration points to directory res/contents folder, we have to change the path. ProjectItem destProjItem = ResourceManagerUtil.getProjectItem(destName, contentsDirItems); string projPath = Path.GetDirectoryName(currProj.FullName); srcHierarchy = srcHierarchy.Take(srcHierarchy.Count() - 1).ToArray(); if (srcHierarchy.Count() == 0) { return; } if (srcHierarchy[0].Equals("ALL")) { isAllConf = true; srcHierarchy = srcHierarchy.Skip(1).ToArray(); } string srcPath = projPath.ToString() + "\\res\\contents\\" + String.Join("\\", srcHierarchy); string extResult = Path.GetExtension(String.Join("/", srcHierarchy)); string[] srcPathArray = Path.GetDirectoryName(srcPath).Split(new string[] { srcHierarchy[0] }, StringSplitOptions.None); ProjectItem srcParentPrjItem = contentsDirItems; string srcLastItem = srcHierarchy.Last(); foreach (string folderName in srcHierarchy) { if (!object.ReferenceEquals(folderName, srcLastItem)) { try { srcParentPrjItem = ResourceManagerUtil.getProjectItem(folderName, srcParentPrjItem); } catch (Exception) { } } } //If path is Folder if (extResult.Equals("")) { if (isAllConf) { List <string> srcHierList = new List <string>(srcHierarchy); srcHierList.Insert(0, "ALL"); srcHierarchy = srcHierList.ToArray(); } for (int i = 1; i < srcHierarchy.Length - 1; i++) { if (i < 0) { break; } if (!srcHierarchy[i].Equals("")) { destProjItem = ResourceManagerUtil.addProjectFolder(srcHierarchy[i], destProjItem); } } ResourceManagerUtil.copyDir(srcPath, destProjItem); } //If path is file else { if (isAllConf) { srcPathArray = Path.GetDirectoryName(srcPath).Split(new string[] { "\\res\\contents\\" }, StringSplitOptions.None); } if (srcPathArray.Count() > 1) { foreach (string folderName in srcPathArray[1].Split('\\')) { if (!folderName.Equals("")) { destProjItem = ResourceManagerUtil.addProjectFolder(folderName, destProjItem); } } } ResourceManagerUtil.copyFile(srcPath, destProjItem); } if (opt.Equals("Move To")) { try { ResourceManagerUtil.removeProjectItem(srcLastItem, srcParentPrjItem); } catch (Exception) { FileAttributes attr = File.GetAttributes(@srcPath); //detect whether its a directory or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { Directory.Delete(srcPath); } else { File.Delete(srcPath); } } } } }