[longomatch] Fix the migration tool



commit 5aae99e40b449d01c3b6ca78419d8fbf2daf623a
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Oct 13 14:51:07 2014 +0200

    Fix the migration tool

 LongoMatch.Core/Common/EventsBroker.cs             |    8 +
 LongoMatch.Core/Handlers/Handlers.cs               |    1 +
 LongoMatch.GUI/Gui/MainWindow.cs                   |    5 +
 .../gtk-gui/LongoMatch.Gui.MainWindow.cs           |    7 +-
 LongoMatch.GUI/gtk-gui/gui.stetic                  |    7 +
 LongoMatch.Migration/Converter.cs                  |  376 +++++++++++++++-----
 LongoMatch.Migration/LongoMatch.Migration.csproj   |   26 ++-
 LongoMatch.Migration/MainWindow.cs                 |  147 +++++---
 LongoMatch.Migration/Makefile.am                   |    4 +-
 LongoMatch.Migration/Program.cs                    |   45 +++-
 LongoMatch.Migration/gtk-gui/MainWindow.cs         |   84 +++--
 LongoMatch.Migration/gtk-gui/gui.stetic            |   22 +-
 LongoMatch.Services/Services/ToolsManager.cs       |   23 ++
 build/build.environment.mk                         |    1 +
 build/build.rules.mk                               |    2 +-
 15 files changed, 560 insertions(+), 198 deletions(-)
---
diff --git a/LongoMatch.Core/Common/EventsBroker.cs b/LongoMatch.Core/Common/EventsBroker.cs
index e03e340..82074f5 100644
--- a/LongoMatch.Core/Common/EventsBroker.cs
+++ b/LongoMatch.Core/Common/EventsBroker.cs
@@ -76,6 +76,7 @@ namespace LongoMatch.Core.Common
                public event ManageDatabases ManageDatabasesEvent;
                public event EditPreferences EditPreferencesEvent;
                public event ConvertVideoFilesHandler ConvertVideoFilesEvent;
+               public event MigrateDBHandler MigrateDB;
                
                public event OpenedProjectChangedHandler OpenedProjectChanged;
                
@@ -397,6 +398,13 @@ namespace LongoMatch.Core.Common
                                SeekEvent (time, accurate);
                        }
                }
+               
+               public void EmitMigrateDB ()
+               {
+                       if (MigrateDB != null) {
+                               MigrateDB ();
+                       }
+               }
        }
 }
 
diff --git a/LongoMatch.Core/Handlers/Handlers.cs b/LongoMatch.Core/Handlers/Handlers.cs
index f686862..fe1f203 100644
--- a/LongoMatch.Core/Handlers/Handlers.cs
+++ b/LongoMatch.Core/Handlers/Handlers.cs
@@ -81,6 +81,7 @@ namespace LongoMatch.Core.Handlers
        public delegate void ManageProjects ();
        public delegate void ManageDatabases ();
        public delegate void EditPreferences ();
+       public delegate void MigrateDBHandler ();
        /*Playlist Events*/
        /* Create a new playlist */
        public delegate Playlist NewPlaylistHandler (Project project);
diff --git a/LongoMatch.GUI/Gui/MainWindow.cs b/LongoMatch.GUI/Gui/MainWindow.cs
index b44fb2a..a8c9262 100644
--- a/LongoMatch.GUI/Gui/MainWindow.cs
+++ b/LongoMatch.GUI/Gui/MainWindow.cs
@@ -311,6 +311,11 @@ namespace LongoMatch.Gui
                        info.Run();
                        info.Destroy();
                }
+
+               protected void OnMigrationToolActionActivated(object sender, EventArgs e)
+               {
+                       Config.EventsBroker.EmitMigrateDB ();
+               }
                #endregion
        }
 }
diff --git a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs 
b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs
index 60d4f6a..80a377a 100644
--- a/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs
+++ b/LongoMatch.GUI/gtk-gui/LongoMatch.Gui.MainWindow.cs
@@ -33,6 +33,7 @@ namespace LongoMatch.Gui
                private global::Gtk.Action DatabasesManagerAction;
                private global::Gtk.Action PreferencesAction;
                private global::Gtk.Action ShowProjectStatsAction;
+               private global::Gtk.Action MigrationToolAction;
                private global::Gtk.VBox vbox1;
                private global::Gtk.VBox menubox;
                private global::Gtk.MenuBar menubar1;
