コード例 #1
0
        private static void Show(string topicPath, string vnp, string appName, string webRootPath, Action onAppStart, Action <object, EventArgs> onAppExit)
        {
            string cortonaCachePath = "C:/ProgramData/ParallelGraphics/VM/TC_Cache";

            if (Directory.Exists(cortonaCachePath))
            {
                try
                {
                    PathHelper.ForceDeleteFolderContentRecursively(cortonaCachePath);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Error cleaning folder {cortonaCachePath}");
                }
            }

            ExternalProgram external = new ExternalProgram();

            TopicModel    model    = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(topicPath));
            OldTopicModel oldModel = JsonConvert.DeserializeObject <OldTopicModel>(File.ReadAllText(topicPath));

            if (!string.IsNullOrEmpty(oldModel.pathToZip))
            {
                model.localization = "default";
                model.pathToZip    = oldModel.pathToZip;
            }
            if (!string.IsNullOrEmpty(oldModel.vmpPath))
            {
                model.localization = "default";
                model.vmpPath      = oldModel.vmpPath;
            }

            if (!File.Exists(appName))
            {
                _logger.LogError($"Error opening Cortona, file doesn't exist: {appName}");
                return;
            }

            external.ShowApp(appName, vnp, webRootPath, onAppExit);

            model.isOpened = 1;
            onAppStart();

            File.WriteAllText(topicPath, JsonConvert.SerializeObject(model));
        }
コード例 #2
0
        public static List <TopicModel> GetTopicsOrigin(string scenario_id)
        {
            string scenarioRootFolder = FindFolderById(scenario_id, PathHelper.GetRepoPath());

            EnsureScenarioFoldersExist(scenarioRootFolder);

            var topicsDirectory = Path.Combine(scenarioRootFolder, "topics");
            var objects         = new List <TopicModel>();

            foreach (string t in Directory.GetFiles(topicsDirectory))
            {
                TopicModel    topic    = JsonConvert.DeserializeObject <TopicModel>(File.ReadAllText(t));
                OldTopicModel oldTopic = JsonConvert.DeserializeObject <OldTopicModel>(File.ReadAllText(t));
                if (!string.IsNullOrEmpty(oldTopic.pathToZip))
                {
                    topic.localization = "default";
                    topic.pathToZip    = oldTopic.pathToZip;
                }

                if (!string.IsNullOrEmpty(oldTopic.vmpPath))
                {
                    topic.localization = "default";
                    topic.vmpPath      = oldTopic.vmpPath;
                }

                if (string.IsNullOrEmpty(topic.pathToZip) && !string.IsNullOrEmpty(topic.pathToZipDEFAULT))
                {
                    topic.pathToZip = topic.pathToZipDEFAULT;
                    File.WriteAllText(t, JsonConvert.SerializeObject(topic));
                }

                topic.infoPath = t;
                objects.Add(topic);
            }

            return(objects);
        }
コード例 #3
0
        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]));
                            }
                        }
                    }
                }
            }
        }