Exemple #1
0
        public static void PerfomCopies()
        {
            EditorProfileData data = EditorProfileData.active;

            if (data == null)
            {
                EditorUtility.DisplayDialog("No Profile Selected", "Select an active profile first: Select an Editor Profile Asset and click 'Activate' in inspector.", "Ok");
                return;
            }
            EditorProfileData.KeyString src = data.getString("filePatcher.default");

            int changed = 0;

            string[] lines = src.value.Split(new char[] { '|' });
            for (int i = 0; i < lines.Length; i++)
            {
                String line = lines[i];
                if (line.Length == 0)
                {
                    continue;                                       //skip any empty
                }
                string[] elements = line.Split(new char[] { '>' }); //syntax: fromFile>toFile>settingsInt
                //Skip incomplete
                if (elements.Length == 0)
                {
                    continue;
                }
                else if (elements.Length == 1)
                {
                    continue;
                }
                else if (elements.Length == 2)
                {
                    elements = new string[] { elements[0], elements[1], "" }
                }
                ;                                                                                        //if only flags are missing, allow processing with default flags
                StringFlags f = new StringFlags(elements[2]);

                if (!f.active)
                {
                    Debug.Log("Skip (disabled): " + elements[0]); continue;
                }
                if (!File.Exists(elements[0]))
                {
                    Debug.LogWarning("File not found: " + elements[0]); continue;
                }
                if (!File.Exists(elements[1]))
                {
                    Debug.LogWarning("File not found: " + elements[1]); continue;
                }

                try
                {
                    EditorUtility.DisplayCancelableProgressBar("FilePatcher", elements[1] + " to " + elements[0], i / lines.Length);
                    File.Copy(elements[1], elements[0], true);
                    Debug.Log("Copied " + elements[1] + " to " + elements[0]);
                    changed += 1;
                }
                catch (Exception ex)
                {
                    Debug.LogError("Could not copy " + elements[1] + " to " + elements[0] + ": " + ex.Message);
                }
            }
            EditorUtility.ClearProgressBar();
            if (src.value.Length == 0)
            {
                EditorUtility.DisplayDialog("Entries missing", "There are no File Patcher entries in the active profile. Select files in Assets and add them via context menu to the current profile.", "Ok");
            }
            else if (changed == 0)
            {
                EditorUtility.DisplayDialog("Nothing happened", "No files where changed. Check console for reasons.", "Ok");
            }
            else
            {
                AssetDatabase.Refresh();
            }
        }
    }
Exemple #2
0
        private static void EditorProfileDataEditor_onDrawSubEditor(EditorProfileData data)
        {
            open = EditorGUILayout.Foldout(open, "File Patcher");
            if (open)
            {
                EditorProfileData.KeyString src = data.getString("filePatcher.default");
                if (src == null)
                {
                    EditorGUILayout.HelpBox("No entries.", MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox("Patching is executed when you select the patch command from menu " + Main.MenuFolderLabel + ".", MessageType.Info);
                    string[] lines = src.value.Split(new char[] { '|' });
                    EditorGUILayout.BeginVertical();
                    for (int i = 0; i < lines.Length; i++)
                    {
                        String line = lines[i];
                        if (line.Length == 0 && i == lines.Length - 1)
                        {
                            continue;                                       //skip empty last one
                        }
                        string[] elements = line.Split(new char[] { '>' }); //syntax: fromFile>toFile>settingsInt
                        //Fill up any missing elements:
                        if (elements.Length == 0)
                        {
                            elements = new string[] { "", "", "0" }
                        }
                        ;
                        else if (elements.Length == 1)
                        {
                            elements = new string[] { elements[0], "", "0" }
                        }
                        ;
                        else if (elements.Length == 2)
                        {
                            elements = new string[] { elements[0], elements[1], "0" }
                        }
                        ;

                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        StringFlags f = new StringFlags(elements[2]);
                        GUI.changed = false;
                        EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
                        f.active = EditorGUILayout.ToggleLeft("Replace file", f.active, GUILayout.ExpandWidth(true));
                        //EditorGUILayout.LabelField("Replace file "+(f.active ? "" : "[Disabled]"), (f.active?EditorStyles.boldLabel:EditorStyles.label), GUILayout.ExpandWidth(true));
                        if (GUILayout.Button(new GUIContent("×", "Delete this entry"), GUILayout.Width(20)))
                        {
                            Undo.RecordObject(data, "Delete FilePatcher entry from " + data.name);
                            List <String> l = lines.ToList();
                            l.RemoveAt(i);
                            lines     = l.ToArray();
                            src.value = string.Join("|", lines);
                            break;
                        }
                        EditorGUILayout.EndHorizontal();
                        GUIStyle padded = new GUIStyle(); padded.padding = new RectOffset(16, 0, 0, 0);
                        EditorGUILayout.BeginVertical(padded);
                        elements[0] = EditorGUILayout.TextField(elements[0]);
                        EditorGUILayout.LabelField("with file", EditorStyles.miniLabel);
                        EditorGUILayout.BeginHorizontal();
                        elements[1] = EditorGUILayout.TextField(elements[1]);
                        if (GUILayout.Button(new GUIContent("...", "Browse file system"), EditorStyles.miniButton, GUILayout.Width(22)))
                        {
                            string path = "";
                            try { path = Path.GetDirectoryName(elements[1]); } catch { path = ""; }            //if path holds a filename, we try to open the file picker dialog in the file's folder.
                            path = EditorUtility.OpenFilePanel("Select File Path", path, "");
                            if (path.Length != 0)
                            {
                                elements[1] = path;
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                        f.checkVersion = EditorGUILayout.ToggleLeft(new GUIContent("Check Version", "For DLLs version numbers can be compared. If this is checked, then the file will only be copied when the version numbers differ."), f.checkVersion);
                        //EditorGUILayout.LabelField(f.ToString());
                        EditorGUILayout.EndVertical();
                        EditorGUILayout.EndHorizontal();
                        if (GUI.changed)
                        {
                            elements[2] = f.ToString();
                            lines[i]    = string.Join(">", elements);
                            src.value   = string.Join("|", lines);
                            break;
                        }
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUILayout.HelpBox("To add a new entry select the file(s) in Project View and add it via context menu to the active profile.", MessageType.Info);

                /*UnityEngine.Object newObj = null;
                 * newObj=EditorGUILayout.ObjectField("Add entry for asset:", newObj, typeof(UnityEngine.Object), false);
                 * if (newObj!=null)
                 * {
                 *  Debug.Log("Adding new: "+newObj);
                 * }*/
            }
        }