Esempio n. 1
0
        public static void Copy(string from, string to, CopyProperties copyProp, int iter = 100)
        {
            if (to[to.Length - 1] != '\\')
            {
                to += '\\';
            }

            string fileName = Path.GetFileName(from);

            to += fileName;
            try
            {
                File.Copy(from, to);
            }
            catch (IOException ex) when(ex.HResult == -2147024816)
            {
                if (copyProp == CopyProperties.ReWrite)
                {
                    File.Delete(to);
                    File.Copy(from, to);
                }
                else if (copyProp == CopyProperties.NewName)
                {
                    string path    = Path.GetDirectoryName(to);
                    string ext     = Path.GetExtension(to);
                    string name    = Path.GetFileNameWithoutExtension(to);
                    bool   errFlag = false;
                    for (int i = 1; i <= iter; i++)
                    {
                        string new_to = $"{path}\\{name}_({i}){ext}";
                        if (!File.Exists(new_to))
                        {
                            try
                            {
                                File.Copy(from, new_to);
                            }
                            catch (IOException exx) when(exx.HResult == -2147024816)
                            {
                                errFlag = true;
                            }

                            if (errFlag == false)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
    public override void OnInspectorGUI()
    {
        CopyProperties myTarget = (CopyProperties)target;

        // Show default inspector property editor
        DrawDefaultInspector();

        if (GUILayout.Button("Copy"))
        {
            isCopied = true;
            text     = myTarget.GetProperties();
        }
        if (isCopied)
        {
            scroll = EditorGUILayout.BeginScrollView(scroll);
            text   = EditorGUILayout.TextArea(text, GUILayout.Height(200));
            EditorGUILayout.EndScrollView();
        }
    }