@@ -136,6 +137,9 @@ namespace LongoMatch.Gui
                        this.ShowProjectStatsAction.Sensitive = false;
                        this.ShowProjectStatsAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("Show 
project stats");
                        w1.Add (this.ShowProjectStatsAction, null);
+                       this.MigrationToolAction = new global::Gtk.Action ("MigrationToolAction", 
global::Mono.Unix.Catalog.GetString ("Migration Tool"), null, null);
+                       this.MigrationToolAction.ShortLabel = global::Mono.Unix.Catalog.GetString ("Migration 
Tool");
+                       w1.Add (this.MigrationToolAction, null);
                        this.UIManager.InsertActionGroup (w1, 0);
                        this.AddAccelGroup (this.UIManager.AccelGroup);
                        this.Name = "LongoMatch.Gui.MainWindow";
@@ -151,7 +155,7 @@ namespace LongoMatch.Gui
                        this.menubox.Name = "menubox";
                        this.menubox.Spacing = 6;
                        // Container child menubox.Gtk.Box+BoxChild
-                       this.UIManager.AddUiFromString ("<ui><menubar name='menubar1'><menu name='FileAction' 
action='FileAction'><menuitem name='NewPojectAction' action='NewPojectAction'/><menuitem name='openAction' 
action='openAction'/><menuitem name='SaveProjectAction' action='SaveProjectAction'/><menuitem 
name='CloseProjectAction' action='CloseProjectAction'/><separator/><menuitem name='ImportProjectAction' 
action='ImportProjectAction'/><separator/><menuitem name='PreferencesAction' 
action='PreferencesAction'/><separator/><menuitem name='QuitAction' action='QuitAction'/></menu><menu 
name='ToolsAction' action='ToolsAction'><menuitem name='ProjectsManagerAction' 
action='ProjectsManagerAction'/><menuitem name='CategoriesTemplatesManagerAction' 
action='CategoriesTemplatesManagerAction'/><menuitem name='TeamsTemplatesManagerAction' 
action='TeamsTemplatesManagerAction'/><menuitem name='DatabasesManagerAction' 
action='DatabasesManagerAction'/><separator/><menuitem name='ShowProjectStatsAction' acti
 on='ShowProjectStatsAction'/><menu name='ExportProjectAction1' action='ExportProjectAction1'><menuitem 
name='ExportToProjectFileAction' action='ExportToProjectFileAction'/></menu><separator/><menuitem 
name='VideoConverterToolAction' action='VideoConverterToolAction'/></menu><menu name='ViewAction' 
action='ViewAction'><menuitem name='FullScreenAction' action='FullScreenAction'/><separator/><menuitem 
name='TagSubcategoriesAction' action='TagSubcategoriesAction'/></menu><menu name='HelpAction' 
action='HelpAction'><menuitem name='AboutAction' action='AboutAction'/><menuitem name='HelpAction1' 
action='HelpAction1'/><menuitem name='dialogInfoAction' action='dialogInfoAction'/></menu></menubar></ui>");
+                       this.UIManager.AddUiFromString ("<ui><menubar name='menubar1'><menu name='FileAction' 
action='FileAction'><menuitem name='NewPojectAction' action='NewPojectAction'/><menuitem name='openAction' 
action='openAction'/><menuitem name='SaveProjectAction' action='SaveProjectAction'/><menuitem 
name='CloseProjectAction' action='CloseProjectAction'/><separator/><menuitem name='ImportProjectAction' 
action='ImportProjectAction'/><separator/><menuitem name='PreferencesAction' 
action='PreferencesAction'/><separator/><menuitem name='QuitAction' action='QuitAction'/></menu><menu 
name='ToolsAction' action='ToolsAction'><menuitem name='ProjectsManagerAction' 
action='ProjectsManagerAction'/><menuitem name='CategoriesTemplatesManagerAction' 
action='CategoriesTemplatesManagerAction'/><menuitem name='TeamsTemplatesManagerAction' 
action='TeamsTemplatesManagerAction'/><menuitem name='DatabasesManagerAction' 
action='DatabasesManagerAction'/><separator/><menuitem name='ShowProjectStatsAction' acti
 on='ShowProjectStatsAction'/><menu name='ExportProjectAction1' action='ExportProjectAction1'><menuitem 
name='ExportToProjectFileAction' action='ExportToProjectFileAction'/></menu><separator/><menuitem 
name='VideoConverterToolAction' action='VideoConverterToolAction'/><menuitem name='MigrationToolAction' 
action='MigrationToolAction'/></menu><menu name='ViewAction' action='ViewAction'><menuitem 
name='FullScreenAction' action='FullScreenAction'/><separator/><menuitem name='TagSubcategoriesAction' 
action='TagSubcategoriesAction'/></menu><menu name='HelpAction' action='HelpAction'><menuitem 
name='AboutAction' action='AboutAction'/><menuitem name='HelpAction1' action='HelpAction1'/><menuitem 
name='dialogInfoAction' action='dialogInfoAction'/></menu></menubar></ui>");
                        this.menubar1 = ((global::Gtk.MenuBar)(this.UIManager.GetWidget ("/menubar1")));
                        this.menubar1.Name = "menubar1";
                        this.menubox.Add (this.menubar1);
@@ -200,6 +204,7 @@ namespace LongoMatch.Gui
                        this.HelpAction1.Activated += new global::System.EventHandler 
(this.OnHelpAction1Activated);
                        this.dialogInfoAction.Activated += new global::System.EventHandler 
(this.OnDialogInfoActionActivated);
                        this.VideoConverterToolAction.Activated += new global::System.EventHandler 
(this.OnVideoConverterToolActionActivated);
+                       this.MigrationToolAction.Activated += new global::System.EventHandler 
(this.OnMigrationToolActionActivated);
                }
        }
 }
diff --git a/LongoMatch.GUI/gtk-gui/gui.stetic b/LongoMatch.GUI/gtk-gui/gui.stetic
index d7e81c6..3a43dad 100644
--- a/LongoMatch.GUI/gtk-gui/gui.stetic
+++ b/LongoMatch.GUI/gtk-gui/gui.stetic
@@ -784,6 +784,12 @@
         <property name="Sensitive">False</property>
         <property name="ShortLabel" translatable="yes">Show project stats</property>
       </action>
+      <action id="MigrationToolAction">
+        <property name="Type">Action</property>
+        <property name="Label" translatable="yes">Migration Tool</property>
+        <property name="ShortLabel" translatable="yes">Migration Tool</property>
+        <signal name="Activated" handler="OnMigrationToolActionActivated" />
+      </action>
     </action-group>
     <property name="MemberName" />
     <property name="Title" translatable="yes">LongoMatch</property>
@@ -825,6 +831,7 @@
                     </node>
                     <node type="Separator" />
                     <node type="Menuitem" action="VideoConverterToolAction" />
+                    <node type="Menuitem" action="MigrationToolAction" />
                   </node>
                   <node type="Menu" action="ViewAction">
                     <node type="Menuitem" action="FullScreenAction" />
diff --git a/LongoMatch.Migration/Converter.cs b/LongoMatch.Migration/Converter.cs
index 591efb8..a07da9b 100644
--- a/LongoMatch.Migration/Converter.cs
+++ b/LongoMatch.Migration/Converter.cs
@@ -29,133 +29,331 @@ namespace LongoMatch.Migration
 {
        public class Converter
        {
-               
-               public static void ConvertCategories (string inputPath, string outputPath) {
-                       Categories cats = SerializableObject.Load<Categories> (inputPath,
-                                                                              SerializationType.Binary);
+               static LongoMatch.Core.Common.Point ConvertPoint (Point newp)
+               {
+                       return new LongoMatch.Core.Common.Point (newp.DX, newp.DY);
+               }
+
+               static LongoMatch.Core.Common.Image ConvertImage (Image image)
+               {
+                       if (image == null) {
+                               return null;
+                       }
+                       return new LongoMatch.Core.Common.Image (image.Value); 
+               }
+
+               static LongoMatch.Core.Store.Time ConvertTime (Time time)
+               {
+                       return new LongoMatch.Core.Store.Time (time.MSeconds); 
+               }
+
+               static LongoMatch.Core.Common.Color ConvertColor (System.Drawing.Color color)
+               {
+                       return new LongoMatch.Core.Common.Color (color.R, color.G, color.B); 
+               }
+
+               static LongoMatch.Core.Store.HotKey ConvertHotkey (HotKey hotkey)
+               {
+                       return new LongoMatch.Core.Store.HotKey { Key = hotkey.Key, Modifier = 
hotkey.Modifier }; 
+               }
+
+               static LongoMatch.Core.Store.FrameDrawing ConvertFrameDrawing (Drawing keyFrameDrawing)
+               {
+                       if (keyFrameDrawing == null)
+                               return null;
+                       var frameDrawing = new LongoMatch.Core.Store.FrameDrawing ();
+                       frameDrawing.Freehand = ConvertImage (keyFrameDrawing.Pixbuf);
+                       frameDrawing.Render = new LongoMatch.Core.Store.Time (keyFrameDrawing.RenderTime);
+                       frameDrawing.Pause = new LongoMatch.Core.Store.Time (5000);
+                       return frameDrawing;
+               }
+
+               static LongoMatch.Core.Store.MediaFile ConvertMediaFile (MediaFile file)
+               {
+                       var newf = new LongoMatch.Core.Store.MediaFile ();
+                       newf.AudioCodec = file.AudioCodec;
+                       newf.Container = file.Container;
+                       newf.Duration = ConvertTime (file.Duration);
+                       newf.FilePath = file.FilePath;
+                       newf.Fps = file.Fps;
+                       newf.HasAudio = file.HasAudio;
+                       newf.HasVideo = file.HasVideo;
+                       newf.Par = file.Par;
+                       newf.Preview = ConvertImage (file.Preview);
+                       newf.VideoCodec = file.VideoCodec;
+                       newf.VideoHeight = file.VideoHeight;
+                       newf.VideoWidth = file.VideoWidth;
+                       return newf;
+               }
+
+               static LongoMatch.Core.Store.ProjectDescription ConvertProjectDescription (ProjectDescription 
desc)
+               {
+                       var newdesc = new LongoMatch.Core.Store.ProjectDescription ();
+                       newdesc.Season = desc.Season;
+                       newdesc.Competition = desc.Competition;
+                       newdesc.Category = desc.Category;
+                       newdesc.LocalName = desc.LocalName;
+                       newdesc.VisitorName = desc.VisitorName;
+                       newdesc.LocalGoals = desc.LocalGoals;
+                       newdesc.VisitorGoals = desc.VisitorGoals;
+                       newdesc.MatchDate = desc.MatchDate;
+                       newdesc.LastModified = desc.LastModified;
+                       newdesc.FileSet = new LongoMatch.Core.Store.MediaFileSet ();
+                       newdesc.FileSet.SetAngle (LongoMatch.Core.Common.MediaFileAngle.Angle1,
+                                                 ConvertMediaFile (desc.File));
+                       return newdesc;
+               }
+
+               static LongoMatch.Core.Store.Player ConvertPlayer (Player p)
+               {
+                       var player = new LongoMatch.Core.Store.Player ();
+                       if (p.ID == Guid.Empty) {
+                               p.ID = new Guid ();
+                       } else {
+                               player.ID = p.ID;
+                       }
+                       player.Name = p.Name;
+                       player.Position = p.Position;
+                       player.Number = p.Number;
+                       player.Photo = ConvertImage (p.Photo);
+                       player.Birthday = p.Birthday;
+                       player.Nationality = p.Nationality;
+                       player.Height = p.Height;
+                       player.Weight = p.Weight;
+                       player.Playing = p.Playing;
+                       player.Mail = p.Mail;
+                       return player;
+               }
+
+               public static LongoMatch.Core.Store.Templates.Dashboard ConvertCategories (Categories cats,
+                                                                                          out Dictionary 
<TagSubCategory, List<LongoMatch.Core.Store.Tag>> dict,
+                                                                                          out Dictionary 
<Category, LongoMatch.Core.Store.EventType > eventTypesDict)
+               {
+                       dict = new Dictionary<TagSubCategory, List<LongoMatch.Core.Store.Tag>> ();
+                       eventTypesDict = new Dictionary<Category, LongoMatch.Core.Store.EventType>();
+                       int i = 0;
+                       var dashboard = new LongoMatch.Core.Store.Templates.Dashboard ();
+                       dashboard.Name = cats.Name;
+                       dashboard.Image = ConvertImage (cats.Image);
+                       dashboard.FieldBackground = ConvertImage (cats.FieldBackground);
+                       dashboard.HalfFieldBackground = ConvertImage (cats.HalfFieldBackground);
+                       dashboard.GoalBackground = ConvertImage (cats.GoalBackground);
+                       dashboard.ID = cats.ID;
+                       dashboard.GamePeriods = new List<string> { "1", "2" };
+                       
                        foreach (Category cat in cats) {
-                               cat.UUID = Guid.NewGuid ();
-                               List<SubCategory> l = new List<SubCategory>();
+                               var button = new LongoMatch.Core.Store.AnalysisEventButton {
+                                       Position = new LongoMatch.Core.Common.Point (10 + (i % 7) * (120 + 
10),
+                                                                                    10 + (i / 7) * (80 + 
10)),
+                                       Width = 120,
+                                       Height = 80,
+                               };
+                               button.BackgroundColor = ConvertColor (cat.Color);
+                               button.HotKey = ConvertHotkey (cat.HotKey);
+                               button.TagsPerRow = 4;
+                               button.ShowSubcategories = false;
+                               button.Start = ConvertTime (cat.Start);
+                               button.Stop = ConvertTime (cat.Stop);
+                               button.EventType = new LongoMatch.Core.Store.AnalysisEventType ();
+                               var evt = button.AnalysisEventType;
+                               evt.Name = cat.Name;
+                               evt.ID = cat.UUID;
+                               evt.TagGoalPosition = cat.TagGoalPosition;
+                               evt.TagFieldPosition = cat.TagGoalPosition;
+                               evt.TagHalfFieldPosition = cat.TagHalfFieldPosition;
+                               evt.HalfFieldPositionIsDistance = cat.HalfFieldPositionIsDistance;
+                               evt.FieldPositionIsDistance = cat.FieldPositionIsDistance;
+                               evt.SortMethod = (LongoMatch.Core.Common.SortMethodType)cat.SortMethod;
+                               evt.Color = ConvertColor (cat.Color);
                                foreach (ISubCategory subcat in cat.SubCategories) {
                                        if (subcat is TagSubCategory) {
-                                               SubCategory s = new SubCategory ();
-                                               s.Name = subcat.Name;
-                                               s.AllowMultiple = subcat.AllowMultiple;
-                                               s.Options = (subcat as TagSubCategory).ToList();
-                                               l.Add (s);
+                                               var tagsub = subcat as TagSubCategory;
+                                               var l = new List<LongoMatch.Core.Store.Tag> ();
+                                               foreach (string s in tagsub) {
+                                                       var t = new LongoMatch.Core.Store.Tag (s, 
subcat.Name);
+                                                       l.Add (t);
+                                                       evt.Tags.Add (t);
+                                               }
+                                               dict.Add (tagsub, l);
                                        }
                                }
-                               cat.SubCategoriesList = l;
+                               eventTypesDict.Add (cat, button.EventType);
+                               dashboard.List.Add (button);
+                               i++;
                        }
-                       cats.ID = Guid.NewGuid ();
-                       SerializableObject.Save (cats, outputPath);                     
-               }
-               
-               public static void ConvertTeamTemplate (string inputPath, string outputPath) {
-                       TeamTemplate team = SerializableObject.Load<TeamTemplate> (inputPath,
-                                                                                  SerializationType.Binary);
-                       foreach (Player p in team) {
-                               p.ID = Guid.NewGuid ();
+                       foreach (GameUnit gu in cats.GameUnits) {
+                               var timer = new LongoMatch.Core.Store.TimerButton {
+                                       Position = new LongoMatch.Core.Common.Point (10 + (i % 7) * (120 + 
10),
+                                                                                    10 + (i / 7) * (80 + 
10)),
+                                       Width = 120,
+                                       Height = 80,
+                               };
+                               timer.Timer = new LongoMatch.Core.Store.Timer {
+                                       Name = gu.Name
+                               };
+                               dashboard.List.Add (timer);
+                               i++;
                        }
-                       team.UUID = Guid.NewGuid ();
-                       team.FormationStr = "1-4-3-3";
-                       SerializableObject.Save (team, outputPath);                     
+                       return dashboard;
                }
-               
-               public static void ConvertProject (Project project, string outputDir) {
-                       Dictionary <TagSubCategory, SubCategory> dict = new Dictionary<TagSubCategory, 
SubCategory>();
+
+               static string FixPath (string outputPath)
+               {
+                       int i = 0;
                        
-                       project.Timers = new List<Timer>();
-                       project.Periods = new List<Period>();
-                       for (int i=0; i < project.Categories.GamePeriods.Count; i++) {
-                               int duration = project.Description.File.Duration.MSeconds;
-                               int periodDuration = duration / project.Categories.GamePeriods.Count;
-                               string period = project.Categories.GamePeriods[i];
-
-                               Period p = new Period {Name = period};
-                               p.Start (new Time (i * periodDuration));
-                               p.Stop (new Time (i * periodDuration + periodDuration));
-                               project.Periods.Add (p);
+                       while (System.IO.File.Exists (outputPath)) {
+                               var dir = System.IO.Path.GetDirectoryName (outputPath);
+                               var name = System.IO.Path.GetFileNameWithoutExtension (outputPath);
+                               var ext = System.IO.Path.GetExtension (outputPath);
+                               outputPath = System.IO.Path.Combine (dir, String.Format ("{0}_{1}{2}", name, 
i, ext));
+                               i++;
                        }
+                       return outputPath;
+               }
+
+               public static void ConvertCategories (string inputPath, string outputPath)
+               {
+                       Categories cats = SerializableObject.Load<Categories> (inputPath,
+                                                                              SerializationType.Binary);
+                       Dictionary<TagSubCategory, List<LongoMatch.Core.Store.Tag>> ignore1;
+                       Dictionary <Category, LongoMatch.Core.Store.EventType > ignore2;
+                       var dashboard = ConvertCategories (cats, out ignore1, out ignore2);
+                       outputPath = FixPath (outputPath);
+                       LongoMatch.Core.Common.Serializer.Save (dashboard, outputPath);
+               }
+
+               public static LongoMatch.Core.Store.Templates.TeamTemplate ConvertTeamTemplate (TeamTemplate 
team,
+                                                                                             Dictionary 
<Player, LongoMatch.Core.Store.Player> teamsDict)
+               {
+                       var newteam = new LongoMatch.Core.Store.Templates.TeamTemplate ();
+                       newteam.Name = team.Name;
+                       newteam.TeamName = team.TeamName;
+                       newteam.Shield = ConvertImage (team.Shield);
+                       newteam.ID = team.UUID;
                        
-                       foreach (Player p in project.LocalTeamTemplate) {
-                               p.ID = Guid.NewGuid ();
-                       }
-                       project.LocalTeamTemplate.UUID = Guid.NewGuid ();
-                       foreach (Player p in project.VisitorTeamTemplate) {
-                               p.ID = Guid.NewGuid ();
-                       }
-                       project.LocalTeamTemplate.UUID = Guid.NewGuid ();
-                       foreach (Category cat in project.Categories) {
-                               cat.UUID = Guid.NewGuid ();
-                               List<SubCategory> l = new List<SubCategory>();
-                               foreach (ISubCategory subcat in cat.SubCategories) {
-                                       if (subcat is TagSubCategory) {
-                                               SubCategory s = new SubCategory ();
-                                               s.Name = subcat.Name;
-                                               s.AllowMultiple = subcat.AllowMultiple;
-                                               s.Options = (subcat as TagSubCategory).ToList();
-                                               l.Add (s);
-                                               dict.Add (subcat as TagSubCategory, s);
+                       foreach (Player p in team) {
+                               var newplayer = ConvertPlayer (p);
+                               newteam.List.Add (newplayer);
+                               if (teamsDict != null) {
+                                       if (!teamsDict.ContainsKey (p)) {
+                                               teamsDict.Add (p, newplayer);
                                        }
                                }
-                               cat.SubCategoriesList = l;
                        }
-                       project.Categories.ID = Guid.NewGuid ();
+                       return newteam;
+               }
+
+               public static void ConvertTeamTemplate (string inputPath, string outputPath)
+               {
+                       TeamTemplate team = SerializableObject.Load<TeamTemplate> (inputPath,
+                                                                                  SerializationType.Binary);
+                       var newteam = ConvertTeamTemplate (team, null);
+                       outputPath = FixPath (outputPath);
+                       LongoMatch.Core.Common.Serializer.Save (newteam, outputPath);
+               }
+
+               public static void ConvertProject (Project project, string outputDir)
+               {
+                       Dictionary<TagSubCategory, List<LongoMatch.Core.Store.Tag>> subcatsDict;
+                       Dictionary <Category, LongoMatch.Core.Store.EventType > eventTypesDict;
+                       Image field, halffield, goal;
+                       var teamsDict = new Dictionary <Player, LongoMatch.Core.Store.Player> ();
+                       var newproject = new LongoMatch.Core.Store.Project ();
+                       newproject.ID = project.UUID;
+                       newproject.LocalTeamTemplate = ConvertTeamTemplate (project.LocalTeamTemplate, 
teamsDict);
+                       newproject.VisitorTeamTemplate = ConvertTeamTemplate (project.VisitorTeamTemplate, 
teamsDict);
+                       newproject.Dashboard = ConvertCategories (project.Categories, out subcatsDict, out 
eventTypesDict);
+                       newproject.UpdateEventTypesAndTimers ();
+                       newproject.Description = ConvertProjectDescription (project.Description);
+
+                       if (project.Categories.GamePeriods != null) {
+                               for (int i=0; i < project.Categories.GamePeriods.Count; i++) {
+                                       int duration = project.Description.File.Duration.MSeconds;
+                                       int periodDuration = duration / project.Categories.GamePeriods.Count;
+                                       string period = project.Categories.GamePeriods [i];
+                                       
+                                       var p = new LongoMatch.Core.Store.Period { Name = period };
+                                       p.Nodes.Add (new LongoMatch.Core.Store.TimeNode {
+                                               Name = period,
+                                               Start = new LongoMatch.Core.Store.Time (i * periodDuration),
+                                               Stop = new LongoMatch.Core.Store.Time (i * periodDuration + 
periodDuration)
+                                       });
+                                       newproject.Periods.Add (p);
+                               }
+                       }
                        
-                       foreach (Play play in project.AllPlays ()) {
-                               Coordinates c;
+                       field = project.Categories.FieldBackground;
+                       halffield = project.Categories.HalfFieldBackground;
+                       goal = project.Categories.GoalBackground;
                                
-                               List<Tag> tags = new List<Tag> ();
-                               foreach (StringTag t in play.Tags.Tags) {
-                                       tags.Add (new Tag {SubCategory = dict[t.SubCategory as 
TagSubCategory], Value = t.Value});
+                       foreach (Play play in project.AllPlays ()) {
+                               LongoMatch.Core.Common.Coordinates c;
+
+                               var newplay = new LongoMatch.Core.Store.TimelineEvent ();
+                               newplay.ActiveViews.Add (LongoMatch.Core.Common.MediaFileAngle.Angle1);
+                               var fd = ConvertFrameDrawing (play.KeyFrameDrawing);
+                               if (fd != null) {
+                                       newplay.Drawings.Add (fd);
                                }
-                               play.TagsList = tags;
+                               newplay.EventTime = ConvertTime (play.Start + play.Duration / 2);
+                               newplay.Name = play.Name;
+                               newplay.Notes = play.Notes;
+                               newplay.Rate = play.Rate;
+                               newplay.Start = ConvertTime (play.Start);
+                               newplay.Stop = ConvertTime (play.Stop);
+                               newplay.Team = (LongoMatch.Core.Common.Team) play.Team;
 
-                               play.ID = Guid.NewGuid ();
+                               newplay.EventType = eventTypesDict[play.Category];
                                foreach (Player player in play.Players.GetTagsValues()) {
-                                       play.PlayersList.Add (player);
+                                       newplay.Players.Add (teamsDict [player]);
                                }
-                               
+
+                               foreach (StringTag t in play.Tags.Tags) {
+                                       var tags = subcatsDict [t.SubCategory as TagSubCategory];
+                                       newplay.Tags.Add (tags.FirstOrDefault (e => e.Value == t.Value));
+                               }
+
                                if (play.FieldPosition != null) {
-                                       c = new Coordinates ();
+                                       c = new LongoMatch.Core.Common.Coordinates ();
                                        foreach (Point p in play.FieldPosition) {
-                                               Point newp = p.Normalize 
(project.Categories.FieldBackground.Width,
-                                                                         
project.Categories.FieldBackground.Height);
-                                               c.Add (newp);
+                                               Point newp = p.Normalize (field.Width, field.Height);
+                                               c.Points.Add (ConvertPoint (newp));
                                        }
-                                       play.FieldPosition = c;
+                                       newplay.FieldPosition = c;
                                }
                                
                                if (play.HalfFieldPosition != null) {
-                                       c = new Coordinates ();
+                                       c = new LongoMatch.Core.Common.Coordinates ();
                                        foreach (Point p in play.HalfFieldPosition) {
-                                               Point newp = p.Normalize 
(project.Categories.HalfFieldBackground.Width,
-                                                                         
project.Categories.HalfFieldBackground.Height);
-                                               c.Add (newp);
+                                               Point newp = p.Normalize (halffield.Width, halffield.Height);
+                                               c.Points.Add (ConvertPoint (newp));
                                        }
-                                       play.HalfFieldPosition = c;
+                                       newplay.HalfFieldPosition = c;
                                }
                                
                                if (play.GoalPosition != null) {
-                                       c = new Coordinates ();
+                                       c = new LongoMatch.Core.Common.Coordinates ();
                                        foreach (Point p in play.GoalPosition) {
-                                               Point newp = p.Normalize 
(project.Categories.GoalBackground.Width,
-                                                                         
project.Categories.GoalBackground.Height);
-                                               c.Add (newp);
+                                               Point newp = p.Normalize (goal.Width, goal.Height);
+                                               c.Points.Add (ConvertPoint (newp));
                                        }
-                                       play.GoalPosition = c;
+                                       newplay.GoalPosition = c;
                                }
+                               newproject.Timeline.Add (newplay);
                        }
-                       SerializableObject.Save (project, Path.Combine (outputDir, project.UUID.ToString())); 
                  
+                       field.Dispose ();
+                       halffield.Dispose ();
+                       goal.Dispose ();
+                       LongoMatch.Core.Common.Serializer.Save (newproject, Path.Combine (outputDir, 
project.UUID.ToString ()));
                }
-               
-               public static void ConvertDB (string dbfile, string outputdir) {
+
+               public static void ConvertDB (string dbfile, string outputdir)
+               {
                        string dboutputdir;
                        string dbname;
                        DataBase db;
                        
-                       dbname = Path.GetFileName (dbfile).Split('.')[0] + ".ldb";
+                       dbname = Path.GetFileName (dbfile).Split ('.') [0] + ".ldb";
                        
                        dboutputdir = Path.Combine (outputdir, Path.Combine (outputdir, dbname));
                        if (!Directory.Exists (dboutputdir)) {
@@ -164,8 +362,8 @@ namespace LongoMatch.Migration
                        
                        db = new DataBase (dbfile);
                        foreach (ProjectDescription pd in db.GetAllProjects ()) {
-                                       Project p = db.GetProject (pd.UUID);
-                                       LongoMatch.Migration.Converter.ConvertProject (p, dboutputdir);
+                               Project p = db.GetProject (pd.UUID);
+                               ConvertProject (p, dboutputdir);
                        }
                }
        }
diff --git a/LongoMatch.Migration/LongoMatch.Migration.csproj 
b/LongoMatch.Migration/LongoMatch.Migration.csproj
index a65bb88..915bcfb 100644
--- a/LongoMatch.Migration/LongoMatch.Migration.csproj
+++ b/LongoMatch.Migration/LongoMatch.Migration.csproj
@@ -8,18 +8,25 @@
     <RootNamespace>LongoMatch.Migration</RootNamespace>
     <AssemblyName>LongoMatch</AssemblyName>
     <UseMSBuildEngine>False</UseMSBuildEngine>
+    <ProductVersion>12.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
     <Optimize>false</Optimize>
-    <OutputPath>bin\Debug</OutputPath>
-    <DefineConstants>DEBUG;HAVE_GTK</DefineConstants>
+    <OutputPath>..\bin\migration</OutputPath>
+    <DefineConstants>DEBUG HAVE_GTK</DefineConstants>
     <WarningLevel>4</WarningLevel>
     <ConsolePause>false</ConsolePause>
+    <EnvironmentVariables>
+      <EnvironmentVariables>
+        <Variable name="LGM_UNINSTALLED" value="" />
+      </EnvironmentVariables>
+    </EnvironmentVariables>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <Optimize>false</Optimize>
-    <OutputPath>bin\Release</OutputPath>
+    <OutputPath>..\bin\migration</OutputPath>
     <WarningLevel>4</WarningLevel>
     <ConsolePause>false</ConsolePause>
     <DebugSymbols>true</DebugSymbols>
@@ -29,18 +36,23 @@
     <Reference Include="System" />
     <Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
       <SpecificVersion>False</SpecificVersion>
+      <Package>gtk-sharp-2.0</Package>
     </Reference>
     <Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
       <SpecificVersion>False</SpecificVersion>
+      <Package>gtk-sharp-2.0</Package>
     </Reference>
     <Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
       <SpecificVersion>False</SpecificVersion>
+      <Package>glib-sharp-2.0</Package>
     </Reference>
     <Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
       <SpecificVersion>False</SpecificVersion>
+      <Package>gtk-sharp-2.0</Package>
     </Reference>
     <Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
       <SpecificVersion>False</SpecificVersion>
+      <Package>gtk-sharp-2.0</Package>
     </Reference>
     <Reference Include="Mono.Posix" />
     <Reference Include="System.Core" />
@@ -122,4 +134,10 @@
     <Folder Include="Common\" />
     <Folder Include="Tests\" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+  <ItemGroup>
+    <ProjectReference Include="..\LongoMatch.Core\LongoMatch.Core.csproj">
+      <Project>{B70912B2-7ED5-450E-97BD-45A3D45A0358}</Project>
+      <Name>LongoMatch.Core</Name>
+    </ProjectReference>
+  </ItemGroup>
+</Project>
diff --git a/LongoMatch.Migration/MainWindow.cs b/LongoMatch.Migration/MainWindow.cs
index b760de7..1a02f72 100644
--- a/LongoMatch.Migration/MainWindow.cs
+++ b/LongoMatch.Migration/MainWindow.cs
@@ -16,18 +16,18 @@
 //  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 //
 using System;
+using System.Linq;
 using System.IO;
 using Gtk;
 using System.Collections.Generic;
 using LongoMatch.DB;
 using LongoMatch.Store;
+using Mono.Unix;
+using LongoMatch.Common;
 
 public partial class MainWindow: Gtk.Window
 {      
 
-       string baseDirectory;
-       string homeDirectory;
-       string configDirectory;
        string buf;
        List<string> teams, categories, dbs;
        
@@ -35,36 +35,24 @@ public partial class MainWindow: Gtk.Window
        public MainWindow (): base (Gtk.WindowType.Toplevel)
        {
                Build ();
-               SetupBasedir ();
                FindFiles ();
                UpdateLabel ();
                buf = "";
+               convertbutton.Clicked += HandleConvertClicked;
+               closebutton.Clicked += HandleCloseClicked;
        }
+
        
-       void SetupBasedir () {
-               string home;
-                       
-               baseDirectory = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory,"../");
-               if (!System.IO.Directory.Exists(System.IO.Path.Combine(baseDirectory, "share", 
"longomatch"))) {
-                       baseDirectory = System.IO.Path.Combine(baseDirectory, "../");
-               }
-               
-               home = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal);
-               homeDirectory = System.IO.Path.Combine(home, "LongoMatch");
-               if (Environment.OSVersion.Platform == PlatformID.Win32NT)
-                       configDirectory = homeDirectory;
-               else
-                       configDirectory = System.IO.Path.Combine(home,"." + "longomatch");
-       }
        
-       void FindFiles () {
+       void FindFiles ()
+       {
                string dbdir, templatesdir;
                
-               dbs = new List<string>();
-               teams = new List<string>(); 
-               categories = new List<string>();
+               dbs = new List<string> ();
+               teams = new List<string> (); 
+               categories = new List<string> ();
                
-               dbdir = System.IO.Path.Combine (configDirectory, "db");
+               dbdir = System.IO.Path.Combine (LongoMatch.Config.ConfigDir, "db");
                if (Directory.Exists (dbdir)) {
                        foreach (string file in Directory.GetFiles (dbdir)) {
                                if (file.EndsWith ("1.db")) {
@@ -73,7 +61,7 @@ public partial class MainWindow: Gtk.Window
                        }
                }
                
-               templatesdir = System.IO.Path.Combine (homeDirectory, "templates");
+               templatesdir = System.IO.Path.Combine (LongoMatch.Config.HomeDir, "templates");
                if (Directory.Exists (templatesdir)) {
                        foreach (string file in Directory.GetFiles (templatesdir)) {
                                if (file.EndsWith (".lct")) {
@@ -84,6 +72,15 @@ public partial class MainWindow: Gtk.Window
                                }
                        }
                }
+               
+               if (dbs.Count == 0 && teams.Count == 0 && categories.Count == 0) {
+                       Gtk.MessageDialog dialog = new MessageDialog (this,
+                                                                     DialogFlags.Modal | 
DialogFlags.DestroyWithParent,
+                                                                     MessageType.Info, ButtonsType.Ok, 
+                                                                     Catalog.GetString ("Nothing to migrate 
from the old version"));
+                       dialog.Run();
+                       Application.Quit ();
+               }
        }
        
        void UpdateLabel () {
@@ -98,30 +95,27 @@ public partial class MainWindow: Gtk.Window
                a.RetVal = true;
        }
 
-       protected void OnButton2Clicked (object sender, EventArgs e)
+       protected void HandleCloseClicked (object sender, EventArgs e)
        {
                Application.Quit();
        }
        
        void UpdateText (string t) {
-               buf += t;
-               textview1.Buffer.Text = buf;
+               Application.Invoke (delegate {
+                       buf += t;
+                       textview1.Buffer.Text = buf;
+                       progressbar1.Pulse ();
+               });
        }
 
-       protected void OnButton1Clicked (object sender, EventArgs e)
+       void StartMigrationThread ()
        {
-               string dbdir =  System.IO.Path.Combine (homeDirectory, "db"); 
-               string teamdir =  System.IO.Path.Combine (homeDirectory, "db", "teams"); 
-               string analysisdir =  System.IO.Path.Combine (homeDirectory, "db", "analysis"); 
-               bool withError;
+               string dbdir = System.IO.Path.Combine (LongoMatch.Config.HomeDir, "db");
+               string teamdir = System.IO.Path.Combine (LongoMatch.Config.HomeDir, "db", "teams");
+               string analysisdir = System.IO.Path.Combine (LongoMatch.Config.HomeDir, "db", "analysis");
+               bool withError = false;
                MessageDialog d;
-               
-               scrolledwindow1.Visible = true ;
-               label2.Visible = false;
-               label3.Visible = false;
-               withError = false;
-               
-               textview1.Buffer.Text = buf;
+
                if (!Directory.Exists (teamdir)) {
                        UpdateText ("Creating directory " + teamdir + "\n");
                        Directory.CreateDirectory (teamdir);
@@ -130,11 +124,30 @@ public partial class MainWindow: Gtk.Window
                        UpdateText ("Creating directory " + analysisdir + "\n");
                        Directory.CreateDirectory (analysisdir);
                }
-               
-               foreach (string f in dbs) {
-                       UpdateText ("Converting dabase " + f + "...");
+               foreach (string dbfile in dbs) {
+                       UpdateText ("Converting dabase " + dbfile + "..." + "\n");
                        try {
-                               LongoMatch.Migration.Converter.ConvertDB (f, dbdir);
+                               string dboutputdir;
+                               string dbname;
+                               DataBase db;
+                               dbname = System.IO.Path.GetFileName (dbfile).Split ('.') [0] + ".ldb";
+                               dboutputdir = System.IO.Path.Combine (dbfile, System.IO.Path.Combine (dbdir, 
dbname));
+                               if (!Directory.Exists (dboutputdir)) {
+                                       Directory.CreateDirectory (dboutputdir);
+                               }
+                               db = new DataBase (dbfile);
+                               foreach (ProjectDescription pd in db.GetAllProjects ()) {
+                                       try {
+                                               Project p = db.GetProject (pd.UUID);
+                                               UpdateText ("Converting project " + p.Description.Title + 
"..." + "\n");
+                                               LongoMatch.Migration.Converter.ConvertProject (p, 
dboutputdir);
+                                       } catch (Exception ex) {
+                                               UpdateText ("ERROR\n");
+                                               UpdateText (ex.ToString ());
+                                               withError = true;
+                                       }
+                               }
+                               System.IO.File.Delete (System.IO.Path.Combine (dboutputdir, db.Name + 
".ldb"));
                                UpdateText ("OK\n");
                        } catch (Exception ex) {
                                UpdateText ("ERROR\n");
@@ -143,6 +156,9 @@ public partial class MainWindow: Gtk.Window
                        }
                }
                foreach (string f in teams) {
+                       if (System.IO.Path.GetFileNameWithoutExtension (f) == "default") {
+                               continue;
+                       }
                        UpdateText ("Converting team template " + f + "...");
                        try {
                                string p = System.IO.Path.Combine (teamdir, System.IO.Path.GetFileName (f));
@@ -155,28 +171,45 @@ public partial class MainWindow: Gtk.Window
                        }
                }
                foreach (string f in categories) {
+                       if (System.IO.Path.GetFileNameWithoutExtension (f) == "default") {
+                               continue;
+                       }
                        UpdateText ("Converting analysis template " + f + "...");
                        try {
                                string p = System.IO.Path.Combine (analysisdir, System.IO.Path.GetFileName 
(f));
                                LongoMatch.Migration.Converter.ConvertCategories (f, p);
                                UpdateText ("OK\n");
-                       } catch (Exception ex) {
+                       }
+                       catch (Exception ex) {
                                UpdateText ("ERROR\n");
                                UpdateText (ex.ToString ());
                                withError = true;
                        }
                }
-               
-               if (!withError) {
-                       d = new MessageDialog (this, DialogFlags.Modal, MessageType.Info,
-                                              ButtonsType.Ok, "Everything migrated correctly!");
-                       d.Run();
-                       Application.Quit();
-               } else {
-                       button1.Visible = false;
-                       d = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Error,
-                                              ButtonsType.Ok, "Some errors where found migrating the old 
content.");
-                       d.Run();
-               }
+               Application.Invoke (delegate {
+                       if (!withError) {
+                               d = new MessageDialog (this, DialogFlags.Modal, MessageType.Info, 
ButtonsType.Ok, "Everything migrated correctly!");
+                               d.Run ();
+                               Application.Quit ();
+                       }
+                       else {
+                               convertbutton.Visible = false;
+                               progressbar1.Visible = false;
+                               d = new MessageDialog (this, DialogFlags.DestroyWithParent, 
MessageType.Error, ButtonsType.Ok, "Some errors where found migrating the old content.");
+                               d.Run ();
+                               d.Destroy ();
+                       }
+               });
+       }
+
+       protected void HandleConvertClicked (object sender, EventArgs e)
+       {
+               scrolledwindow1.Visible = true;
+               label2.Visible = false;
+               label3.Visible = false;
+               textview1.Buffer.Text = buf;
+               progressbar1.Visible = true;
+               System.Threading.Thread t = new System.Threading.Thread (StartMigrationThread);
+               t.Start ();
        }
 }
diff --git a/LongoMatch.Migration/Makefile.am b/LongoMatch.Migration/Makefile.am
index 7712688..ec37059 100644
--- a/LongoMatch.Migration/Makefile.am
+++ b/LongoMatch.Migration/Makefile.am
@@ -1,5 +1,6 @@
 ASSEMBLY = LongoMatch
-TARGET = winexe
+TARGET = exe
+INSTALL_DIR = $(pkglibdir)/migration
 
 LINK = $(REF_DEP_LONGOMATCH_MIGRATION)
 
@@ -54,3 +55,4 @@ RESOURCES = gtk-gui/gui.stetic \
        Data/project.lgm
 
 include $(top_srcdir)/build/build.mk
+ASSEMBLY_FILE = $(top_builddir)/bin/migration/$(ASSEMBLY).$(ASSEMBLY_EXTENSION)
diff --git a/LongoMatch.Migration/Program.cs b/LongoMatch.Migration/Program.cs
index 8b3a1bd..7019880 100644
--- a/LongoMatch.Migration/Program.cs
+++ b/LongoMatch.Migration/Program.cs
@@ -17,6 +17,7 @@
 //
 using System;
 using Gtk;
+using System.IO;
 
 namespace LongoMatch.Migration
 {
@@ -24,10 +25,52 @@ namespace LongoMatch.Migration
        {
                public static void Main (string[] args)
                {
-                       Application.Init ();
+                       SetupBasedir ();
+                       InitGtk ();
                        MainWindow win = new MainWindow ();
                        win.Show ();
                        Application.Run ();
                }
+               
+               static void SetupBasedir ()
+               {
+                       string home, homeDirectory, baseDirectory, configDirectory;
+                       
+                       baseDirectory = System.IO.Path.Combine (System.AppDomain.CurrentDomain.BaseDirectory, 
"..", "..", "..");
+                       home = System.Environment.GetFolderPath (Environment.SpecialFolder.Personal);
+                       homeDirectory = System.IO.Path.Combine (home, "LongoMatch");
+                       if (Environment.OSVersion.Platform == PlatformID.Win32NT)
+                               configDirectory = homeDirectory;
+                       else {
+                               configDirectory = System.IO.Path.Combine (home, "." + "longomatch");
+                       }
+                       LongoMatch.Config.ConfigDir = configDirectory;
+                       LongoMatch.Config.homeDirectory = homeDirectory;
+                       
+                       if (Environment.GetEnvironmentVariable ("LGM_UNINSTALLED") != null) {
+                               LongoMatch.Config.baseDirectory = ".";
+                               LongoMatch.Config.dataDir = "../data";
+                       } else {
+                               LongoMatch.Config.baseDirectory = baseDirectory;
+                               LongoMatch.Config.dataDir = System.IO.Path.Combine 
(LongoMatch.Config.baseDirectory, "share", "longomatch");
+                       }
+               }
+       
+               static  void InitGtk ()
+               {
+                       string gtkRC, iconsDir;
+                       
+                       gtkRC = Path.Combine (Config.dataDir, "theme", "gtk-2.0", "gtkrc");
+                       if (File.Exists (gtkRC)) {
+                               Rc.AddDefaultFile (gtkRC);
+                       }
+                       
+                       Application.Init ();
+                       
+                       iconsDir = Path.Combine (Config.dataDir, "icons");
+                       if (Directory.Exists (iconsDir)) {
+                               IconTheme.Default.PrependSearchPath (iconsDir);
+                       }
+               }
        }
 }
diff --git a/LongoMatch.Migration/gtk-gui/MainWindow.cs b/LongoMatch.Migration/gtk-gui/MainWindow.cs
index 471392c..eec8319 100644
--- a/LongoMatch.Migration/gtk-gui/MainWindow.cs
+++ b/LongoMatch.Migration/gtk-gui/MainWindow.cs
@@ -8,9 +8,10 @@ public partial class MainWindow
        private global::Gtk.Label label3;
        private global::Gtk.ScrolledWindow scrolledwindow1;
        private global::Gtk.TextView textview1;
+       private global::Gtk.ProgressBar progressbar1;
        private global::Gtk.HBox hbox1;
-       private global::Gtk.Button button2;
-       private global::Gtk.Button button1;
+       private global::Gtk.Button closebutton;
+       private global::Gtk.Button convertbutton;
 
        protected virtual void Build ()
        {
@@ -61,50 +62,58 @@ public partial class MainWindow
                global::Gtk.Box.BoxChild w5 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.vbox2]));
                w5.Position = 0;
                // Container child vbox1.Gtk.Box+BoxChild
+               this.progressbar1 = new global::Gtk.ProgressBar ();
+               this.progressbar1.Name = "progressbar1";
+               this.vbox1.Add (this.progressbar1);
+               global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.progressbar1]));
+               w6.Position = 1;
+               w6.Expand = false;
+               w6.Fill = false;
+               // Container child vbox1.Gtk.Box+BoxChild
                this.hbox1 = new global::Gtk.HBox ();
                this.hbox1.Name = "hbox1";
                this.hbox1.Spacing = 6;
                // Container child hbox1.Gtk.Box+BoxChild
-               this.button2 = new global::Gtk.Button ();
-               this.button2.CanFocus = true;
-               this.button2.Name = "button2";
-               this.button2.UseStock = true;
-               this.button2.UseUnderline = true;
-               this.button2.Label = "gtk-close";
-               this.hbox1.Add (this.button2);
-               global::Gtk.Box.BoxChild w6 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.button2]));
-               w6.Position = 0;
-               w6.Fill = false;
+               this.closebutton = new global::Gtk.Button ();
+               this.closebutton.CanFocus = true;
+               this.closebutton.Name = "closebutton";
+               this.closebutton.UseStock = true;
+               this.closebutton.UseUnderline = true;
+               this.closebutton.Label = "gtk-close";
+               this.hbox1.Add (this.closebutton);
+               global::Gtk.Box.BoxChild w7 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.closebutton]));
+               w7.Position = 0;
+               w7.Fill = false;
                // Container child hbox1.Gtk.Box+BoxChild
-               this.button1 = new global::Gtk.Button ();
-               this.button1.CanFocus = true;
-               this.button1.Name = "button1";
-               this.button1.UseUnderline = true;
-               // Container child button1.Gtk.Container+ContainerChild
-               global::Gtk.Alignment w7 = new global::Gtk.Alignment (0.5F, 0.5F, 0F, 0F);
+               this.convertbutton = new global::Gtk.Button ();
+               this.convertbutton.CanFocus = true;
+               this.convertbutton.Name = "convertbutton";
+               this.convertbutton.UseUnderline = true;
+               // Container child convertbutton.Gtk.Container+ContainerChild
+               global::Gtk.Alignment w8 = new global::Gtk.Alignment (0.5F, 0.5F, 0F, 0F);
                // Container child GtkAlignment.Gtk.Container+ContainerChild
-               global::Gtk.HBox w8 = new global::Gtk.HBox ();
-               w8.Spacing = 2;
+               global::Gtk.HBox w9 = new global::Gtk.HBox ();
+               w9.Spacing = 2;
                // Container child GtkHBox.Gtk.Container+ContainerChild
-               global::Gtk.Image w9 = new global::Gtk.Image ();
-               w9.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-refresh", 
global::Gtk.IconSize.Menu);
-               w8.Add (w9);
+               global::Gtk.Image w10 = new global::Gtk.Image ();
+               w10.Pixbuf = global::Stetic.IconLoader.LoadIcon (this, "gtk-refresh", 
global::Gtk.IconSize.Menu);
+               w9.Add (w10);
                // Container child GtkHBox.Gtk.Container+ContainerChild
-               global::Gtk.Label w11 = new global::Gtk.Label ();
-               w11.LabelProp = global::Mono.Unix.Catalog.GetString ("Convert");
-               w11.UseUnderline = true;
-               w8.Add (w11);
-               w7.Add (w8);
-               this.button1.Add (w7);
-               this.hbox1.Add (this.button1);
-               global::Gtk.Box.BoxChild w15 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.button1]));
-               w15.Position = 1;
-               w15.Fill = false;
-               this.vbox1.Add (this.hbox1);
-               global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.hbox1]));
+               global::Gtk.Label w12 = new global::Gtk.Label ();
+               w12.LabelProp = global::Mono.Unix.Catalog.GetString ("Convert");
+               w12.UseUnderline = true;
+               w9.Add (w12);
+               w8.Add (w9);
+               this.convertbutton.Add (w8);
+               this.hbox1.Add (this.convertbutton);
+               global::Gtk.Box.BoxChild w16 = ((global::Gtk.Box.BoxChild)(this.hbox1 [this.convertbutton]));
                w16.Position = 1;
