protected FilePropertyEditor(IPropertyEditorParams editorParams, string[] allowedFileTypes) : base(editorParams) { ContainerWidget.AddNode(new Widget { Layout = new HBoxLayout(), Nodes = { (editor = editorParams.EditBoxFactory()), new HSpacer(4), (button = new ThemedButton { Text = "...", MinMaxWidth = 20, LayoutCell = new LayoutCell(Alignment.Center) }) } }); editor.LayoutCell = new LayoutCell(Alignment.Center); editor.Submitted += text => AssignAsset(AssetPath.CorrectSlashes(text)); button.Clicked += () => { var dlg = new FileDialog { AllowedFileTypes = allowedFileTypes, Mode = FileDialogMode.Open, InitialDirectory = Directory.Exists(LastOpenedDirectory) ? LastOpenedDirectory : Project.Current.GetSystemDirectory(Document.Current.Path), }; if (dlg.RunModal()) { SetFilePath(dlg.FileName); LastOpenedDirectory = Project.Current.GetSystemDirectory(dlg.FileName); } }; }
public ParsedNode(Node node, string name, bool isInExternalScene) { Id = node.Id; Name = name; Type = node.GetType().Name; TypeFullName = node.GetType().FullName; ClassName = name; FieldName = "_" + name; ContentsPath = AssetPath.CorrectSlashes(node.ContentsPath ?? ""); IsInExternalScene = isInExternalScene; if (IsExternalScene) { string externalName; string externalBaseName; ScenesCodeCooker.ParseCommonName(Path.GetFileNameWithoutExtension(ContentsPath), out externalName, out externalBaseName); ClassName = externalName; } foreach (var animation in node.Animations) { var isDefault = animation == node.DefaultAnimation; foreach (var marker in animation.Markers.Where(marker => !string.IsNullOrEmpty(marker.Id))) { if (isDefault) { Markers.Add(marker.Id); } NamedMarkers.Add(new AnimationMarker(animation.Id, marker.Id)); } } }
public bool DocumentExists(string path) { if (string.IsNullOrEmpty(path)) { return(false); } return(GetFullPath(AssetPath.CorrectSlashes(path), out var fullPath) && File.Exists(fullPath)); }
private void SetFilePath(string path) { string asset, type; if (Utils.ExtractAssetPathOrShowAlert(path, out asset, out type)) { AssignAsset(AssetPath.CorrectSlashes(asset)); } }
public void Start() { Console.WriteLine("Generating scenes code for {0} scenes...", scenes.Count); var generatedScenesPath = $"{directory}/{projectName}.GeneratedScenes"; if (!Directory.Exists(generatedScenesPath)) { GenerateProjectFiles(generatedScenesPath); } var scenesPath = $@"{directory}/{projectName}.GeneratedScenes/Scenes"; if (Directory.Exists(scenesPath)) { RetryUntilSuccessDeleteDirectory(scenesPath); } var sceneToFrameTree = new List <Tuple <string, ParsedFramesTree> >(); foreach (var scene in scenes) { var bundleName = sceneToBundleMap[scene.Key]; var bundleSourcePath = $"{scenesPath}/{bundleName}"; if (!Directory.Exists(bundleSourcePath)) { RetryUntilSuccessCreateDirectory(bundleSourcePath); } currentCookingScene = scene.Key; var parsedFramesTree = GenerateParsedFramesTree(scene.Key, scene.Value); sceneToFrameTree.Add(new Tuple <string, ParsedFramesTree>(scene.Key, parsedFramesTree)); } foreach (var kv in sceneToFrameTree) { var parsedFramesTree = kv.Item2; currentCookingScene = kv.Item1; var k = Path.ChangeExtension(kv.Item1, null); k = AssetPath.CorrectSlashes(k); var id = scenes[kv.Item1].Id; var useful = parsedFramesTree.ParsedNodes.Count > 0 || parsedFramesTree.InnerClasses.Count > 0 || (id != null && id.StartsWith("@")); if (!useful && !referringScenes.ContainsKey(k)) { continue; } var bundleName = sceneToBundleMap[kv.Item1]; var bundleSourcePath = $"{scenesPath}/{bundleName}"; var code = parsedFramesTree.GenerateCode(this); code = code.Replace("<%PROJECT_NAME%>", projectName); code = code.Replace("<%NAMESPACE%>", GetBundleNamespace(bundleName)); code = new CodeFormatter(code).FormattedCode; File.WriteAllText(bundleSourcePath + "/" + parsedFramesTree.ClassName + ".cs", code); } GenerateCommonParts(scenesPath); }
private void RegisterModifiedAsset(string path) { if (!TryGetAssetPath(path, out var localPath)) { return; } localPath = AssetPath.CorrectSlashes(localPath); modifiedAssets.Add(localPath); Current.SceneCache.InvalidateEntryFromFilesystem(localPath); Tasks.StopByTag(aggregateModifiedAssetsTaskTag); Tasks.Add(AggregateModifiedAssetsTask, aggregateModifiedAssetsTaskTag); }
private void AddReferringSceneSafe(string externalScene, string referringScene) { externalScene = AssetPath.CorrectSlashes(externalScene); referringScene = AssetPath.CorrectSlashes(referringScene); if (!referringScenes.ContainsKey(externalScene)) { var l = new List <string>(); referringScenes.Add(externalScene, l); } referringScenes[externalScene].Add(referringScene); }
private bool IsCookingRulesFileItself(string path) { path = AssetPath.CorrectSlashes(path); if (File.GetAttributes(path) == FileAttributes.Directory) { return(false); } bool isPerDirectory = Path.GetFileName(path) == CookingRulesBuilder.CookingRulesFilename; bool isPerFile = path.EndsWith(".txt") && File.Exists(path.Remove(path.Length - 4)); return(isPerDirectory || isPerFile); }
private string GetLocalDocumentPath(string path, bool pathIsAbsolute) { string localPath = path; if (pathIsAbsolute) { if (this == Null || !Current.TryGetAssetPath(path, out localPath)) { return(null); } } return(AssetPath.CorrectSlashes(localPath)); }
private void RegisterModifiedAsset(string path) { string localPath; if (!TryGetAssetPath(path, out localPath)) { return; } localPath = AssetPath.CorrectSlashes(localPath); modifiedAssets.Add(localPath); Tasks.StopByTag(aggregateModifiedAssetsTaskTag); Tasks.Add(AggregateModifiedAssetsTask, aggregateModifiedAssetsTaskTag); }
public static bool ExtractAssetPathOrShowAlert(string filePath, out string assetPath, out string assetType) { if (!filePath.StartsWith(Core.Project.Current.AssetsDirectory, StringComparison.CurrentCultureIgnoreCase)) { AlertDialog.Show($"Asset '{filePath}' outside the project directory"); assetPath = null; assetType = null; return(false); } else { var localPath = filePath.Substring(Core.Project.Current.AssetsDirectory.Length + 1); assetPath = System.IO.Path.ChangeExtension(AssetPath.CorrectSlashes(localPath), null); assetType = System.IO.Path.GetExtension(localPath).ToLower(); return(true); } }
private void SetFilePath(string path) { string asset, type; if (Utils.ExtractAssetPathOrShowAlert(path, out asset, out type) && Utils.AssertCurrentDocument(asset, type)) { if (!IsValid(asset)) { AlertDialog.Show($"Asset '{asset}' missing or path contains characters other than latin letters and digits."); } else { AssignAsset(AssetPath.CorrectSlashes(asset)); } } }
private void InitializeRemoteScriptingPreferences() { try { var projectJson = Orange.The.Workspace.ProjectJson.AsDynamic; var projectDirectory = Orange.The.Workspace.ProjectDirectory; ScriptsPath = AssetPath.CorrectSlashes(Path.Combine(projectDirectory, (string)projectJson.RemoteScripting.ScriptsPath)); ScriptsAssemblyName = (string)projectJson.RemoteScripting.ScriptsAssemblyName; var scriptsReferencesPath = Path.Combine(projectDirectory, (string)projectJson.RemoteScripting.ReferencesPath); foreach (string reference in projectJson.RemoteScripting.References) { scriptReferences.Add(AssetPath.CorrectSlashes(Path.Combine(scriptsReferencesPath, reference))); } EntryPointsClass = (string)projectJson.RemoteScripting.EntryPointsClass; RemoteStoragePath = AssetPath.CorrectSlashes(Path.Combine(projectDirectory, (string)projectJson.RemoteScripting.RemoteStoragePath)); Console.WriteLine("Remote scripting preferences was successfully loaded."); } catch { InitializeDefaultRemoteScriptingPreferences(); } }
private string GetBundleNameOfExternalScene(ParsedNode node) { var bundleName = string.Empty; var scenePath = AssetPath.CorrectSlashes(node.ContentsPath); foreach (var sceneExtension in scenesExtensions) { string sceneBundle; if (!sceneToBundleMap.TryGetValue(scenePath + sceneExtension, out sceneBundle)) { continue; } bundleName = sceneBundle; break; } if (string.IsNullOrEmpty(bundleName)) { Console.WriteLine("Warning! Can not find external scene \'{0}\' in \'{1}!\'", scenePath, currentCookingScene); } return(bundleName); }
public Document OpenDocument(string path, bool pathIsGlobal = false) { string localPath = path; if (pathIsGlobal) { if (this == Null || !Current.TryGetAssetPath(path, out localPath)) { OpenFileOutsideProjectAttempt(path); return(null); } } localPath = AssetPath.CorrectSlashes(localPath); var doc = Documents.FirstOrDefault(i => i.Path == localPath); if (doc == null) { var tmpFile = AutosaveProcessor.GetTemporalFilePath(localPath); string systemPath; if (GetSystemPath(tmpFile, out systemPath) && TempFileLoadConfirmation.Invoke(localPath)) { doc = new Document(tmpFile); doc.SaveAs(localPath); } else { doc = new Document(localPath); } if (systemPath != null) { File.Delete(systemPath); } documents.Add(doc); } doc.MakeCurrent(); AddRecentDocument(doc.Path); return(doc); }
public static bool ExtractAssetPathOrShowAlert(string filePath, out string assetPath, out string assetType) { string path = AssetPath.CorrectSlashes(filePath); string assetsPath = AssetPath.CorrectSlashes(Core.Project.Current.AssetsDirectory); if (Path.IsPathRooted(path)) { if (!path.StartsWith(assetsPath, StringComparison.CurrentCultureIgnoreCase)) { AlertDialog.Show($"Asset '{filePath}' outside the project directory"); assetPath = null; assetType = null; return(false); } else { path = path.Substring(assetsPath.Length + 1); } } assetPath = Path.ChangeExtension(path, null); assetType = Path.GetExtension(path).ToLower(); return(true); }
protected override void Paste() { try { AssignAsset(AssetPath.CorrectSlashes(Clipboard.Text)); } catch (System.Exception) { } }
private void SetPathPrefix(string oldPrefix, string prefix) => this.SetProperty <T>(current => StringToValueConverter(AssetPath.CorrectSlashes( Path.Combine(prefix, ValueToStringConverter(current).Substring(oldPrefix.Length).TrimStart('/')))));
public void Start() { Console.WriteLine("Generating scenes code for {0} scenes...", scenesForProcessing.Count); var generatedScenesPath = $"{directory}/{projectName}.GeneratedScenes"; if (!Directory.Exists(generatedScenesPath)) { GenerateProjectFiles(generatedScenesPath); } var scenesPath = $@"{directory}/{projectName}.GeneratedScenes/Scenes"; RemoveOrphanedGeneratedCodeItems(); RemoveUpdatingCommonPartsFromCache(); foreach (var scenePath in allScenes) { externalSceneToOriginalScenePath.Add(Path.ChangeExtension(scenePath, null), scenePath); } var sceneToFrameTree = new List <Tuple <string, ParsedFramesTree> >(); foreach (var scene in scenesForProcessing) { var bundleName = sceneToBundleMap[scene.Key]; var bundleSourcePath = $"{scenesPath}/{bundleName}"; if (!Directory.Exists(bundleSourcePath)) { RetryUntilSuccessCreateDirectory(bundleSourcePath); } currentCookingScene = scene.Key; var parsedFramesTree = GenerateParsedFramesTree(scene.Key, scene.Value); sceneToFrameTree.Add(new Tuple <string, ParsedFramesTree>(scene.Key, parsedFramesTree)); } foreach (var kv in sceneToFrameTree) { var parsedFramesTree = kv.Item2; currentCookingScene = kv.Item1; var k = Path.ChangeExtension(kv.Item1, null); k = AssetPath.CorrectSlashes(k); var id = scenesForProcessing[kv.Item1].Id; var bundleName = sceneToBundleMap[kv.Item1]; var bundleSourcePath = $"{scenesPath}/{bundleName}"; var generatedCodePath = bundleSourcePath + "/" + parsedFramesTree.ClassName + ".cs"; var useful = parsedFramesTree.ParsedNodes.Count > 0 || parsedFramesTree.InnerClasses.Count > 0 || (id != null && (id.StartsWith("@") || id.StartsWith(">"))); if (!useful) { if (File.Exists(generatedCodePath)) { File.Delete(generatedCodePath); } continue; } var code = parsedFramesTree.GenerateCode(this); code = code.Replace("<%PROJECT_NAME%>", projectName); code = code.Replace("<%NAMESPACE%>", GetBundleNamespace(bundleName)); code = new CodeFormatter(code).FormattedCode; File.WriteAllText(generatedCodePath, code); } UpdateCache(); // Collect not loaded scenes which are also contains common parts affected by actually modified and referred to them scenes // Because we need those to correctly update common parts. i.e. to calc common parts you need all of common parts referrers List <string> reprocessScenes = new List <string>(); foreach (var kv in codeCookerCache.CommonPartToReferredScenes) { if (commonParts.ContainsKey(kv.Key)) { foreach (var scene in kv.Value) { if (!modifiedScenes.Contains(scene)) { reprocessScenes.Add(scene); } } } } foreach (var scene in reprocessScenes) { GenerateParsedFramesTree(scene, Node.CreateFromAssetBundle(scene)); } GenerateCommonParts(scenesPath); UpdateCommonPartsCache(); }
private static bool IsInAssetDir(string path) { return(AssetPath.CorrectSlashes(path).StartsWith(AssetPath.CorrectSlashes(The.Workspace.AssetsDirectory))); }
private static CookingRules GetAssociatedCookingRules(CookingRulesCollection crc, string path, bool createIfNotExists = false) { Action <string, CookingRules> ignoreRules = (p, r) => { r = r.InheritClone(); r.Ignore = true; crc[NormalizePath(p)] = r; }; path = AssetPath.CorrectSlashes(path); string key = NormalizePath(path); CookingRules cr = null; if (File.GetAttributes(path) == FileAttributes.Directory) { // Directory var crPath = AssetPath.Combine(path, Orange.CookingRulesBuilder.CookingRulesFilename); if (crc.ContainsKey(key)) { cr = crc[key]; if (cr.SourceFilename != crPath) { if (createIfNotExists) { cr = cr.InheritClone(); crc[key] = cr; ignoreRules(crPath, cr); } else { return(null); } } } else { throw new Lime.Exception("CookingRule record for directory should already be present in collection"); } cr.SourceFilename = crPath; } else { bool isPerDirectory = Path.GetFileName(path) == CookingRulesBuilder.CookingRulesFilename; bool isPerFile = path.EndsWith(".txt") && File.Exists(path.Remove(path.Length - 4)); string filename = isPerFile ? path.Remove(path.Length - 4) : path; if (isPerDirectory || isPerFile) { // Cooking Rules File itself if (crc.ContainsKey(key)) { cr = crc[key].Parent; } else { throw new Lime.Exception("CookingRule record for cooking rules file itself should already be present in collection"); } } else { // Regular File var crPath = path + ".txt"; var crKey = NormalizePath(crPath); if (crc.ContainsKey(crKey)) { cr = crc[crKey].Parent; } else if (!createIfNotExists) { return(null); } else if (crc.ContainsKey(NormalizePath(path))) { cr = crc[NormalizePath(path)].InheritClone(); cr.SourceFilename = crPath; ignoreRules(crPath, cr); crc[key] = cr; } else { throw new Lime.Exception("CookingRule record for any regular file should already be present in collection"); } } } return(cr); }