private static void ImportHandler(int deep, string parent, string path, bool overwrite, string destination, bool checkIndex = false) { foreach (DirectoryInfo folder in new DirectoryInfo(path).GetDirectories()) { string dirName = folder.Name; string infoPath = Path.Combine(path, dirName, dirName + ".info"); if (File.Exists(infoPath)) { string[] nameSplit = dirName.Split('.'); string oldId = dirName.Split('.')[0]; string newId; if (overwrite || deep < 2) { newId = oldId; } else { newId = PathHelper.GenerateId(10); } if (nameSplit.Length < 2) { newId = PathHelper.GenerateId(10) + ".Folder" + random.Next(1000, 10000); } bool copyInfo = true; string newDirName = dirName.Replace(oldId, newId); if (!string.IsNullOrEmpty(destination)) { string[] dest = destination.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (dest.Length > 0) { newDirName = dest[0]; newId = dest[0].Split('.')[0]; destination = destination.Replace(dest[0], ""); copyInfo = false; } } if (deep == 2) { tempIds.Add(new IdContainer(oldId, newId)); } if (dirName != newDirName) { Directory.Move(Path.Combine(path, dirName), Path.Combine(path, newDirName)); infoPath = Path.Combine(path, newDirName, dirName + ".info"); if (copyInfo) { if (File.Exists(Path.Combine(path, newDirName, newDirName + ".info"))) { File.Delete(Path.Combine(path, newDirName, newDirName + ".info")); } File.Move(infoPath, Path.Combine(path, newDirName, newDirName + ".info")); } else { File.Delete(infoPath); } } ImportHandler(deep + 1, Path.Combine(parent, newDirName), folder.FullName.Replace(dirName, newDirName), overwrite, destination, checkIndex); } if (dirName == "topics") { FileInfo[] folderFiles = folder.GetFiles(); int filesCount = 0; if (checkIndex) { string repoPath = Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder()).Replace("\\", "/"); string newLocation = Path.Combine(repoPath, parent).Replace("\\", "/") + "/topics"; if (!Directory.Exists(newLocation)) { Directory.CreateDirectory(newLocation); } filesCount = Directory.GetFiles(newLocation, "*", SearchOption.AllDirectories).Length; } int indexId = 0; foreach (FileInfo t in folderFiles) { TopicModel topic = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(t.FullName)); OldTopicModel oldTopic = JsonConvert.DeserializeObject <OldTopicModel>(File.ReadAllText(t.FullName)); if (!string.IsNullOrEmpty(oldTopic.pathToZip)) { topic.localization = "default"; topic.pathToZip = oldTopic.pathToZip; //Debug.Log("Old import"); } if (!string.IsNullOrEmpty(oldTopic.vmpPath)) { topic.localization = "default"; topic.vmpPath = oldTopic.vmpPath; //Debug.Log("Old import"); } if (string.IsNullOrEmpty(topic.unique_id)) { topic.unique_id = PathHelper.GenerateId(6); } if (checkIndex) { topic.index = filesCount; } string oldTopicName = t.Name; string newTopicName = "topic" + PathHelper.GenerateIntId(8) + ".info"; topic.localization = "default"; string locPath = Path.Combine(Path.Combine(UsersHelper.GetUserFolder(), UsersHelper.GetToolsFolder()), parent, "default"); string tempPath = Path.Combine(t.Directory.Parent.FullName, "default"); if (!string.IsNullOrEmpty(topic.pathToZip)) { string oldZipName = new FileInfo(topic.pathToZip).Name; string newZipName = "zip" + PathHelper.GenerateIntId(8) + ".zip"; if (File.Exists(Path.Combine(tempPath, "pub_in", oldZipName))) { if (File.Exists(Path.Combine(tempPath, "pub_in", newZipName))) { File.Delete(Path.Combine(tempPath, "pub_in", newZipName)); } File.Move(Path.Combine(tempPath, "pub_in", oldZipName), Path.Combine(tempPath, "pub_in", newZipName)); } topic.pathToZip = Path.Combine(locPath, "pub_in", newZipName); topic.pathToZip = topic.pathToZip.Replace("\\", "/"); topic.pathToZipDEFAULT = Path.Combine(locPath, "pub_in", newZipName); topic.pathToZipDEFAULT = topic.pathToZip.Replace("\\", "/"); } if (!string.IsNullOrEmpty(topic.vmpPath)) { string oldVmpName = new FileInfo(topic.vmpPath).Name; string newVmpName = "obj" + PathHelper.GenerateIntId(8) + ".vmp"; if (File.Exists(Path.Combine(tempPath, "projects", oldVmpName))) { if (File.Exists(Path.Combine(tempPath, "projects", newVmpName))) { File.Delete(Path.Combine(tempPath, "projects", newVmpName)); } File.Move(Path.Combine(tempPath, "projects", oldVmpName), Path.Combine(tempPath, "projects", newVmpName)); } if (File.Exists(Path.Combine(tempPath, "projects", oldVmpName.Replace(".vmp", ".vmb")))) { if (File.Exists(Path.Combine(tempPath, "projects", newVmpName.Replace(".vmp", ".vmb")))) { File.Delete(Path.Combine(tempPath, "projects", newVmpName.Replace(".vmp", ".vmb"))); } File.Move(Path.Combine(tempPath, "projects", oldVmpName.Replace(".vmp", ".vmb")), Path.Combine(tempPath, "projects", newVmpName.Replace(".vmp", ".vmb"))); } topic.vmpPath = Path.Combine(locPath, "projects", newVmpName); topic.vmpPath = topic.vmpPath.Replace("\\", "/"); topic.vmpPathDEFAULT = Path.Combine(locPath, "projects", newVmpName); topic.vmpPathDEFAULT = topic.vmpPath.Replace("\\", "/"); } topic.isOpened = 0; //change path to zip and vmp File.WriteAllText(t.FullName, JsonConvert.SerializeObject(topic)); //topic.index = folderFiles.Length; if (File.Exists(t.FullName.Replace(oldTopicName, newTopicName))) { File.Delete(t.FullName.Replace(oldTopicName, newTopicName)); } Thread.Sleep(100); File.Move(t.FullName, t.FullName.Replace(oldTopicName, newTopicName)); } if (!checkIndex) { List <TopicModel> topicModels = new List <TopicModel>(); foreach (FileInfo t in folder.GetFiles()) { TopicModel topic = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(t.FullName)); topic.infoPath = t.FullName; topicModels.Add(topic); } topicModels = topicModels.OrderBy(t => t.index).ToList(); for (int i = 0; i < topicModels.Count; i++) { if (topicModels[i].index != i) { topicModels[i].index = i; File.WriteAllText(topicModels[i].infoPath, JsonConvert.SerializeObject(topicModels[i])); } } } } } }