-               w16.Expand = false;
                w16.Fill = false;
+               this.vbox1.Add (this.hbox1);
+               global::Gtk.Box.BoxChild w17 = ((global::Gtk.Box.BoxChild)(this.vbox1 [this.hbox1]));
+               w17.Position = 2;
+               w17.Expand = false;
+               w17.Fill = false;
                this.Add (this.vbox1);
                if ((this.Child != null)) {
                        this.Child.ShowAll ();
@@ -112,9 +121,8 @@ public partial class MainWindow
                this.DefaultWidth = 664;
                this.DefaultHeight = 285;
                this.scrolledwindow1.Hide ();
+               this.progressbar1.Hide ();
                this.Show ();
                this.DeleteEvent += new global::Gtk.DeleteEventHandler (this.OnDeleteEvent);
-               this.button2.Clicked += new global::System.EventHandler (this.OnButton2Clicked);
-               this.button1.Clicked += new global::System.EventHandler (this.OnButton1Clicked);
        }
 }
diff --git a/LongoMatch.Migration/gtk-gui/gui.stetic b/LongoMatch.Migration/gtk-gui/gui.stetic
index 94900c8..1bf80bd 100644
--- a/LongoMatch.Migration/gtk-gui/gui.stetic
+++ b/LongoMatch.Migration/gtk-gui/gui.stetic
@@ -5,7 +5,7 @@
     <target-gtk-version>2.12</target-gtk-version>
   </configuration>
   <import>
