2
// XcodeSyncedContent.cs
5
// Michael Hutchinson <mhutch@xamarin.com>
7
// Copyright (c) Xamarin, Inc. (http://xamarin.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
using System.Collections.Generic;
32
using MonoDevelop.Core;
33
using MonoDevelop.Projects;
34
using MonoDevelop.MacDev.ObjCIntegration;
35
using System.Threading.Tasks;
36
using MonoDevelop.MacDev.XcodeIntegration;
38
namespace MonoDevelop.MacDev.XcodeSyncing
40
class XcodeSyncedContent : XcodeSyncedItem
42
FilePath targetRelative, source;
43
bool isInterfaceDefinition;
45
public XcodeSyncedContent (ProjectFile p)
47
this.targetRelative = p.ProjectVirtualPath;
48
this.source = p.FilePath;
49
isInterfaceDefinition = p.BuildAction == BuildAction.InterfaceDefinition;
52
public override bool NeedsSyncOut (IProgressMonitor monitor, XcodeSyncContext context)
54
string target = context.ProjectDir.Combine (targetRelative);
56
if (!File.Exists (target))
59
if (File.GetLastWriteTime (source) > context.GetSyncTime (targetRelative)) {
60
monitor.Log.WriteLine ("{0} has changed since last sync.", targetRelative);
67
public override void SyncOut (IProgressMonitor monitor, XcodeSyncContext context)
69
monitor.Log.WriteLine ("Exporting '{0}' to Xcode.", targetRelative);
71
var target = context.ProjectDir.Combine (targetRelative);
72
var dir = target.ParentDirectory;
74
if (!Directory.Exists (dir))
75
Directory.CreateDirectory (dir);
77
if (File.Exists (target))
80
File.Copy (source, target);
81
DateTime mtime = File.GetLastWriteTime (target);
82
context.SetSyncTime (targetRelative, mtime);
85
public override bool NeedsSyncBack (IProgressMonitor monitor, XcodeSyncContext context)
87
if (!isInterfaceDefinition)
90
string target = context.ProjectDir.Combine (targetRelative);
92
if (!File.Exists (target)) {
93
monitor.Log.WriteLine ("{0} has been removed since last sync.", targetRelative);
94
// FIXME: some day we should mirror this change back to MonoDevelop
98
if (File.GetLastWriteTime (target) > context.GetSyncTime (targetRelative)) {
99
monitor.Log.WriteLine ("{0} has changed since last sync.", targetRelative);
106
public override void SyncBack (IProgressMonitor monitor, XcodeSyncBackContext context)
108
monitor.Log.WriteLine ("Queueing sync-back of changes made to '{0}' from Xcode.", targetRelative);
110
context.FileSyncJobs.Add (new XcodeSyncFileBackJob (source, targetRelative, false));
113
public override void AddToProject (XcodeProject project, FilePath syncProjectDir)
115
project.AddResource (targetRelative);
118
public override string[] GetTargetRelativeFileNames ()
120
return new string [] {