~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeSyncedContent.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// XcodeSyncedContent.cs
3
 
//  
4
 
// Author:
5
 
//       Michael Hutchinson <mhutch@xamarin.com>
6
 
// 
7
 
// Copyright (c) Xamarin, Inc. (http://xamarin.com)
8
 
// 
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:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
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
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using System.Linq;
29
 
using System.IO;
30
 
using System.Collections.Generic;
31
 
 
32
 
using MonoDevelop.Core;
33
 
using MonoDevelop.Projects;
34
 
using MonoDevelop.MacDev.ObjCIntegration;
35
 
using System.Threading.Tasks;
36
 
using MonoDevelop.MacDev.XcodeIntegration;
37
 
 
38
 
namespace MonoDevelop.MacDev.XcodeSyncing
39
 
{
40
 
        class XcodeSyncedContent : XcodeSyncedItem
41
 
        {
42
 
                FilePath targetRelative, source;
43
 
                bool isInterfaceDefinition;
44
 
                
45
 
                public XcodeSyncedContent (ProjectFile p)
46
 
                {
47
 
                        this.targetRelative = p.ProjectVirtualPath;
48
 
                        this.source = p.FilePath;
49
 
                        isInterfaceDefinition = p.BuildAction == BuildAction.InterfaceDefinition;
50
 
                }
51
 
                
52
 
                public override bool NeedsSyncOut (IProgressMonitor monitor, XcodeSyncContext context)
53
 
                {
54
 
                        string target = context.ProjectDir.Combine (targetRelative);
55
 
                        
56
 
                        if (!File.Exists (target))
57
 
                                return true;
58
 
                        
59
 
                        if (File.GetLastWriteTime (source) > context.GetSyncTime (targetRelative)) {
60
 
                                monitor.Log.WriteLine ("{0} has changed since last sync.", targetRelative);
61
 
                                return true;
62
 
                        }
63
 
                        
64
 
                        return false;
65
 
                }
66
 
                
67
 
                public override void SyncOut (IProgressMonitor monitor, XcodeSyncContext context)
68
 
                {
69
 
                        monitor.Log.WriteLine ("Exporting '{0}' to Xcode.", targetRelative);
70
 
                        
71
 
                        var target = context.ProjectDir.Combine (targetRelative);
72
 
                        var dir = target.ParentDirectory;
73
 
                        
74
 
                        if (!Directory.Exists (dir))
75
 
                                Directory.CreateDirectory (dir);
76
 
                        
77
 
                        if (File.Exists (target))
78
 
                                File.Delete (target);
79
 
                        
80
 
                        File.Copy (source, target);
81
 
                        DateTime mtime = File.GetLastWriteTime (target);
82
 
                        context.SetSyncTime (targetRelative, mtime);
83
 
                }
84
 
                
85
 
                public override bool NeedsSyncBack (IProgressMonitor monitor, XcodeSyncContext context)
86
 
                {
87
 
                        if (!isInterfaceDefinition)
88
 
                                return false;
89
 
                        
90
 
                        string target = context.ProjectDir.Combine (targetRelative);
91
 
                        
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
95
 
                                return false;
96
 
                        }
97
 
                        
98
 
                        if (File.GetLastWriteTime (target) > context.GetSyncTime (targetRelative)) {
99
 
                                monitor.Log.WriteLine ("{0} has changed since last sync.", targetRelative);
100
 
                                return true;
101
 
                        }
102
 
                        
103
 
                        return false;
104
 
                }
105
 
                
106
 
                public override void SyncBack (IProgressMonitor monitor, XcodeSyncBackContext context)
107
 
                {
108
 
                        monitor.Log.WriteLine ("Queueing sync-back of changes made to '{0}' from Xcode.", targetRelative);
109
 
                        
110
 
                        context.FileSyncJobs.Add (new XcodeSyncFileBackJob (source, targetRelative, false));
111
 
                }
112
 
                
113
 
                public override void AddToProject (XcodeProject project, FilePath syncProjectDir)
114
 
                {
115
 
                        project.AddResource (targetRelative);
116
 
                }
117
 
                
118
 
                public override string[] GetTargetRelativeFileNames ()
119
 
                {
120
 
                        return new string [] { 
121
 
                                targetRelative,
122
 
                        };
123
 
                }
124
 
        }
125
 
}