-    <widget-library name="../bin/Debug/LongoMatch.exe" internal="true" />
+    <widget-library name="../../bin/migration/LongoMatch.exe" internal="true" />
   </import>
   <widget class="Gtk.Window" id="MainWindow" design-size="664 285">
     <property name="MemberName" />
@@ -69,17 +69,28 @@
           </packing>
         </child>
         <child>
+          <widget class="Gtk.ProgressBar" id="progressbar1">
+            <property name="MemberName" />
+            <property name="Visible">False</property>
+          </widget>
+          <packing>
+            <property name="Position">1</property>
+            <property name="AutoSize">True</property>
+            <property name="Expand">False</property>
+            <property name="Fill">False</property>
+          </packing>
+        </child>
+        <child>
           <widget class="Gtk.HBox" id="hbox1">
             <property name="MemberName" />
             <property name="Spacing">6</property>
             <child>
-              <widget class="Gtk.Button" id="button2">
+              <widget class="Gtk.Button" id="closebutton">
                 <property name="MemberName" />
                 <property name="CanFocus">True</property>
                 <property name="UseStock">True</property>
                 <property name="Type">StockItem</property>
                 <property name="StockId">gtk-close</property>
-                <signal name="Clicked" handler="OnButton2Clicked" />
                 <property name="label">gtk-close</property>
               </widget>
               <packing>
