Commit 1c847220 authored by jang dong hyeok's avatar jang dong hyeok
Browse files

.

parent 076f0c68
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using PlasticGui;
using Unity.PlasticSCM.Editor.UI.Tree;
namespace Unity.PlasticSCM.Editor.Views.PendingChanges
{
internal enum PendingChangesTreeColumn
{
Item,
Status,
Size,
Extension,
Type,
DateModififed,
Repository
}
[Serializable]
internal class PendingChangesTreeHeaderState : MultiColumnHeaderState, ISerializationCallbackReceiver
{
internal static PendingChangesTreeHeaderState GetDefault(bool isGluonMode)
{
PendingChangesTreeHeaderState headerState =
new PendingChangesTreeHeaderState(BuildColumns());
headerState.visibleColumns = GetDefaultVisibleColumns();
SetMode(headerState, isGluonMode);
return headerState;
}
internal static List<string> GetColumnNames()
{
List<string> result = new List<string>();
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.ItemColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.StatusColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.SizeColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.ExtensionColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.TypeColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.DateModifiedColumn));
result.Add(PlasticLocalization.GetString(PlasticLocalization.Name.RepositoryColumn));
return result;
}
internal static string GetColumnName(PendingChangesTreeColumn column)
{
switch (column)
{
case PendingChangesTreeColumn.Item:
return PlasticLocalization.GetString(PlasticLocalization.Name.ItemColumn);
case PendingChangesTreeColumn.Status:
return PlasticLocalization.GetString(PlasticLocalization.Name.StatusColumn);
case PendingChangesTreeColumn.Size:
return PlasticLocalization.GetString(PlasticLocalization.Name.SizeColumn);
case PendingChangesTreeColumn.Extension:
return PlasticLocalization.GetString(PlasticLocalization.Name.ExtensionColumn);
case PendingChangesTreeColumn.Type:
return PlasticLocalization.GetString(PlasticLocalization.Name.TypeColumn);
case PendingChangesTreeColumn.DateModififed:
return PlasticLocalization.GetString(PlasticLocalization.Name.DateModifiedColumn);
case PendingChangesTreeColumn.Repository:
return PlasticLocalization.GetString(PlasticLocalization.Name.RepositoryColumn);
default:
return null;
}
}
internal static void SetMode(MultiColumnHeaderState state, bool isGluonMode)
{
List<int> result = state.visibleColumns.ToList();
if (!result.Contains((int)PendingChangesTreeColumn.Item))
result.Add((int)PendingChangesTreeColumn.Item);
if (isGluonMode)
result.Remove((int)PendingChangesTreeColumn.Type);
state.columns[(int)PendingChangesTreeColumn.Item].allowToggleVisibility = false;
state.columns[(int)PendingChangesTreeColumn.Type].allowToggleVisibility = !isGluonMode;
state.visibleColumns = result.ToArray();
}
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (mHeaderTitles != null)
TreeHeaderColumns.SetTitles(columns, mHeaderTitles);
if (mColumsAllowedToggleVisibility != null)
TreeHeaderColumns.SetVisibilities(columns, mColumsAllowedToggleVisibility);
}
void ISerializationCallbackReceiver.OnBeforeSerialize()
{
}
static int[] GetDefaultVisibleColumns()
{
List<int> result = new List<int>();
result.Add((int)PendingChangesTreeColumn.Item);
result.Add((int)PendingChangesTreeColumn.Status);
result.Add((int)PendingChangesTreeColumn.DateModififed);
return result.ToArray();
}
static Column[] BuildColumns()
{
return new Column[]
{
new Column()
{
width = 800,
headerContent = new GUIContent(
GetColumnName(PendingChangesTreeColumn.Item)),
minWidth = 200
},
new Column()
{
width = 200,
headerContent = new GUIContent(
GetColumnName(PendingChangesTreeColumn.Status)),
minWidth = 80
},
new Column()
{
width = 80,
headerContent = new GUIContent(
GetColumnName(PendingChangesTreeColumn.Size)),
minWidth = 45
},
new Column()
{
width = 70,
headerContent = new GUIContent(
GetColumnName(PendingChangesTreeColumn.Extension)),
minWidth = 50
},
new Column()
{
width = 60,
headerContent = new GUIContent(
GetColumnName(PendingChangesTreeColumn.Type)),
minWidth = 45
},
new Column()
{
width = 330,
headerContent = new GUIContent(
GetColumnName(PendingChangesTreeColumn.DateModififed)),
minWidth = 100
},
new Column()
{
width = 210,
headerContent = new GUIContent(
GetColumnName(PendingChangesTreeColumn.Repository)),
minWidth = 90
}
};
}
PendingChangesTreeHeaderState(Column[] columns)
: base(columns)
{
if (mHeaderTitles == null)
mHeaderTitles = TreeHeaderColumns.GetTitles(columns);
if (mColumsAllowedToggleVisibility == null)
mColumsAllowedToggleVisibility = TreeHeaderColumns.GetVisibilities(columns);
}
[SerializeField]
string[] mHeaderTitles;
[SerializeField]
bool[] mColumsAllowedToggleVisibility;
}
}
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
using Codice.Client.BaseCommands;
using Codice.Client.Common;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WorkspaceWindow.PendingChanges;
using Unity.PlasticSCM.Editor.AssetUtils;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.UI.Tree;
using Unity.PlasticSCM.Editor.AssetsOverlays.Cache;
using Unity.PlasticSCM.Editor.AssetsOverlays;
namespace Unity.PlasticSCM.Editor.Views.PendingChanges
{
internal class PendingChangesTreeView : TreeView
{
internal PendingChangesTreeView(
WorkspaceInfo wkInfo,
bool isGluonMode,
PendingChangesTreeHeaderState headerState,
List<string> columnNames,
PendingChangesViewMenu menu,
IAssetStatusCache assetStatusCache)
: base(new TreeViewState())
{
mWkInfo = wkInfo;
mIsGluonMode = isGluonMode;
mColumnNames = columnNames;
mMenu = menu;
mAssetStatusCache = assetStatusCache;
mPendingChangesTree = new UnityPendingChangesTree();
multiColumnHeader = new PendingChangesMultiColumnHeader(
headerState, mPendingChangesTree);
multiColumnHeader.canSort = true;
multiColumnHeader.sortingChanged += SortingChanged;
customFoldoutYOffset = UnityConstants.TREEVIEW_FOLDOUT_Y_OFFSET;
rowHeight = UnityConstants.TREEVIEW_ROW_HEIGHT;
showAlternatingRowBackgrounds = true;
mCooldownFilterAction = new CooldownWindowDelayer(
DelayedSearchChanged, UnityConstants.SEARCH_DELAYED_INPUT_ACTION_INTERVAL);
}
protected override void SelectionChanged(IList<int> selectedIds)
{
if (mIsSelectionChangedEventDisabled)
return;
List<UnityEngine.Object> assets = new List<UnityEngine.Object>();
foreach (ChangeInfo changeInfo in GetSelectedChanges(false))
{
UnityEngine.Object asset = LoadAsset.FromChangeInfo(changeInfo);
if (asset == null)
continue;
assets.Add(asset);
}
UnityEditor.Selection.objects = assets.ToArray();
}
public override IList<TreeViewItem> GetRows()
{
return mRows;
}
public override void OnGUI(Rect rect)
{
base.OnGUI(rect);
Event e = Event.current;
if (e.type != EventType.KeyDown)
return;
bool isProcessed = mMenu.ProcessKeyActionIfNeeded(e);
if (isProcessed)
e.Use();
}
protected override bool CanChangeExpandedState(TreeViewItem item)
{
return item is ChangeCategoryTreeViewItem;
}
protected override TreeViewItem BuildRoot()
{
return new TreeViewItem(0, -1, string.Empty);
}
protected override IList<TreeViewItem> BuildRows(TreeViewItem rootItem)
{
try
{
RegenerateRows(
mPendingChangesTree, mTreeViewItemIds, this,
rootItem, mRows, mExpandCategories);
}
finally
{
mExpandCategories = false;
}
return mRows;
}
protected override void CommandEventHandling()
{
// NOTE - empty override to prevent crash when pressing ctrl-a in the treeview
}
protected override void SearchChanged(string newSearch)
{
mCooldownFilterAction.Ping();
}
protected override void ContextClickedItem(int id)
{
mMenu.Popup();
Repaint();
}
protected override void RowGUI(RowGUIArgs args)
{
DrawTreeViewItem.InitializeStyles();
if (args.item is ChangeCategoryTreeViewItem)
{
CategoryTreeViewItemGUI(
args.rowRect, rowHeight,
(ChangeCategoryTreeViewItem)args.item,
args.selected, args.focused);
return;
}
if (args.item is ChangeTreeViewItem)
{
ChangeTreeViewItemGUI(
mWkInfo.ClientPath,
mIsGluonMode,
mAssetStatusCache,
this,
mPendingChangesTree,
(ChangeTreeViewItem)args.item,
args);
return;
}
base.RowGUI(args);
}
internal void BuildModel(
PlasticGui.WorkspaceWindow.PendingChanges.PendingChanges pendingChanges,
CheckedStateManager checkedStateManager)
{
mTreeViewItemIds.Clear();
mPendingChangesTree.BuildChangeCategories(
mWkInfo.ClientPath, pendingChanges, checkedStateManager);
}
internal void Refilter()
{
Filter filter = new Filter(searchString);
mPendingChangesTree.Filter(filter, mColumnNames);
mExpandCategories = true;
}
internal void Sort()
{
int sortedColumnIdx = multiColumnHeader.state.sortedColumnIndex;
bool sortAscending = multiColumnHeader.IsSortedAscending(sortedColumnIdx);
mPendingChangesTree.Sort(
mColumnNames[sortedColumnIdx],
sortAscending);
}
internal SelectedChangesGroupInfo GetSelectedChangesGroupInfo()
{
SelectedChangesGroupInfo result = new SelectedChangesGroupInfo();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (KeyValuePair<PendingChangeInfo, int> item
in mTreeViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
ChangeInfo changeInfo = item.Key.ChangeInfo;
result.SelectedCount++;
result.IsAnyDirectorySelected |= changeInfo.IsDirectory;
result.IsAnyPrivateSelected |= !ChangeInfoType.IsControlled(changeInfo);
result.IsAnyControlledSelected |= ChangeInfoType.IsControlled(changeInfo);
result.IsAnyLocalChangeSelected |= ChangeInfoType.IsLocalChange(changeInfo);
result.FilterInfo.IsAnyIgnoredSelected |= ChangeInfoType.IsIgnored(changeInfo);
result.FilterInfo.IsAnyHiddenChangedSelected |= ChangeInfoType.IsHiddenChanged(changeInfo);
string wkRelativePath = InternalNames.RootDir +
WorkspacePath.GetWorkspaceRelativePath(
mWkInfo.ClientPath, changeInfo.GetFullPath());
if (result.SelectedCount == 1)
{
result.FilterInfo.CommonName = Path.GetFileName(changeInfo.GetFullPath());
result.FilterInfo.CommonExtension = changeInfo.GetExtension();
result.FilterInfo.CommonFullPath = wkRelativePath;
continue;
}
if (result.FilterInfo.CommonName != Path.GetFileName(changeInfo.GetFullPath()))
result.FilterInfo.CommonName = null;
if (result.FilterInfo.CommonExtension != changeInfo.GetExtension())
result.FilterInfo.CommonExtension = null;
if (result.FilterInfo.CommonFullPath != wkRelativePath)
result.FilterInfo.CommonFullPath = null;
}
return result;
}
internal bool GetSelectedPathsToDelete(
out List<string> privateDirectories,
out List<string> privateFiles)
{
privateDirectories = new List<string>();
privateFiles = new List<string>();
List<ChangeInfo> dirChanges = new List<ChangeInfo>();
List<ChangeInfo> fileChanges = new List<ChangeInfo>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return false;
foreach (KeyValuePair<PendingChangeInfo, int> item
in mTreeViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
ChangeInfo changeInfo = item.Key.ChangeInfo;
if (ChangeInfoType.IsControlled(changeInfo))
continue;
if (changeInfo.IsDirectory)
{
dirChanges.Add(changeInfo);
continue;
}
fileChanges.Add(changeInfo);
}
mPendingChangesTree.FillWithMeta(fileChanges);
mPendingChangesTree.FillWithMeta(dirChanges);
privateDirectories = dirChanges.Select(
d => d.GetFullPath()).ToList();
privateFiles = fileChanges.Select(
f => f.GetFullPath()).ToList();
return true;
}
internal void GetCheckedChanges(
bool bExcludePrivates,
out List<ChangeInfo> changes,
out List<ChangeInfo> dependenciesCandidates)
{
mPendingChangesTree.GetCheckedChanges(
bExcludePrivates, out changes, out dependenciesCandidates);
}
internal List<ChangeInfo> GetAllChanges()
{
List<ChangeInfo> result = new List<ChangeInfo>();
foreach (PendingChangeCategory category in mPendingChangesTree.GetNodes())
{
foreach (PendingChangeInfo change in category.GetCurrentChanges())
result.Add(change.ChangeInfo);
}
mPendingChangesTree.FillWithMeta(result);
return result;
}
internal ChangeInfo GetMetaChange(ChangeInfo change)
{
if (change == null)
return null;
return mPendingChangesTree.GetMetaChange(change);
}
internal List<ChangeInfo> GetDependenciesCandidates(
List<ChangeInfo> selectedChanges, bool bExcludePrivates)
{
return mPendingChangesTree.GetDependenciesCandidates(
selectedChanges, bExcludePrivates);
}
internal List<ChangeInfo> GetSelectedChanges(bool includeMetaFiles)
{
List<ChangeInfo> result = new List<ChangeInfo>();
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return result;
foreach (KeyValuePair<PendingChangeInfo, int> item
in mTreeViewItemIds.GetInfoItems())
{
if (!selectedIds.Contains(item.Value))
continue;
result.Add(item.Key.ChangeInfo);
}
if (includeMetaFiles)
mPendingChangesTree.FillWithMeta(result);
return result;
}
internal bool SelectionHasMeta()
{
ChangeInfo selectedChangeInfo = GetSelectedRow();
if (selectedChangeInfo == null)
return false;
return mPendingChangesTree.HasMeta(selectedChangeInfo);
}
internal ChangeInfo GetSelectedRow()
{
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return null;
int selectedId = selectedIds[0];
foreach (KeyValuePair<PendingChangeInfo, int> item
in mTreeViewItemIds.GetInfoItems())
{
if (selectedId == item.Value)
return item.Key.ChangeInfo;
}
return null;
}
internal ChangeInfo GetNearestAddedChange()
{
IList<int> selectedIds = GetSelection();
if (selectedIds.Count == 0)
return null;
int id = selectedIds[0];
IList<TreeViewItem> treeViewItems =
FindRows(new List<int>() { id });
if (treeViewItems.Count == 0)
return null;
PendingChangeInfo changeInfo =
((ChangeTreeViewItem)treeViewItems[0]).ChangeInfo;
PendingChangeCategory category =
(PendingChangeCategory)changeInfo.GetParent();
int itemIndex = category.GetChildPosition(changeInfo);
ChangeInfo result = GetNextExistingAddedItem(category, itemIndex);
if (result != null)
return result;
return GetPreviousExistingAddedItem(category, itemIndex);
}
internal void SelectFirstPendingChangeOnTree()
{
int treeIdFirstItem = GetTreeIdFirstItem();
if (treeIdFirstItem == -1)
return;
mIsSelectionChangedEventDisabled = true;
try
{
TableViewOperations.SetSelectionAndScroll(
this, new List<int> { treeIdFirstItem });
}
finally
{
mIsSelectionChangedEventDisabled = false;
}
}
internal void SelectPreviouslySelectedPendingChanges(
List<ChangeInfo> changesToSelect)
{
List<int> idsToSelect = new List<int>();
foreach (ChangeInfo change in changesToSelect)
{
int changeId = GetTreeIdForItem(change);
if (changeId == -1)
continue;
idsToSelect.Add(changeId);
}
mIsSelectionChangedEventDisabled = true;
try
{
TableViewOperations.SetSelectionAndScroll(
this, idsToSelect);
}
finally
{
mIsSelectionChangedEventDisabled = false;
}
}
internal int GetSelectedItemCount()
{
List<PendingChangeCategory> categories = mPendingChangesTree.GetNodes();
if (categories == null)
return 0;
int checkedCount = 0;
foreach (PendingChangeCategory category in categories)
{
checkedCount += category.GetCheckedChangesCount();
}
return checkedCount;
}
internal int GetTotalItemCount()
{
List<PendingChangeCategory> categories = mPendingChangesTree.GetNodes();
if (categories == null)
return 0;
int totalCount = 0;
foreach (PendingChangeCategory category in categories)
{
totalCount += category.GetChildrenCount();
}
return totalCount;
}
ChangeInfo GetNextExistingAddedItem(
PendingChangeCategory addedCategory, int targetAddedItemIndex)
{
int addedItemsCount = addedCategory.GetChildrenCount();
for (int i = targetAddedItemIndex + 1; i < addedItemsCount; i++)
{
ChangeInfo currentChangeInfo = GetExistingAddedItem(addedCategory, i);
if (currentChangeInfo != null)
return currentChangeInfo;
}
return null;
}
ChangeInfo GetPreviousExistingAddedItem(
PendingChangeCategory addedCategory, int targetAddedItemIndex)
{
for (int i = targetAddedItemIndex - 1; i >= 0; i--)
{
ChangeInfo currentChangeInfo = GetExistingAddedItem(addedCategory, i);
if (currentChangeInfo != null)
return currentChangeInfo;
}
return null;
}
ChangeInfo GetExistingAddedItem(
PendingChangeCategory addedCategory, int addedItemIndex)
{
ChangeInfo currentChangeInfo = ((PendingChangeInfo)addedCategory.
GetChild(addedItemIndex)).ChangeInfo;
if (Directory.Exists(currentChangeInfo.Path) ||
File.Exists(currentChangeInfo.Path))
return currentChangeInfo;
return null;
}
int GetTreeIdFirstItem()
{
List<PendingChangeCategory> categories = mPendingChangesTree.GetNodes();
if (categories == null)
return -1;
if (categories.Count == 0)
return -1;
List<PendingChangeInfo> changes = categories[0].GetCurrentChanges();
if (changes.Count == 0)
return -1;
int changeId;
if (mTreeViewItemIds.TryGetInfoItemId(changes[0], out changeId))
return changeId;
return -1;
}
int GetTreeIdForItem(ChangeInfo change)
{
foreach (KeyValuePair<PendingChangeInfo, int> item in mTreeViewItemIds.GetInfoItems())
{
ChangeInfo changeInfo = item.Key.ChangeInfo;
if (changeInfo.ChangeTypes != change.ChangeTypes)
continue;
if (changeInfo.GetFullPath() != change.GetFullPath())
continue;
return item.Value;
}
return -1;
}
void DelayedSearchChanged()
{
Refilter();
Sort();
Reload();
TableViewOperations.ScrollToSelection(this);
}
void SortingChanged(MultiColumnHeader multiColumnHeader)
{
Sort();
Reload();
}
static void CategoryTreeViewItemGUI(
Rect rowRect,
float rowHeight,
ChangeCategoryTreeViewItem item,
bool isSelected,
bool isFocused)
{
Texture icon = GetCategoryIcon(item.Category);
string label = item.Category.GetHeaderText();
bool wasChecked = item.Category.IsChecked();
bool hadCheckedChildren = item.Category.GetCheckedChangesCount() > 0;
bool isChecked = DrawTreeViewItem.ForCheckableCategoryItem(
rowRect, rowHeight, item.depth, icon, label,
isSelected, isFocused, wasChecked, hadCheckedChildren);
if (!wasChecked && isChecked)
{
item.Category.UpdateCheckedState(true);
return;
}
if (wasChecked && !isChecked)
{
item.Category.UpdateCheckedState(false);
return;
}
}
static void ChangeTreeViewItemGUI(
string wkPath,
bool isGluonMode,
IAssetStatusCache assetStatusCache,
PendingChangesTreeView treeView,
UnityPendingChangesTree pendingChangesTree,
ChangeTreeViewItem item,
RowGUIArgs args)
{
for (int visibleColumnIdx = 0; visibleColumnIdx < args.GetNumVisibleColumns(); visibleColumnIdx++)
{
Rect cellRect = args.GetCellRect(visibleColumnIdx);
PendingChangesTreeColumn column =
(PendingChangesTreeColumn)args.GetColumn(visibleColumnIdx);
ChangeTreeViewItemCellGUI(
isGluonMode,
assetStatusCache,
cellRect,
treeView.rowHeight,
treeView,
pendingChangesTree,
item,
column,
args.selected,
args.focused);
}
}
static void ChangeTreeViewItemCellGUI(
bool isGluonMode,
IAssetStatusCache assetStatusCache,
Rect rect,
float rowHeight,
PendingChangesTreeView treeView,
UnityPendingChangesTree pendingChangesTree,
ChangeTreeViewItem item,
PendingChangesTreeColumn column,
bool isSelected,
bool isFocused)
{
PendingChangeInfo changeInfo = item.ChangeInfo;
string label = changeInfo.GetColumnText(
PendingChangesTreeHeaderState.GetColumnName(column));
if (column == PendingChangesTreeColumn.Item)
{
if (pendingChangesTree.HasMeta(changeInfo.ChangeInfo))
label = string.Concat(label, UnityConstants.TREEVIEW_META_LABEL);
Texture icon = GetIcon(changeInfo);
bool isConflicted = IsConflicted(
isGluonMode, assetStatusCache,
changeInfo.ChangeInfo.GetFullPath());
GetChangesOverlayIcon.Data overlayIconData =
GetChangesOverlayIcon.ForPendingChange(
changeInfo.ChangeInfo, isConflicted);
bool wasChecked = changeInfo.IsChecked();
bool isChecked = DrawTreeViewItem.ForCheckableItemCell(
rect, rowHeight, item.depth,
icon, overlayIconData, label,
isSelected, isFocused, false,
wasChecked);
changeInfo.UpdateCheckedState(isChecked);
if (wasChecked != isChecked)
UpdateCheckStateForSelection(treeView, item);
return;
}
if (column == PendingChangesTreeColumn.Size)
{
DrawTreeViewItem.ForSecondaryLabelRightAligned(
rect, label, isSelected, isFocused, false);
return;
}
DrawTreeViewItem.ForSecondaryLabel(
rect, label, isSelected, isFocused, false);
}
static void UpdateCheckStateForSelection(
PendingChangesTreeView treeView,
ChangeTreeViewItem senderTreeViewItem)
{
IList<int> selectedIds = treeView.GetSelection();
if (selectedIds.Count <= 1)
return;
if (!selectedIds.Contains(senderTreeViewItem.id))
return;
bool isChecked = senderTreeViewItem.ChangeInfo.IsChecked();
foreach (TreeViewItem treeViewItem in treeView.FindRows(selectedIds))
{
if (treeViewItem is ChangeCategoryTreeViewItem)
{
((ChangeCategoryTreeViewItem)treeViewItem).Category
.UpdateCheckedState(isChecked);
continue;
}
((ChangeTreeViewItem)treeViewItem).ChangeInfo
.UpdateCheckedState(isChecked);
}
}
static void RegenerateRows(
UnityPendingChangesTree pendingChangesTree,
TreeViewItemIds<PendingChangeCategory, PendingChangeInfo> treeViewItemIds,
PendingChangesTreeView treeView,
TreeViewItem rootItem,
List<TreeViewItem> rows,
bool expandCategories)
{
ClearRows(rootItem, rows);
List<PendingChangeCategory> categories = pendingChangesTree.GetNodes();
if (categories == null)
return;
foreach (PendingChangeCategory category in categories)
{
int categoryId;
if (!treeViewItemIds.TryGetCategoryItemId(category, out categoryId))
categoryId = treeViewItemIds.AddCategoryItem(category);
ChangeCategoryTreeViewItem categoryTreeViewItem =
new ChangeCategoryTreeViewItem(categoryId, category);
rootItem.AddChild(categoryTreeViewItem);
rows.Add(categoryTreeViewItem);
if (!expandCategories &&
!treeView.IsExpanded(categoryTreeViewItem.id))
continue;
foreach (PendingChangeInfo change in category.GetCurrentChanges())
{
int changeId;
if (!treeViewItemIds.TryGetInfoItemId(change, out changeId))
changeId = treeViewItemIds.AddInfoItem(change);
TreeViewItem changeTreeViewItem =
new ChangeTreeViewItem(changeId, change);
categoryTreeViewItem.AddChild(changeTreeViewItem);
rows.Add(changeTreeViewItem);
}
}
if (!expandCategories)
return;
treeView.state.expandedIDs = treeViewItemIds.GetCategoryIds();
}
static void ClearRows(
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
if (rootItem.hasChildren)
rootItem.children.Clear();
rows.Clear();
}
static Texture GetCategoryIcon(PendingChangeCategory category)
{
switch (category.Type)
{
case PendingChangeCategoryType.Added:
return Images.GetImage(Images.Name.IconAdded);
case PendingChangeCategoryType.Changed:
return Images.GetImage(Images.Name.IconChanged);
case PendingChangeCategoryType.Deleted:
return Images.GetImage(Images.Name.IconDeleted);
case PendingChangeCategoryType.Moved:
return Images.GetImage(Images.Name.IconMoved);
default:
return null;
}
}
static Texture GetIcon(PendingChangeInfo change)
{
if (change.ChangeInfo.IsDirectory)
return Images.GetDirectoryIcon();
string fullPath = change.ChangeInfo.GetFullPath();
return Images.GetFileIcon(fullPath);
}
static bool IsConflicted(
bool isGluonMode,
IAssetStatusCache assetStatusCache,
string fullPath)
{
if (!isGluonMode)
return false;
return ClassifyAssetStatus.IsConflicted(
assetStatusCache.GetStatusForPath(fullPath));
}
bool mExpandCategories;
bool mIsSelectionChangedEventDisabled;
TreeViewItemIds<PendingChangeCategory, PendingChangeInfo> mTreeViewItemIds =
new TreeViewItemIds<PendingChangeCategory, PendingChangeInfo>();
List<TreeViewItem> mRows = new List<TreeViewItem>();
UnityPendingChangesTree mPendingChangesTree;
CooldownWindowDelayer mCooldownFilterAction;
readonly PendingChangesViewMenu mMenu;
readonly IAssetStatusCache mAssetStatusCache;
readonly List<string> mColumnNames;
readonly bool mIsGluonMode;
readonly WorkspaceInfo mWkInfo;
}
}
using UnityEditor;
using UnityEngine;
using PlasticGui;
using PlasticGui.WorkspaceWindow.Items;
using PlasticGui.WorkspaceWindow.Open;
using PlasticGui.WorkspaceWindow.PendingChanges;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.PendingChanges
{
internal class PendingChangesViewMenu
{
internal interface IMetaMenuOperations
{
void DiffMeta();
void OpenMeta();
void OpenMetaWith();
void OpenMetaInExplorer();
void HistoryMeta();
bool SelectionHasMeta();
}
internal PendingChangesViewMenu(
IPendingChangesMenuOperations pendingChangesMenuOperations,
IOpenMenuOperations openMenuOperations,
IMetaMenuOperations metaMenuOperations,
IFilesFilterPatternsMenuOperations filterMenuOperations)
{
mPendingChangesMenuOperations = pendingChangesMenuOperations;
mOpenMenuOperations = openMenuOperations;
mMetaMenuOperations = metaMenuOperations;
mFilterMenuBuilder = new FilesFilterPatternsMenuBuilder(filterMenuOperations);
BuildComponents();
}
internal void Popup()
{
GenericMenu menu = new GenericMenu();
UpdateMenuItems(menu);
menu.ShowAsContext();
}
internal bool ProcessKeyActionIfNeeded(Event e)
{
PendingChangesMenuOperations operationToExecute =
GetPendingChangesMenuOperation(e);
OpenMenuOperations openOperationToExecute =
GetOpenMenuOperation(e);
if (operationToExecute == PendingChangesMenuOperations.None &&
openOperationToExecute == OpenMenuOperations.None)
return false;
SelectedChangesGroupInfo info =
mPendingChangesMenuOperations.GetSelectedChangesGroupInfo();
if (operationToExecute != PendingChangesMenuOperations.None)
return ProcessKeyActionForPendingChangesMenu(
operationToExecute, mPendingChangesMenuOperations, info);
return ProcessKeyActionForOpenMenu(
openOperationToExecute, mOpenMenuOperations, info);
}
void OpenMenuItem_Click()
{
mOpenMenuOperations.Open();
}
void OpenWithMenuItem_Click()
{
mOpenMenuOperations.OpenWith();
}
void OpenInExplorerMenuItem_Click()
{
mOpenMenuOperations.OpenInExplorer();
}
void OpenMetaMenuItem_Click()
{
mMetaMenuOperations.OpenMeta();
}
void OpenMetaWithMenuItem_Click()
{
mMetaMenuOperations.OpenMetaWith();
}
void OpenMetaInExplorerMenuItem_Click()
{
mMetaMenuOperations.OpenMetaInExplorer();
}
void DiffMenuItem_Click()
{
mPendingChangesMenuOperations.Diff();
}
void DiffMetaMenuItem_Click()
{
mMetaMenuOperations.DiffMeta();
}
void UndoChangesMenuItem_Click()
{
mPendingChangesMenuOperations.UndoChanges();
}
void CheckoutMenuItem_Click()
{
mPendingChangesMenuOperations.ApplyLocalChanges();
}
void DeleteMenuItem_Click()
{
mPendingChangesMenuOperations.Delete();
}
void HistoryMenuItem_Click()
{
mPendingChangesMenuOperations.History();
}
void HistoryMetaMenuItem_Click()
{
mMetaMenuOperations.HistoryMeta();
}
void UpdateMenuItems(GenericMenu menu)
{
SelectedChangesGroupInfo info =
mPendingChangesMenuOperations.GetSelectedChangesGroupInfo();
PendingChangesMenuOperations operations =
PendingChangesMenuUpdater.GetAvailableMenuOperations(info);
OpenMenuOperations openOperations =
GetOpenMenuOperations.ForPendingChanges(info);
if (operations == PendingChangesMenuOperations.None &&
openOperations == OpenMenuOperations.None)
{
menu.AddDisabledItem(GetNoActionMenuItemContent());
return;
}
UpdateOpenMenuItems(menu, openOperations);
menu.AddSeparator(string.Empty);
if (operations.HasFlag(PendingChangesMenuOperations.DiffWorkspaceContent))
menu.AddItem(mDiffMenuItemContent, false, DiffMenuItem_Click);
else
menu.AddDisabledItem(mDiffMenuItemContent);
if (mMetaMenuOperations.SelectionHasMeta())
{
if (operations.HasFlag(PendingChangesMenuOperations.DiffWorkspaceContent))
menu.AddItem(mDiffMetaMenuItemContent, false, DiffMetaMenuItem_Click);
else
menu.AddDisabledItem(mDiffMetaMenuItemContent);
}
menu.AddSeparator(string.Empty);
if (operations.HasFlag(PendingChangesMenuOperations.UndoChanges))
menu.AddItem(mUndoChangesMenuItemContent, false, UndoChangesMenuItem_Click);
else
menu.AddDisabledItem(mUndoChangesMenuItemContent);
menu.AddSeparator(string.Empty);
if (operations.HasFlag(PendingChangesMenuOperations.ApplyLocalChanges))
menu.AddItem(mCheckoutMenuItemContent, false, CheckoutMenuItem_Click);
else
menu.AddDisabledItem(mCheckoutMenuItemContent);
if (operations.HasFlag(PendingChangesMenuOperations.Delete))
menu.AddItem(mDeleteMenuItemContent, false, DeleteMenuItem_Click);
else
menu.AddDisabledItem(mDeleteMenuItemContent);
menu.AddSeparator(string.Empty);
mFilterMenuBuilder.UpdateMenuItems(
menu, FilterMenuUpdater.GetMenuActions(info));
menu.AddSeparator(string.Empty);
if (operations.HasFlag(PendingChangesMenuOperations.History))
menu.AddItem(mViewHistoryMenuItemContent, false, HistoryMenuItem_Click);
else
menu.AddDisabledItem(mViewHistoryMenuItemContent, false);
if (mMetaMenuOperations.SelectionHasMeta())
{
if (operations.HasFlag(PendingChangesMenuOperations.History))
menu.AddItem(mViewHistoryMetaMenuItemContent, false, HistoryMetaMenuItem_Click);
else
menu.AddDisabledItem(mViewHistoryMetaMenuItemContent);
}
}
void UpdateOpenMenuItems(GenericMenu menu, OpenMenuOperations operations)
{
if (!operations.HasFlag(OpenMenuOperations.Open) &&
!operations.HasFlag(OpenMenuOperations.OpenWith) &&
!operations.HasFlag(OpenMenuOperations.OpenInExplorer))
{
menu.AddDisabledItem(mOpenSubmenuItemContent);
return;
}
if (operations.HasFlag(OpenMenuOperations.Open))
menu.AddItem(mOpenMenuItemContent, false, OpenMenuItem_Click);
else
menu.AddDisabledItem(mOpenMenuItemContent);
if (operations.HasFlag(OpenMenuOperations.OpenWith))
menu.AddItem(mOpenWithMenuItemContent, false, OpenWithMenuItem_Click);
else
menu.AddDisabledItem(mOpenWithMenuItemContent);
if (operations.HasFlag(OpenMenuOperations.OpenInExplorer))
menu.AddItem(mOpenInExplorerMenuItemContent, false, OpenInExplorerMenuItem_Click);
else
menu.AddDisabledItem(mOpenInExplorerMenuItemContent);
if (!mMetaMenuOperations.SelectionHasMeta())
return;
menu.AddSeparator(PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen) + "/");
if (operations.HasFlag(OpenMenuOperations.Open))
menu.AddItem(mOpenMetaMenuItemContent, false, OpenMetaMenuItem_Click);
else
menu.AddDisabledItem(mOpenMetaMenuItemContent);
if (operations.HasFlag(OpenMenuOperations.OpenWith))
menu.AddItem(mOpenMetaWithMenuItemContent, false, OpenMetaWithMenuItem_Click);
else
menu.AddDisabledItem(mOpenMetaWithMenuItemContent);
if (operations.HasFlag(OpenMenuOperations.OpenInExplorer))
menu.AddItem(mOpenMetaInExplorerMenuItemContent, false, OpenMetaInExplorerMenuItem_Click);
else
menu.AddDisabledItem(mOpenMetaInExplorerMenuItemContent);
}
GUIContent GetNoActionMenuItemContent()
{
if (mNoActionMenuItemContent == null)
{
mNoActionMenuItemContent = new GUIContent(PlasticLocalization.GetString(
PlasticLocalization.Name.NoActionMenuItem));
}
return mNoActionMenuItemContent;
}
void BuildComponents()
{
mOpenSubmenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen));
mOpenMenuItemContent = new GUIContent(
UnityMenuItem.GetText(
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen),
string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen),
GetPlasticShortcut.ForOpen())));
mOpenWithMenuItemContent = new GUIContent(
UnityMenuItem.GetText(
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen),
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpenWith)));
mOpenInExplorerMenuItemContent = new GUIContent(
UnityMenuItem.GetText(
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen),
PlasticLocalization.GetString(PlasticLocalization.Name.OpenInExplorerMenuItem)));
mOpenMetaMenuItemContent = new GUIContent(
UnityMenuItem.GetText(
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen),
PlasticLocalization.GetString(PlasticLocalization.Name.OpenMeta)));
mOpenMetaWithMenuItemContent = new GUIContent(
UnityMenuItem.GetText(
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen),
PlasticLocalization.GetString(PlasticLocalization.Name.OpenMetaWith)));
mOpenMetaInExplorerMenuItemContent = new GUIContent(
UnityMenuItem.GetText(
PlasticLocalization.GetString(PlasticLocalization.Name.ItemsMenuItemOpen),
PlasticLocalization.GetString(PlasticLocalization.Name.OpenMetaInExplorer)));
mDiffMenuItemContent = new GUIContent(string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMenuItem),
GetPlasticShortcut.ForDiff()));
mDiffMetaMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.DiffMetaMenuItem));
mUndoChangesMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.PendingChangesMenuItemUndoChanges));
mCheckoutMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.PendingChangesMenuItemCheckout));
mDeleteMenuItemContent = new GUIContent(string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.PendingChangesMenuItemDelete),
GetPlasticShortcut.ForDelete()));
mViewHistoryMenuItemContent = new GUIContent(string.Format("{0} {1}",
PlasticLocalization.GetString(PlasticLocalization.Name.ViewHistoryMenuItem),
GetPlasticShortcut.ForHistory()));
mViewHistoryMetaMenuItemContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.ViewHistoryMetaMenuItem));
mFilterMenuBuilder.BuildIgnoredSubmenuItem();
mFilterMenuBuilder.BuildHiddenChangesSubmenuItem();
}
static bool ProcessKeyActionForPendingChangesMenu(
PendingChangesMenuOperations operationToExecute,
IPendingChangesMenuOperations pendingChangesMenuOperations,
SelectedChangesGroupInfo info)
{
PendingChangesMenuOperations operations =
PendingChangesMenuUpdater.GetAvailableMenuOperations(info);
if (!operations.HasFlag(operationToExecute))
return false;
ProcessPendingChangesMenuOperation(
operationToExecute, pendingChangesMenuOperations);
return true;
}
static bool ProcessKeyActionForOpenMenu(
OpenMenuOperations openOperationToExecute,
IOpenMenuOperations openMenuOperations,
SelectedChangesGroupInfo info)
{
OpenMenuOperations openOperations =
GetOpenMenuOperations.ForPendingChanges(info);
if (!openOperations.HasFlag(openOperationToExecute))
return false;
ProcessOpenMenuOperation(
openOperationToExecute, openMenuOperations);
return true;
}
static void ProcessPendingChangesMenuOperation(
PendingChangesMenuOperations operationToExecute,
IPendingChangesMenuOperations pendingChangesMenuOperations)
{
if (operationToExecute == PendingChangesMenuOperations.DiffWorkspaceContent)
{
pendingChangesMenuOperations.Diff();
return;
}
if (operationToExecute == PendingChangesMenuOperations.Delete)
{
pendingChangesMenuOperations.Delete();
return;
}
if (operationToExecute == PendingChangesMenuOperations.History)
{
pendingChangesMenuOperations.History();
return;
}
}
static void ProcessOpenMenuOperation(
OpenMenuOperations openOperationToExecute,
IOpenMenuOperations openMenuOperations)
{
if (openOperationToExecute == OpenMenuOperations.Open)
{
openMenuOperations.Open();
return;
}
}
static PendingChangesMenuOperations GetPendingChangesMenuOperation(Event e)
{
if (Keyboard.IsControlOrCommandKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.D))
return PendingChangesMenuOperations.DiffWorkspaceContent;
if (Keyboard.IsKeyPressed(e, KeyCode.Delete))
return PendingChangesMenuOperations.Delete;
if (Keyboard.IsControlOrCommandKeyPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.H))
return PendingChangesMenuOperations.History;
return PendingChangesMenuOperations.None;
}
static OpenMenuOperations GetOpenMenuOperation(Event e)
{
if (Keyboard.IsShiftPressed(e) && Keyboard.IsKeyPressed(e, KeyCode.O))
return OpenMenuOperations.Open;
return OpenMenuOperations.None;
}
GUIContent mNoActionMenuItemContent;
GUIContent mOpenSubmenuItemContent;
GUIContent mOpenMenuItemContent;
GUIContent mOpenWithMenuItemContent;
GUIContent mOpenInExplorerMenuItemContent;
GUIContent mOpenMetaMenuItemContent;
GUIContent mOpenMetaWithMenuItemContent;
GUIContent mOpenMetaInExplorerMenuItemContent;
GUIContent mDiffMenuItemContent;
GUIContent mDiffMetaMenuItemContent;
GUIContent mUndoChangesMenuItemContent;
GUIContent mCheckoutMenuItemContent;
GUIContent mDeleteMenuItemContent;
GUIContent mViewHistoryMenuItemContent;
GUIContent mViewHistoryMetaMenuItemContent;
FilesFilterPatternsMenuBuilder mFilterMenuBuilder;
IMetaMenuOperations mMetaMenuOperations;
IOpenMenuOperations mOpenMenuOperations;
IPendingChangesMenuOperations mPendingChangesMenuOperations;
}
}
using UnityEditor.IMGUI.Controls;
using PlasticGui.WorkspaceWindow.PendingChanges;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.PendingChanges.PendingMergeLinks
{
internal class MergeLinkListViewItem : TreeViewItem
{
internal MountPendingMergeLink MergeLink { get; private set; }
internal MergeLinkListViewItem(int id, MountPendingMergeLink mergeLink)
: base(id, 0)
{
MergeLink = mergeLink;
displayName = mergeLink.GetPendingMergeLinkText();
icon = Images.GetImage(Images.Name.IconMergeLink);
}
}
}
using System.Collections.Generic;
using UnityEditor.IMGUI.Controls;
using Codice.Client.Commands;
using Codice.Client.Common;
using Codice.CM.Common;
using Codice.CM.Common.Merge;
using PlasticGui.WorkspaceWindow.PendingChanges;
using Unity.PlasticSCM.Editor.UI;
namespace Unity.PlasticSCM.Editor.Views.PendingChanges.PendingMergeLinks
{
internal class MergeLinksListView : TreeView
{
internal float DesiredHeight
{
get
{
return rowHeight * (mMergeLinks.Count + 1);
}
}
internal MergeLinksListView()
: base(new TreeViewState())
{
rowHeight = UnityConstants.TREEVIEW_ROW_HEIGHT;
showAlternatingRowBackgrounds = true;
}
public override IList<TreeViewItem> GetRows()
{
return mRows;
}
protected override TreeViewItem BuildRoot()
{
return new TreeViewItem(0, -1, string.Empty);
}
protected override IList<TreeViewItem> BuildRows(TreeViewItem rootItem)
{
RegenerateRows(mMergeLinks, rootItem, mRows);
return mRows;
}
internal void BuildModel(
IDictionary<MountPoint, IList<PendingMergeLink>> pendingMergeLinks)
{
mMergeLinks = BuildMountPendingMergeLink(pendingMergeLinks);
}
static void RegenerateRows(
List<MountPendingMergeLink> mergeLinks,
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
ClearRows(rootItem, rows);
if (mergeLinks.Count == 0)
return;
for (int i = 0; i < mergeLinks.Count; i++)
{
MergeLinkListViewItem mergeLinkListViewItem =
new MergeLinkListViewItem(i + 1, mergeLinks[i]);
rootItem.AddChild(mergeLinkListViewItem);
rows.Add(mergeLinkListViewItem);
}
}
static void ClearRows(
TreeViewItem rootItem,
List<TreeViewItem> rows)
{
if (rootItem.hasChildren)
rootItem.children.Clear();
rows.Clear();
}
static List<MountPendingMergeLink> BuildMountPendingMergeLink(
IDictionary<MountPoint, IList<PendingMergeLink>> pendingMergeLinks)
{
List<MountPendingMergeLink> result = new List<MountPendingMergeLink>();
foreach (KeyValuePair<MountPoint, IList<PendingMergeLink>> mountLink
in pendingMergeLinks)
{
result.AddRange(BuildMountPendingMergeLinks(
mountLink.Key, mountLink.Value));
}
return result;
}
static List<MountPendingMergeLink> BuildMountPendingMergeLinks(
MountPoint mount, IList<PendingMergeLink> links)
{
List<MountPendingMergeLink> result = new List<MountPendingMergeLink>();
RepositoryInfo repInfo = RepositorySpecResolverProvider.Get().
GetRepInfo(mount.RepSpec);
foreach (PendingMergeLink link in links)
result.Add(new MountPendingMergeLink(repInfo.GetRepSpec(), link));
return result;
}
List<TreeViewItem> mRows = new List<TreeViewItem>();
List<MountPendingMergeLink> mMergeLinks = new List<MountPendingMergeLink>();
}
}
using System.Collections.Generic;
using Codice.Client.BaseCommands;
using Codice.Client.Commands;
using PlasticGui;
using PlasticGui.WorkspaceWindow.PendingChanges;
namespace Unity.PlasticSCM.Editor.Views.PendingChanges
{
internal class UnityPendingChangesTree
{
internal UnityPendingChangesTree()
{
mInnerTree = new PendingChangesTree();
mMetaCache = new MetaCache();
}
internal List<PendingChangeCategory> GetNodes()
{
return mInnerTree.GetNodes();
}
internal bool HasMeta(ChangeInfo changeInfo)
{
return mMetaCache.ContainsMeta(changeInfo);
}
internal ChangeInfo GetMetaChange(ChangeInfo change)
{
return mMetaCache.GetExistingMeta(change);
}
internal void FillWithMeta(List<ChangeInfo> changes)
{
changes.AddRange(
mMetaCache.GetExistingMeta(changes));
}
internal void GetCheckedChanges(
bool bExcludePrivates,
out List<ChangeInfo> changes,
out List<ChangeInfo> dependenciesCandidates)
{
mInnerTree.GetCheckedChanges(
bExcludePrivates,
out changes,
out dependenciesCandidates);
changes.AddRange(
mMetaCache.GetExistingMeta(changes));
dependenciesCandidates.AddRange(
mMetaCache.GetExistingMeta(dependenciesCandidates));
}
internal List<ChangeInfo> GetDependenciesCandidates(
List<ChangeInfo> selectedChanges,
bool bExcludePrivates)
{
return mInnerTree.GetDependenciesCandidates(
selectedChanges, bExcludePrivates);
}
internal void BuildChangeCategories(
string wkPath,
PlasticGui.WorkspaceWindow.PendingChanges.PendingChanges pendingChanges,
CheckedStateManager checkedStateManager)
{
mMetaCache.Build(pendingChanges);
mInnerTree.BuildChangeCategories(
wkPath,
pendingChanges,
checkedStateManager);
}
internal void Filter(Filter filter, List<string> columnNames)
{
mInnerTree.Filter(filter, columnNames);
}
internal void Sort(string key, bool ascending)
{
mInnerTree.Sort(key, ascending);
}
MetaCache mMetaCache;
PendingChangesTree mInnerTree;
class MetaCache
{
internal bool ContainsMeta(ChangeInfo changeInfo)
{
string key = BuildKey.ForMetaChange(changeInfo);
return mCache.ContainsKey(key);
}
internal ChangeInfo GetExistingMeta(ChangeInfo change)
{
ChangeInfo result;
if (!mCache.TryGetValue(BuildKey.ForMetaChange(change), out result))
return null;
return result;
}
internal List<ChangeInfo> GetExistingMeta(
List<ChangeInfo> changes)
{
List<ChangeInfo> result = new List<ChangeInfo>();
foreach (ChangeInfo change in changes)
{
string key = BuildKey.ForMetaChange(change);
ChangeInfo metaChange;
if (!mCache.TryGetValue(key, out metaChange))
continue;
result.Add(metaChange);
}
return result;
}
internal void Build(PlasticGui.WorkspaceWindow.PendingChanges.PendingChanges pendingChanges)
{
mCache.Clear();
ExtractMetaToCache(pendingChanges.Added, mCache);
ExtractMetaToCache(pendingChanges.Deleted, mCache);
ExtractMetaToCache(pendingChanges.Changed, mCache);
ExtractMetaToCache(pendingChanges.Moved, mCache);
}
static void ExtractMetaToCache(
List<ChangeInfo> changes,
Dictionary<string, ChangeInfo> cache)
{
HashSet<string> indexedKeys = BuildIndexedKeys(changes);
for (int i = changes.Count - 1; i >= 0; i--)
{
ChangeInfo currentChange = changes[i];
if (!MetaPath.IsMetaPath(currentChange.Path))
continue;
string realPath = MetaPath.GetPathFromMetaPath(currentChange.Path);
if (!indexedKeys.Contains(BuildKey.BuildCacheKey(
currentChange.ChangeTypes, realPath)))
continue;
// found foo.c and foo.c.meta
// with the same chage types - move .meta to cache
cache.Add(BuildKey.ForChange(currentChange), currentChange);
changes.RemoveAt(i);
}
}
static HashSet<string> BuildIndexedKeys(
List<ChangeInfo> changes)
{
HashSet<string> result = new HashSet<string>();
foreach (ChangeInfo change in changes)
{
if (MetaPath.IsMetaPath(change.Path))
continue;
result.Add(BuildKey.ForChange(change));
}
return result;
}
Dictionary<string, ChangeInfo> mCache =
new Dictionary<string, ChangeInfo>();
static class BuildKey
{
internal static string ForChange(ChangeInfo change)
{
return BuildCacheKey(
change.ChangeTypes,
change.Path);
}
internal static string ForMetaChange(ChangeInfo change)
{
return BuildCacheKey(
change.ChangeTypes,
MetaPath.GetMetaPath(change.Path));
}
internal static string BuildCacheKey(ChangeTypes changeTypes, string path)
{
return string.Concat(changeTypes, ":", path);
}
}
}
}
}
using System.Diagnostics;
using Codice.Client.BaseCommands;
using Codice.Client.Common;
using Codice.Client.Common.Threading;
using PlasticGui;
using Unity.PlasticSCM.Editor.Tool;
using Unity.PlasticSCM.Editor.UI.Progress;
namespace Unity.PlasticSCM.Editor.Views.Welcome
{
static class ConfigurePlasticOperation
{
internal static void Run(
bool isGluonMode,
ProgressControlsForViews progressControls)
{
((IProgressControls)progressControls).ShowProgress(string.Empty);
IThreadWaiter waiter = ThreadWaiter.GetWaiter();
waiter.Execute(
/*threadOperationDelegate*/ delegate
{
Process plasticProcess = LaunchTool.OpenConfigurationForMode(isGluonMode);
if (plasticProcess != null)
plasticProcess.WaitForExit();
},
/*afterOperationDelegate*/ delegate
{
((IProgressControls)progressControls).HideProgress();
ClientConfig.Reset();
CmConnection.Reset();
ClientHandlers.Register();
if (waiter.Exception == null)
return;
((IProgressControls)progressControls).ShowError(
waiter.Exception.Message);
});
}
}
}
using System.Diagnostics;
using System.IO;
using System.Net;
using Codice.Client.Common.Threading;
using Codice.Client.Common.WebApi;
using Codice.CM.Common;
using Codice.Utils;
using PlasticGui;
using PlasticGui.Help.NewVersions;
using PlasticGui.WorkspaceWindow;
using Unity.PlasticSCM.Editor.Tool;
using Unity.PlasticSCM.Editor.UI.Progress;
using Unity.PlasticSCM.Editor.WebApi;
namespace Unity.PlasticSCM.Editor.Views.Welcome
{
class DownloadAndInstallOperation
{
internal static void Run(
Edition plasticEdition,
string installerDestinationPath,
ProgressControlsForViews progressControls)
{
((IProgressControls)progressControls).ShowProgress(
PlasticLocalization.GetString(PlasticLocalization.Name.DownloadingProgress));
NewVersionResponse plasticVersion = null;
IThreadWaiter waiter = ThreadWaiter.GetWaiter();
waiter.Execute(
/*threadOperationDelegate*/ delegate
{
plasticVersion =
PlasticScmRestApiClient.GetLastVersion(plasticEdition);
if (plasticVersion == null)
return;
string installerUrl = GetInstallerUrl(
plasticVersion.Version,
plasticEdition == Edition.Cloud);
DownloadInstaller(
installerUrl,
installerDestinationPath,
progressControls);
if (!PlatformIdentifier.IsMac())
return;
installerDestinationPath = UnZipMacOsPackage(
installerDestinationPath);
},
/*afterOperationDelegate*/ delegate
{
((IProgressControls)progressControls).HideProgress();
if (waiter.Exception != null)
{
((IProgressControls)progressControls).ShowError(
waiter.Exception.Message);
return;
}
if (plasticVersion == null)
{
((IProgressControls)progressControls).ShowError(
PlasticLocalization.GetString(PlasticLocalization.Name.ConnectingError));
return;
}
if (!File.Exists(installerDestinationPath))
return;
RunInstaller(
installerDestinationPath,
progressControls);
});
}
static void RunInstaller(
string installerPath,
ProgressControlsForViews progressControls)
{
progressControls.ProgressData.ProgressPercent = -1;
((IProgressControls)progressControls).ShowProgress(
PlasticLocalization.GetString(PlasticLocalization.Name.InstallingProgress));
MacOSConfigWorkaround configWorkaround = new MacOSConfigWorkaround();
IThreadWaiter waiter = ThreadWaiter.GetWaiter();
waiter.Execute(
/*threadOperationDelegate*/ delegate
{
configWorkaround.CreateClientConfigIfNeeded();
Process installerProcess =
LaunchInstaller.ForPlatform(installerPath);
if (installerProcess != null)
installerProcess.WaitForExit();
configWorkaround.DeleteClientConfigIfNeeded();
},
/*afterOperationDelegate*/ delegate
{
((IProgressControls)progressControls).HideProgress();
if (waiter.Exception != null)
{
((IProgressControls)progressControls).ShowError(
waiter.Exception.Message);
return;
}
File.Delete(installerPath);
});
}
static void DownloadInstaller(
string url,
string destinationPath,
ProgressControlsForViews progressControls)
{
int bytesProcessed = 0;
Stream remoteStream = null;
Stream localStream = null;
WebResponse response = null;
try
{
WebRequest request = WebRequest.Create(url);
response = request.GetResponse();
long totalBytes = response.ContentLength;
if (File.Exists(destinationPath) &&
new FileInfo(destinationPath).Length == totalBytes)
{
UnityEngine.Debug.LogFormat(
PlasticLocalization.GetString(PlasticLocalization.Name.SkippingDownloadFileExists),
destinationPath);
return;
}
remoteStream = response.GetResponseStream();
localStream = File.Create(destinationPath);
byte[] buffer = new byte[100 * 1024];
int bytesRead;
do
{
bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
localStream.Write(buffer, 0, bytesRead);
bytesProcessed += bytesRead;
progressControls.ProgressData.ProgressPercent = GetProgressBarPercent.
ForTransfer(bytesProcessed, totalBytes) / 100f;
} while (bytesRead > 0);
}
finally
{
if (response != null)
response.Close();
if (remoteStream != null)
remoteStream.Close();
if (localStream != null)
localStream.Close();
}
}
static string UnZipMacOsPackage(
string zipInstallerPath)
{
try
{
string pkgInstallerPath = zipInstallerPath.Substring(
0, zipInstallerPath.Length - ".zip".Length);
string unzipCommand = string.Format(
"unzip -p \"{0}\" > \"{1}\"",
zipInstallerPath, pkgInstallerPath);
unzipCommand = unzipCommand.Replace("\"", "\"\"");
ProcessStartInfo processStartInfo = new ProcessStartInfo();
processStartInfo.FileName = "/bin/bash";
processStartInfo.Arguments = string.Format("-c \"{0}\"", unzipCommand);
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.CreateNoWindow = true;
Process process = Process.Start(processStartInfo);
process.WaitForExit();
return pkgInstallerPath;
}
finally
{
File.Delete(zipInstallerPath);
}
}
static string GetInstallerUrl(
string version,
bool isCloudEdition)
{
string edition = isCloudEdition ?
"cloudedition" : "full";
string platform = PlatformIdentifier.IsMac() ?
"macosx" : "windows";
return string.Format(
@"https://www.plasticscm.com/download/downloadinstaller/{0}/plasticscm/{1}/{2}",
version,
platform,
edition);
}
}
}
using System;
using System.IO;
using Codice.Utils;
namespace Unity.PlasticSCM.Editor.Views.Welcome
{
static class GetInstallerTmpFileName
{
internal static string ForPlatform()
{
string fileName = Guid.NewGuid().ToString();
if (PlatformIdentifier.IsWindows())
fileName += ".exe";
if (PlatformIdentifier.IsMac())
fileName += ".pkg.zip";
return Path.Combine(
Path.GetTempPath(),
fileName);
}
}
}
using System.IO;
using Codice.Client.Common;
using Codice.Utils;
namespace Unity.PlasticSCM.Editor.Views.Welcome
{
class MacOSConfigWorkaround
{
/* In macOS there is no way to pass a parameter
* to the PKG installer to avoid launching
* Plastic at the end of the installation process.
* As a workaround, we can create an empty client.conf in
* the user config folder. This way the installer skips
* launching Plastic at the end of the installation process.
* see /01plastic/install/mac/macplastic/Scripts/postinstall
* Then, we delete the client.conf file if we created it */
internal void CreateClientConfigIfNeeded()
{
if (!PlatformIdentifier.IsMac())
return;
string clientConfFile = ConfigFileLocation.GetConfigFilePath(
ClientConfig.CLIENT_CONFIG_FILE_NAME);
if (File.Exists(clientConfFile))
return;
File.Create(clientConfFile).Close();
mClientConfigCreated = true;
}
internal void DeleteClientConfigIfNeeded()
{
if (!mClientConfigCreated)
return;
string clientConfFile = ConfigFileLocation.GetConfigFilePath(
ClientConfig.CLIENT_CONFIG_FILE_NAME);
File.Delete(clientConfFile);
}
bool mClientConfigCreated;
}
}
using UnityEditor;
using UnityEngine;
using Codice.Client.Common;
using Codice.CM.Common;
using PlasticGui;
using PlasticGui.WebApi;
using Unity.PlasticSCM.Editor.AssetUtils;
using Unity.PlasticSCM.Editor.UI;
using Unity.PlasticSCM.Editor.Views.CreateWorkspace;
using Unity.PlasticSCM.Editor.UI.Progress;
namespace Unity.PlasticSCM.Editor.Views.Welcome
{
internal class WelcomeView
{
internal WelcomeView(
EditorWindow parentWindow,
CreateWorkspaceView.ICreateWorkspaceListener createWorkspaceListener,
PlasticAPI plasticApi,
IPlasticWebRestApi plasticWebRestApi)
{
mParentWindow = parentWindow;
mCreateWorkspaceListener = createWorkspaceListener;
mPlasticApi = plasticApi;
mPlasticWebRestApi = plasticWebRestApi;
mGuiMessage = new UnityPlasticGuiMessage(parentWindow);
mDownloadProgress = new ProgressControlsForViews();
mConfigureProgress = new ProgressControlsForViews();
mInstallerFile = GetInstallerTmpFileName.ForPlatform();
}
internal void Update()
{
if (mCreateWorkspaceView != null)
mCreateWorkspaceView.Update();
mDownloadProgress.UpdateDeterminateProgress(mParentWindow);
mConfigureProgress.UpdateDeterminateProgress(mParentWindow);
}
internal void OnGUI(
bool isPlasticExeAvailable,
bool clientNeedsConfiguration,
bool isGluonMode)
{
GUILayout.BeginHorizontal();
GUILayout.Space(LEFT_MARGIN);
DoContentViewArea(
isPlasticExeAvailable,
clientNeedsConfiguration,
isGluonMode,
mIsCreateWorkspaceButtonClicked,
mInstallerFile,
mGuiMessage,
mDownloadProgress,
mConfigureProgress);
GUILayout.EndHorizontal();
}
void DoContentViewArea(
bool isPlasticExeAvailable,
bool clientNeedsConfiguration,
bool isGluonMode,
bool isCreateWorkspaceButtonClicked,
string installerFile,
GuiMessage.IGuiMessage guiMessage,
ProgressControlsForViews downloadProgress,
ProgressControlsForViews configureProgress)
{
GUILayout.BeginVertical();
GUILayout.Space(TOP_MARGIN);
if (isCreateWorkspaceButtonClicked)
GetCreateWorkspaceView().OnGUI();
else
DoSetupViewArea(
isPlasticExeAvailable,
clientNeedsConfiguration,
isGluonMode,
mInstallerFile,
mGuiMessage,
mDownloadProgress,
mConfigureProgress);
GUILayout.EndVertical();
}
void DoSetupViewArea(
bool isPlasticExeAvailable,
bool clientNeedsConfiguration,
bool isGluonMode,
string installerFile,
GuiMessage.IGuiMessage guiMessage,
ProgressControlsForViews downloadProgress,
ProgressControlsForViews configureProgress)
{
DoTitleLabel();
GUILayout.Space(STEPS_TOP_MARGIN);
bool isStep1Completed =
isPlasticExeAvailable &
!downloadProgress.ProgressData.IsOperationRunning;
bool isStep2Completed =
isStep1Completed &
!clientNeedsConfiguration &
!configureProgress.ProgressData.IsOperationRunning;
DoStepsArea(
isStep1Completed,
isStep2Completed,
downloadProgress.ProgressData,
configureProgress.ProgressData);
GUILayout.Space(BUTTON_MARGIN);
DoActionButtonsArea(
isStep1Completed,
isStep2Completed,
isGluonMode,
installerFile,
guiMessage,
downloadProgress,
configureProgress);
DoNotificationArea(
downloadProgress.ProgressData,
configureProgress.ProgressData);
}
void DoActionButtonsArea(
bool isStep1Completed,
bool isStep2Completed,
bool isGluonMode,
string installerFile,
GuiMessage.IGuiMessage guiMessage,
ProgressControlsForViews downloadProgress,
ProgressControlsForViews configureProgress)
{
GUILayout.BeginHorizontal();
DoActionButton(
isStep1Completed,
isStep2Completed,
isGluonMode,
installerFile,
guiMessage,
downloadProgress,
configureProgress);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
void DoActionButton(
bool isStep1Completed,
bool isStep2Completed,
bool isGluonMode,
string installerFile,
GuiMessage.IGuiMessage guiMessage,
ProgressControlsForViews downloadProgress,
ProgressControlsForViews configureProgress)
{
if (!isStep1Completed)
{
DoInstallButton(
downloadProgress, guiMessage, installerFile);
return;
}
if (!isStep2Completed)
{
DoConfigureButton(
isGluonMode, configureProgress);
return;
}
if (GUILayout.Button(PlasticLocalization.GetString(PlasticLocalization.Name.CreateWorkspace),
GUILayout.Width(BUTTON_WIDTH)))
mIsCreateWorkspaceButtonClicked = true;
}
static void DoInstallButton(
ProgressControlsForViews downloadProgress,
GuiMessage.IGuiMessage guiMessage,
string installerFile)
{
GUI.enabled = !downloadProgress.ProgressData.IsOperationRunning;
if (GUILayout.Button(PlasticLocalization.GetString(PlasticLocalization.Name.InstallPlasticSCM),
GUILayout.Width(BUTTON_WIDTH)))
{
Edition plasticEdition;
if (TryGetPlasticEditionToDownload(
guiMessage, out plasticEdition))
{
DownloadAndInstallOperation.Run(
plasticEdition, installerFile,
downloadProgress);
GUIUtility.ExitGUI();
}
}
GUI.enabled = true;
}
static void DoConfigureButton(
bool isGluonMode,
ProgressControlsForViews configureProgress)
{
GUI.enabled = !configureProgress.ProgressData.IsOperationRunning;
if (GUILayout.Button(PlasticLocalization.GetString(PlasticLocalization.Name.LoginOrSignUp),
GUILayout.Width(BUTTON_WIDTH)))
{
ConfigurePlasticOperation.Run(
isGluonMode,
configureProgress);
GUIUtility.ExitGUI();
}
GUI.enabled = true;
}
static void DoStepsArea(
bool isStep1Completed,
bool isStep2Completed,
ProgressControlsForViews.Data downloadProgressData,
ProgressControlsForViews.Data configureProgressData)
{
DoDownloadAndInstallStep(
isStep1Completed,
downloadProgressData);
DoLoginOrSignUpStep(
isStep2Completed,
configureProgressData);
DoCreatePlasticWorkspaceStep();
}
static void DoDownloadAndInstallStep(
bool isStep1Completed,
ProgressControlsForViews.Data progressData)
{
Images.Name stepImage = (isStep1Completed) ?
Images.Name.StepOk :
Images.Name.Step1;
string stepText = GetDownloadStepText(
progressData,
isStep1Completed);
GUIStyle style = new GUIStyle(EditorStyles.label);
style.richText = true;
GUILayout.BeginHorizontal();
DoStepLabel(
stepText,
stepImage,
style);
GUILayout.EndHorizontal();
}
static void DoLoginOrSignUpStep(
bool isStep2Completed,
ProgressControlsForViews.Data progressData)
{
Images.Name stepImage = (isStep2Completed) ?
Images.Name.StepOk :
Images.Name.Step2;
string stepText = GetConfigurationStepText(
progressData,
isStep2Completed);
GUIStyle style = new GUIStyle(EditorStyles.label);
style.richText = true;
GUILayout.BeginHorizontal();
DoStepLabel(
stepText,
stepImage,
style);
GUILayout.EndHorizontal();
}
static void DoCreatePlasticWorkspaceStep()
{
GUILayout.BeginHorizontal();
DoStepLabel(
PlasticLocalization.GetString(PlasticLocalization.Name.CreateAPlasticWorkspace),
Images.Name.Step3,
EditorStyles.label);
GUILayout.EndHorizontal();
}
static void DoStepLabel(
string text,
Images.Name imageName,
GUIStyle style)
{
GUILayout.Space(STEPS_LEFT_MARGIN);
GUIContent stepLabelContent = new GUIContent(
string.Format(" {0}", text),
Images.GetImage(imageName));
GUILayout.Label(
stepLabelContent,
style,
GUILayout.Height(STEP_LABEL_HEIGHT));
}
static void DoTitleLabel()
{
GUIContent labelContent = new GUIContent(
PlasticLocalization.GetString(PlasticLocalization.Name.NextStepsToSetup),
Images.GetInfoIcon());
GUILayout.Label(labelContent, EditorStyles.boldLabel);
}
static void DoNotificationArea(
ProgressControlsForViews.Data downloadProgressData,
ProgressControlsForViews.Data configureProgressData)
{
if (!string.IsNullOrEmpty(downloadProgressData.NotificationMessage))
DrawProgressForViews.ForNotificationArea(downloadProgressData);
if (!string.IsNullOrEmpty(configureProgressData.NotificationMessage))
DrawProgressForViews.ForNotificationArea(configureProgressData);
}
static string GetDownloadStepText(
ProgressControlsForViews.Data progressData,
bool isStep1Completed)
{
string result = PlasticLocalization.GetString(PlasticLocalization.Name.DownloadAndInstall);
if (isStep1Completed)
return result;
if (progressData.IsOperationRunning)
result = string.Format("<b>{0}</b> - ", result);
result += progressData.ProgressMessage;
if (progressData.IsOperationRunning && progressData.ProgressPercent >= 0)
{
result += string.Format(
" {0}%", progressData.ProgressPercent * 100);
}
return result;
}
static string GetConfigurationStepText(
ProgressControlsForViews.Data progressData,
bool isStep2Completed)
{
string result = PlasticLocalization.GetString(PlasticLocalization.Name.LoginOrSignUpPlastic);
if (isStep2Completed)
return result;
if (!progressData.IsOperationRunning)
return result;
return string.Format("<b>{0}</b>", result);
}
static bool TryGetPlasticEditionToDownload(
GuiMessage.IGuiMessage guiMessage,
out Edition plasticEdition)
{
plasticEdition = Edition.Cloud;
if (EditionToken.IsCloudEdition())
return true;
GuiMessage.GuiMessageResponseButton result = guiMessage.ShowQuestion(
PlasticLocalization.GetString(PlasticLocalization.Name.PlasticSCM),
PlasticLocalization.GetString(PlasticLocalization.Name.WhichVersionInstall),
PlasticLocalization.GetString(PlasticLocalization.Name.DownloadCloudEdition),
PlasticLocalization.GetString(PlasticLocalization.Name.DownloadEnterpriseEdition),
PlasticLocalization.GetString(PlasticLocalization.Name.CancelButton),
true);
if (result == GuiMessage.GuiMessageResponseButton.Third)
return false;
if (result == GuiMessage.GuiMessageResponseButton.First)
return true;
plasticEdition = Edition.Enterprise;
return true;
}
CreateWorkspaceView GetCreateWorkspaceView()
{
if (mCreateWorkspaceView != null)
return mCreateWorkspaceView;
string workspacePath = ProjectPath.FromApplicationDataPath(
Application.dataPath);
mCreateWorkspaceView = new CreateWorkspaceView(
mParentWindow,
mCreateWorkspaceListener,
mPlasticApi,
mPlasticWebRestApi,
workspacePath);
return mCreateWorkspaceView;
}
string mInstallerFile;
bool mIsCreateWorkspaceButtonClicked = false;
CreateWorkspaceView mCreateWorkspaceView;
readonly ProgressControlsForViews mDownloadProgress;
readonly ProgressControlsForViews mConfigureProgress;
readonly GuiMessage.IGuiMessage mGuiMessage;
readonly PlasticAPI mPlasticApi;
readonly IPlasticWebRestApi mPlasticWebRestApi;
readonly CreateWorkspaceView.ICreateWorkspaceListener mCreateWorkspaceListener;
readonly EditorWindow mParentWindow;
const int LEFT_MARGIN = 30;
const int TOP_MARGIN = 20;
const int STEPS_TOP_MARGIN = 5;
const int STEPS_LEFT_MARGIN = 12;
const int BUTTON_MARGIN = 10;
const int STEP_LABEL_HEIGHT = 20;
const int BUTTON_WIDTH = 170;
const string DOWNLOAD_URL = @"https://www.plasticscm.com/download";
}
}
using System.Reflection;
using Newtonsoft.Json;
using PlasticGui.WebApi.Responses;
namespace Unity.PlasticSCM.Editor.WebApi
{
[ObfuscationAttribute(Exclude = true)]
public class CredentialsResponse
{
[JsonProperty("error")]
public ErrorResponse.ErrorFields Error { get; set; }
public enum TokenType : int
{
Password = 0,
Bearer = 1,
}
[JsonIgnore]
public TokenType Type
{
get { return (TokenType)TokenTypeValue; }
}
[JsonProperty("email")]
public string Email;
[JsonProperty("token")]
public string Token;
[JsonProperty("tokenTypeValue")]
public int TokenTypeValue;
}
}
using System;
using System.IO;
using System.Net;
using Newtonsoft.Json;
using Codice.Client.Common.WebApi;
using Codice.CM.Common;
using Codice.LogWrapper;
using PlasticGui.Help.NewVersions;
using PlasticGui.WebApi.Responses;
namespace Unity.PlasticSCM.Editor.WebApi
{
internal static class PlasticScmRestApiClient
{
internal static UnityPackageBetaEnrollResponse IsBetaEnabled(string bearerToken)
{
Uri endpoint = mWebApiUris.GetFullUri(IsBetaEnabledEndpoint);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint);
request.Method = "GET";
request.ContentType = "application/json";
request.Headers.Add(
HttpRequestHeader.Authorization,
string.Format("Bearer {0}", bearerToken));
return GetResponse<UnityPackageBetaEnrollResponse>(request);
}
catch (Exception ex)
{
mLog.ErrorFormat(
"Unable to retrieve is beta enabled '{0}': {1}",
endpoint.ToString(), ex.Message);
mLog.DebugFormat(
"StackTrace:{0}{1}",
Environment.NewLine, ex.StackTrace);
return null;
}
}
internal static NewVersionResponse GetLastVersion(Edition plasticEdition)
{
Uri endpoint = mWebApiUris.GetFullUri(
WebApiEndpoints.LastVersion.NewVersion,
"9.0.0.0",
WebApiEndpoints.LastVersion.GetEditionString(plasticEdition),
WebApiEndpoints.LastVersion.GetPlatformString());
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint);
request.Method = "GET";
request.ContentType = "application/json";
return GetResponse<NewVersionResponse>(request);
}
catch (Exception ex)
{
mLog.ErrorFormat(
"Unable to retrieve new versions from '{0}': {1}",
endpoint.ToString(), ex.Message);
mLog.DebugFormat(
"StackTrace:{0}{1}",
Environment.NewLine, ex.StackTrace);
return null;
}
}
internal static CredentialsResponse GetCredentials(string unityToken)
{
Uri endpoint = mWebApiUris.GetFullUri(
WebApiEndpoints.Authentication.Credentials,
unityToken);
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endpoint);
request.Method = "GET";
request.ContentType = "application/json";
return GetResponse<CredentialsResponse>(request);
}
catch (Exception ex)
{
return new CredentialsResponse
{
Error = BuildLoggedErrorFields(ex, endpoint)
};
}
}
static TRes GetResponse<TRes>(WebRequest request)
{
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string json = reader.ReadToEnd();
if (string.IsNullOrEmpty(json))
return default(TRes);
return JsonConvert.DeserializeObject<TRes>(json);
}
}
static ErrorResponse.ErrorFields BuildLoggedErrorFields(
Exception ex, Uri endpoint)
{
LogException(ex, endpoint);
return new ErrorResponse.ErrorFields
{
ErrorCode = ErrorCodes.ClientError,
Message = ex.Message
};
}
static void LogException(Exception ex, Uri endpoint)
{
mLog.ErrorFormat(
"There was an error while calling '{0}': {1}",
endpoint.ToString(), ex.Message);
mLog.DebugFormat(
"StackTrace:{0}{1}",
Environment.NewLine, ex.StackTrace);
}
const string IsBetaEnabledEndpoint = "api/unity-package/beta/is-enabled";
static readonly PlasticWebApiUris mWebApiUris = PlasticWebApiUris.BuildDefault();
static readonly ILog mLog = LogManager.GetLogger("PlasticScmRestApiClient");
}
}
using Newtonsoft.Json;
using PlasticGui.WebApi.Responses;
namespace Unity.PlasticSCM.Editor.WebApi
{
public class UnityPackageBetaEnrollResponse
{
[JsonProperty("error")]
public ErrorResponse.ErrorFields Error { get; set; }
[JsonProperty("isBetaEnabled")]
public bool IsBetaEnabled { get; set; }
}
}
Unity Collaborate copyright © 2021 Unity Technologies ApS
Licensed under the Unity Companion License for Unity-dependent projects--see [Unity Companion License](http://www.unity3d.com/legal/licenses/Unity_Companion_License).
Unless expressly provided otherwise, the Software under this license is made available strictly on an “AS IS” BASIS WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. Please review the license for details on these and other terms and conditions.
The MIT License (MIT)
Copyright (c) Microsoft Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment