Exemple #1
0
        private void SyncStatus(int index)
        {
            labelBGStyle.normal.background = delFolders.Contains(index)
                ? bgDarkRed
                : bgDarkGray;

            EditorGUILayout.BeginHorizontal(labelBGStyle);
            {
                FolderSyncData data = syncData[index];
                Label(data.added.Count + " added",
                      deleteFolders ? labelLightGray : labelGreen);
                Label(data.modified.Count + " changed",
                      deleteFolders ? labelLightGray : labelOrange);
                Label(data.deleted.Count + " deleted",
                      deleteFolders ? labelLightGray : labelRed);
            }
            EditorGUILayout.EndHorizontal();
        }
Exemple #2
0
        static public void Sync(SerializedObject so)
        {
            FolderSyncData[]   sync   = GetSyncStatus(so);
            SerializedProperty local  = GetLocalFolders(so);
            SerializedProperty remote = GetRemoteFolders(so);

            int folders = sync.Length;

            for (int i = 0; i < folders; i++)
            {
                FolderSyncData data         = sync[i];
                string         remoteFolder = remote.GetArrayElementAtIndex(i).stringValue;
                string         localFolder  = local.GetArrayElementAtIndex(i).stringValue;
                int            totalFiles   = data.added.Count + data.modified.Count + data.deleted.Count;

                int al = data.added.Count;
                for (int a = 0; a < al; a++)
                {
                    string target = localFolder + data.added[a].Replace(remoteFolder, "");
                    File.Copy(data.added[a], target, true);
                    Progressbar(remoteFolder, i, folders, a / totalFiles);
                }

                int ml = data.modified.Count;
                for (int m = 0; m < ml; m++)
                {
                    string target = localFolder + data.modified[m].Replace(remoteFolder, "");
                    File.Copy(data.modified[m], target, true);
                    Progressbar(remoteFolder, i, folders, (m + al) / totalFiles);
                }

                int dl = data.deleted.Count;
                for (int d = 0; d < dl; d++)
                {
                    File.Delete(data.deleted[d]);
                    Progressbar(localFolder, i, folders, (d + al + ml) / totalFiles);
                }
            }

            EditorUtility.ClearProgressBar();
            AssetDatabase.Refresh();
        }
Exemple #3
0
        static public FolderSyncData[] GetSyncStatus(SerializedObject so)
        {
            List <FolderSyncData> dataList = new List <FolderSyncData>();
            int numFolders             = NumFolders(so);
            SerializedProperty locals  = GetLocalFolders(so);
            SerializedProperty remotes = GetRemoteFolders(so);

            for (int i = 0; i < numFolders; i++)
            {
                SerializedProperty localProp = locals.GetArrayElementAtIndex(i);
                bool          localUndef     = localProp.stringValue == "Undefined";
                List <string> localFiles     = localUndef
                    ? new List <string>()
                    : GetFiles(localProp.stringValue);

                SerializedProperty remoteProp = remotes.GetArrayElementAtIndex(i);
                bool          remoteUndef     = remoteProp.stringValue == "Undefined";
                List <string> remoteFiles     = remoteUndef
                    ? new List <string>()
                    : GetFiles(remoteProp.stringValue);

                FolderSyncData data = new FolderSyncData();

                for (int n = 0; n < remoteFiles.Count; n++)
                {
                    string remoteFile = remoteFiles[n];
                    string curFile    = localProp.stringValue +
                                        remoteFile.Replace(remoteProp.stringValue, "");

                    int fi = localFiles.IndexOf(curFile);
                    if (fi >= 0)
                    {
                        string   localFile  = localFiles[fi];
                        DateTime localDate  = File.GetLastWriteTimeUtc(localFile);
                        DateTime remoteDate = File.GetLastWriteTimeUtc(remoteFile);
                        // dateDiff < 0 : remote is older than local
                        // dateDiff = 0 : remote is same as local
                        // dateDiff > 0 : remote is newer than local
                        int dateDiff = DateTime.Compare(remoteDate, localDate);
                        if (dateDiff > 0)
                        {
                            data.modified.Add(remoteFile);
                        }
                    }
                    else
                    {
                        if (!localUndef)
                        {
                            data.added.Add(remoteFile);
                        }
                    }
                }

                for (int j = 0; j < localFiles.Count; j++)
                {
                    string localFile = localFiles[j];
                    string curFile   = remoteProp.stringValue +
                                       localFile.Replace(localProp.stringValue, "");
                    if (!remoteFiles.Contains(curFile))
                    {
                        data.deleted.Add(localFile);
                    }
                }

                dataList.Add(data);
            }
            return(dataList.ToArray());
        }