@@ -89,14 +100,13 @@
               </packing>
             </child>
             <child>
-              <widget class="Gtk.Button" id="button1">
+              <widget class="Gtk.Button" id="convertbutton">
                 <property name="MemberName" />
                 <property name="CanFocus">True</property>
                 <property name="Type">TextAndIcon</property>
                 <property name="Icon">stock:gtk-refresh Menu</property>
                 <property name="Label" translatable="yes">Convert</property>
                 <property name="UseUnderline">True</property>
-                <signal name="Clicked" handler="OnButton1Clicked" />
               </widget>
               <packing>
                 <property name="Position">1</property>
@@ -106,7 +116,7 @@
             </child>
           </widget>
           <packing>
-            <property name="Position">1</property>
+            <property name="Position">2</property>
             <property name="AutoSize">True</property>
             <property name="Expand">False</property>
             <property name="Fill">False</property>
diff --git a/LongoMatch.Services/Services/ToolsManager.cs b/LongoMatch.Services/Services/ToolsManager.cs
index a214dc6..9286d04 100644
--- a/LongoMatch.Services/Services/ToolsManager.cs
+++ b/LongoMatch.Services/Services/ToolsManager.cs
@@ -26,6 +26,8 @@ using LongoMatch.Core.Interfaces.GUI;
 using LongoMatch.Core.Interfaces.Multimedia;
 using LongoMatch.Core.Store;
 using Mono.Unix;
+using System.Reflection;
+using System.Diagnostics;
 
 namespace LongoMatch.Services
 {
@@ -69,6 +71,8 @@ namespace LongoMatch.Services
                                }
                        };
                        
+                       Config.EventsBroker.MigrateDB += HandleMigrateDB;
+                       
                        Config.EventsBroker.ExportProjectEvent += ExportProject;
                        Config.EventsBroker.ImportProjectEvent += ImportProject;
                }
@@ -171,6 +175,25 @@ namespace LongoMatch.Services
                                return;
                        }
                }
+               
+               void HandleMigrateDB ()
+               {
+                       string codeBase = Assembly.GetExecutingAssembly().CodeBase;
+                       UriBuilder uri = new UriBuilder(codeBase);
+                       string assemblyDir = Path.GetDirectoryName (Uri.UnescapeDataString(uri.Path));
+                       string migrationExe = Path.Combine (assemblyDir, "migration", "LongoMatch.exe");
+                       ProcessStartInfo startInfo = new ProcessStartInfo ();
+                       startInfo.CreateNoWindow = true;
+                       if (System.Environment.OSVersion.Platform != PlatformID.Win32NT) {
+                               startInfo.UseShellExecute = false;
+                       }
+                       startInfo.FileName = "mono";
+                       startInfo.Arguments = migrationExe;
+                       startInfo.EnvironmentVariables.Add ("MONO_PATH", assemblyDir);
+                       using (System.Diagnostics.Process exeProcess = 
System.Diagnostics.Process.Start(startInfo)) {
+                               exeProcess.WaitForExit ();
+                       }
+               }
        }
 
        public class ProjectImporter
