Remove OS detection code, rely on an abstract base controller with similarly named custom controller subclasses for each OS instead.

This commit is contained in:
Hylke Bons 2011-09-25 19:22:35 +02:00
parent f276f842b8
commit d661c184e2
11 changed files with 1353 additions and 1343 deletions

View file

@ -50,7 +50,7 @@ namespace SparkleLib {
// don't have your own. All data needed to connect is hashed and
// we don't store any personal information ever
uri = "irc://204.62.14.135/";
uri = "tcp://204.62.14.135:1986";
}
Uri announce_uri = new Uri (uri);
@ -77,7 +77,7 @@ namespace SparkleLib {
listeners.Add (new SparkleListenerIrc (announce_uri, folder_identifier));
break;
default:
listeners.Add (new SparkleListenerIrc (announce_uri, folder_identifier));
listeners.Add (new SparkleListenerTcp (announce_uri, folder_identifier));
break;
}

View file

@ -256,6 +256,8 @@ namespace SparkleLib {
this.listener.Announcement += delegate (SparkleAnnouncement announcement) {
string identifier = Identifier;
Console.WriteLine (announcement.Message + " ! " + CurrentRevision);
if (announcement.FolderIdentifier == identifier &&
!announcement.Message.Equals (CurrentRevision)) {
if ((Status != SyncStatus.SyncUp) &&

View file

@ -26,13 +26,17 @@ using SparkleLib;
namespace SparkleShare {
public class SparkleMacController : SparkleController {
public class SparkleController : SparkleControllerBase {
// We have to use our own custom made folder watcher, as
// System.IO.FileSystemWatcher fails watching subfolders on Mac
private SparkleMacWatcher watcher;
public SparkleMacController () : base () { }
public SparkleController () : base ()
{
}
public override void Initialize ()
{

View file

@ -74,10 +74,9 @@
<Compile Include="MainMenu.xib.designer.cs">
<DependentUpon>MainMenu.xib</DependentUpon>
</Compile>
<Compile Include="..\SparkleController.cs">
<Link>SparkleController.cs</Link>
<Compile Include="..\SparkleControllerBase.cs">
<Link>SparkleControllerBase.cs</Link>
</Compile>
<Compile Include="SparkleMacController.cs" />
<Compile Include="SparkleStatusIcon.cs" />
<Compile Include="SparkleUI.cs" />
<Compile Include="..\Program.cs">
@ -109,6 +108,7 @@
<Compile Include="..\SparkleExtensions.cs">
<Link>SparkleExtensions.cs</Link>
</Compile>
<Compile Include="SparkleController.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="MainMenu.xib" />

View file

@ -18,11 +18,11 @@ SOURCES = \
SparkleBubbles.cs \
SparkleBubblesController.cs \
SparkleController.cs \
SparkleControllerBase.cs \
SparkleEntry.cs \
SparkleEventLog.cs \
SparkleEventLogController.cs \
SparkleExtensions.cs \
SparkleLinController.cs \
SparkleSetup.cs \
SparkleSetupController.cs \
SparkleSetupWindow.cs \

View file

@ -64,23 +64,10 @@ namespace SparkleShare {
if (show_help)
ShowHelp (option_set);
// Load the right controller for the OS
string controller_name = "Lin";
switch (SparkleBackend.Platform) {
case PlatformID.Unix:
SetProcessName ("sparkleshare");
break;
case PlatformID.MacOSX:
controller_name = "Mac";
break;
case PlatformID.Win32NT:
controller_name = "Win";
break;
}
// Initialize the controller this way so that
// there aren't any exceptions in the OS specific UI's
Controller = new SparkleMacController ();
Controller = new SparkleController ();
Controller.Initialize ();
if (Controller != null) {

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,214 +0,0 @@
// SparkleShare, a collaboration and sharing tool.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using Mono.Unix;
using SparkleLib;
namespace SparkleShare {
public class SparkleLinController : SparkleController {
public SparkleLinController () : base ()
{
}
// Creates a .desktop entry in autostart folder to
// start SparkleShare automatically at login
public override void EnableSystemAutostart ()
{
string autostart_path = Path.Combine (Environment.GetFolderPath (
Environment.SpecialFolder.ApplicationData), "autostart");
string desktopfile_path = Path.Combine (autostart_path, "sparkleshare.desktop");
if (!Directory.Exists (autostart_path))
Directory.CreateDirectory (autostart_path);
if (!File.Exists (desktopfile_path)) {
TextWriter writer = new StreamWriter (desktopfile_path);
writer.WriteLine ("[Desktop Entry]\n" +
"Type=Application\n" +
"Name=SparkleShare\n" +
"Exec=sparkleshare start\n" +
"Icon=folder-sparkleshare\n" +
"Terminal=false\n" +
"X-GNOME-Autostart-enabled=true\n" +
"Categories=Network");
writer.Close ();
// Give the launcher the right permissions so it can be launched by the user
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
file_info.Create (FileAccessPermissions.UserReadWriteExecute);
SparkleHelpers.DebugInfo ("Controller", "Enabled autostart on login");
}
}
// Installs a launcher so the user can launch SparkleShare
// from the Internet category if needed
public override void InstallLauncher ()
{
string apps_path =
new string [] {SparkleConfig.DefaultConfig.HomePath,
".local", "share", "applications"}.Combine ();
string desktopfile_path = Path.Combine (apps_path, "sparkleshare.desktop");
if (!File.Exists (desktopfile_path)) {
if (!Directory.Exists (apps_path))
Directory.CreateDirectory (apps_path);
TextWriter writer = new StreamWriter (desktopfile_path);
writer.WriteLine ("[Desktop Entry]\n" +
"Type=Application\n" +
"Name=SparkleShare\n" +
"Comment=Share documents\n" +
"Exec=sparkleshare start\n" +
"Icon=folder-sparkleshare\n" +
"Terminal=false\n" +
"Categories=Network;");
writer.Close ();
// Give the launcher the right permissions so it can be launched by the user
UnixFileInfo file_info = new UnixFileInfo (desktopfile_path);
file_info.FileAccessPermissions = FileAccessPermissions.UserReadWriteExecute;
SparkleHelpers.DebugInfo ("Controller", "Created '" + desktopfile_path + "'");
}
}
// Adds the SparkleShare folder to the user's
// list of bookmarked places
public override void AddToBookmarks ()
{
string bookmarks_file_path = Path.Combine (SparkleConfig.DefaultConfig.HomePath, ".gtk-bookmarks");
string sparkleshare_bookmark = "file://" + SparkleConfig.DefaultConfig.FoldersPath + " SparkleShare";
if (File.Exists (bookmarks_file_path)) {
StreamReader reader = new StreamReader (bookmarks_file_path);
string bookmarks = reader.ReadToEnd ();
reader.Close ();
if (!bookmarks.Contains (sparkleshare_bookmark)) {
TextWriter writer = File.AppendText (bookmarks_file_path);
writer.WriteLine ("file://" + SparkleConfig.DefaultConfig.FoldersPath + " SparkleShare");
writer.Close ();
}
} else {
StreamWriter writer = new StreamWriter (bookmarks_file_path);
writer.WriteLine ("file://" + SparkleConfig.DefaultConfig.FoldersPath + " SparkleShare");
writer.Close ();
}
}
// Creates the SparkleShare folder in the user's home folder
public override bool CreateSparkleShareFolder ()
{
if (!Directory.Exists (SparkleConfig.DefaultConfig.FoldersPath)) {
Directory.CreateDirectory (SparkleConfig.DefaultConfig.FoldersPath);
SparkleHelpers.DebugInfo ("Controller", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'");
string gvfs_command_path =
new string [] {Path.VolumeSeparatorChar.ToString (),
"usr", "bin", "gvfs-set-attribute"}.Combine ();
// Add a special icon to the SparkleShare folder
if (File.Exists (gvfs_command_path)) {
Process process = new Process ();
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "gvfs-set-attribute";
// Clear the custom (legacy) icon path
process.StartInfo.Arguments = "-t unset " + SparkleConfig.DefaultConfig.FoldersPath + " metadata::custom-icon";
process.Start ();
process.WaitForExit ();
// Give the SparkleShare folder an icon name, so that it scales
process.StartInfo.Arguments = SparkleConfig.DefaultConfig.FoldersPath + " metadata::custom-icon-name 'folder-sparkleshare'";
process.Start ();
process.WaitForExit ();
}
return true;
}
return false;
}
public override string EventLogHTML {
get {
string path = new string [] {Defines.PREFIX,
"share", "sparkleshare", "html", "event-log.html"}.Combine ();
string html = String.Join (Environment.NewLine, File.ReadAllLines (path));
html = html.Replace ("<!-- $jquery-url -->", "file://" +
new string [] {Defines.PREFIX, "share", "sparkleshare", "html", "jquery.js"}.Combine ());
return html;
}
}
public override string DayEntryHTML {
get {
string path = new string [] {Defines.PREFIX,
"share", "sparkleshare", "html", "day-entry.html"}.Combine ();
return String.Join (Environment.NewLine, File.ReadAllLines (path));
}
}
public override string EventEntryHTML {
get {
string path = new string [] {Defines.PREFIX,
"share", "sparkleshare", "html", "event-entry.html"}.Combine ();
return String.Join (Environment.NewLine, File.ReadAllLines (path));
}
}
public override void OpenSparkleShareFolder (string subfolder)
{
string folder = Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, subfolder);
Process process = new Process ();
process.StartInfo.FileName = "xdg-open";
process.StartInfo.Arguments = "\"" + folder + "\"";
process.Start ();
}
}
}

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@ -9,6 +9,7 @@
<AssemblyName>SparkleShare</AssemblyName>
<SchemaVersion>2.0</SchemaVersion>
<RootNamespace>SparkleShare</RootNamespace>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -37,15 +38,9 @@
<Reference Include="System" />
<Reference Include="Mono.Posix" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SparkleLib\SparkleLib.csproj">
<Project>{2C914413-B31C-4362-93C7-1AE34F09112A}</Project>
<Name>SparkleLib</Name>
</ProjectReference>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
<Properties InternalTargetFrameworkVersion="3.5">
<Properties>
<MonoDevelop.Autotools.MakefileInfo IntegrationEnabled="true" RelativeMakefileName="Makefile.am">
<BuildFilesVar Sync="true" Name="SOURCES" />
<DeployFilesVar />
@ -63,7 +58,6 @@
<Compile Include="SparkleBubblesController.cs" />
<Compile Include="SparkleController.cs" />
<Compile Include="SparkleEntry.cs" />
<Compile Include="SparkleLinController.cs" />
<Compile Include="SparkleSetup.cs" />
<Compile Include="SparkleSetupController.cs" />
<Compile Include="SparkleSetupWindow.cs" />
@ -78,5 +72,6 @@
<Compile Include="SparkleAboutController.cs" />
<Compile Include="SparkleAbout.cs" />
<Compile Include="SparkleExtensions.cs" />
<Compile Include="SparkleControllerBase.cs" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SparkleShare", "SparkleShare.csproj", "{728483AA-E34B-4441-BF2C-C8BC2901E4E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{728483AA-E34B-4441-BF2C-C8BC2901E4E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{728483AA-E34B-4441-BF2C-C8BC2901E4E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{728483AA-E34B-4441-BF2C-C8BC2901E4E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{728483AA-E34B-4441-BF2C-C8BC2901E4E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = SparkleShare.csproj
EndGlobalSection
EndGlobal