diff --git a/build/build.environment.mk b/build/build.environment.mk
index f054fcf..1709cec 100644
--- a/build/build.environment.mk
+++ b/build/build.environment.mk
@@ -126,6 +126,7 @@ REF_DEP_LONGOMATCH = \
                      $(LINK_LONGOMATCH_SERVICES)
 
 REF_DEP_LONGOMATCH_MIGRATION = \
+                     $(LINK_LONGOMATCH_CORE) \
                      $(LINK_SYSTEM) \
                      $(LINK_SYSTEM_CORE) \
                      $(LINK_SYSTEM_DRAWING) \
diff --git a/build/build.rules.mk b/build/build.rules.mk
index fbceef1..eed2a74 100644
--- a/build/build.rules.mk
+++ b/build/build.rules.mk
@@ -64,7 +64,7 @@ build-debug:
 $(ASSEMBLY_FILE).mdb: $(ASSEMBLY_FILE)
 
 $(ASSEMBLY_FILE): $(SOURCES_BUILD) $(RESOURCES_EXPANDED) $(DEP_LINK)
-       @mkdir -p $(top_builddir)/bin
+       @mkdir -p $(top_builddir)/bin/migration
        $(AM_V_GEN) $(MCS) \
                $(GMCS_FLAGS) \
                $(ASSEMBLY_BUILD_FLAGS) \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]