Skip to content

Commit

Permalink
Long paths, refactoring, local WorthSyncing, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-raoul committed Oct 16, 2017
1 parent b3ab5cd commit db37962
Show file tree
Hide file tree
Showing 24 changed files with 258 additions and 53 deletions.
4 changes: 2 additions & 2 deletions CmisSync.Auth/Auth.cs → CmisSync.Auth/Authentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace CmisSync.Auth
/// This class allows one to connect to a CMIS repository.
/// It can return a list of repositories, or directly a CMIS session if the repository is known.
/// </summary>
public class Auth
public class Authentication
{
// Log.
private static readonly ILog Logger = LogManager.GetLogger(typeof(Auth));
private static readonly ILog Logger = LogManager.GetLogger(typeof(Authentication));

/// <summary>
/// Connect to a CMIS server and get the list of repositories.
Expand Down
17 changes: 10 additions & 7 deletions CmisSync.Auth/CmisSync.Auth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -54,19 +57,19 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Auth.cs" />
<Compile Include="Authentication.cs" />
<Compile Include="Credentials.cs" />
<Compile Include="Crypto.cs" />
<Compile Include="Password.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<ProjectReference Include="..\Extras\log4net-1.2.11\src\log4net.vs2010.csproj">
Expand Down
2 changes: 1 addition & 1 deletion CmisSync.Auth/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace CmisSync.Auth
public static class Crypto
{
// Log.
private static readonly ILog Logger = LogManager.GetLogger(typeof(Auth));
private static readonly ILog Logger = LogManager.GetLogger(typeof(Authentication));

/// <summary>
/// Obfuscate a string.
Expand Down
2 changes: 1 addition & 1 deletion CmisSync.Auth/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ASSEMBLY_INFO_SOURCE = Properties/AssemblyInfo.cs
LIBS = $(LOG4NET_LIBS) $(DATALIBS) $(JSON_LIBS) $(DOTCMISLIBS) $(WEBLIBS) $(MONOPOSIX)

SOURCES = \
Auth.cs \
Authentication.cs \
Credentials.cs \
Crypto.cs \
Password.cs
Expand Down
8 changes: 8 additions & 0 deletions CmisSync.Auth/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<longPathAware>true</longPathAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
10 changes: 8 additions & 2 deletions CmisSync.Console/CmisSync.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="CmisSyncOnce.cs" />
<Compile Include="ConsoleController.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="YesCertPolicyHandler.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down Expand Up @@ -131,7 +135,9 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="app.manifest" />
</ItemGroup>
<PropertyGroup>
<PostBuildEvent Condition="'$(Configuration)|$(Platform)' == 'Mac Debug|AnyCPU'">$(SolutionDir)installer/createMacInstaller.sh 0.1</PostBuildEvent>
</PropertyGroup>
Expand All @@ -141,4 +147,4 @@ Mkdir "$(ProjectDir)$(OutDir)x64"
Copy "$(SolutionDir)..\..\extras\sqlite-netFx40-static-binary-Win32-2010-1.0.86.0\SQLite.Interop.dll" "$(ProjectDir)$(OutDir)x86\SQLite.Interop.dll"
Copy "$(SolutionDir)..\..\extras\sqlite-netFx40-static-binary-x64-2010-1.0.86.0\SQLite.Interop.dll" "$(ProjectDir)$(OutDir)x64\SQLite.Interop.dll"</PreBuildEvent>
</PropertyGroup>
</Project>
</Project>
12 changes: 11 additions & 1 deletion CmisSync.Console/CmisSyncOnce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace CmisSync.Console
/// </summary>
class CmisSyncOnce
{
/// <summary>
/// Logging.
/// </summary>
private static readonly ILog Logger = LogManager.GetLogger(typeof(CmisSyncOnce));

/// <summary>
/// Configured synchronized folder on which the synchronization must be performed.
/// </summary>
Expand All @@ -32,6 +37,11 @@ class CmisSyncOnce
public static int Main (string[] args)
{
Utils.ConfigureLogging();
Logger.Info("Starting. Version: " + CmisSync.Lib.Backend.Version);

// Uncomment this line to disable SSL checking (for self-signed certificates)
// ServicePointManager.CertificatePolicy = new YesCertPolicyHandler();

PathRepresentationConverter.SetConverter(new WindowsPathRepresentationConverter());

CmisSyncOnce once = new CmisSyncOnce();
Expand Down Expand Up @@ -89,7 +99,7 @@ private bool Sync ()
foreach (RepoInfo repoInfo in repos)
{
CmisRepo cmisRepo = new CmisRepo (repoInfo, controller, false);
success &= cmisRepo.SyncNotInBackground();
success &= cmisRepo.SyncInForeground();
}

return success;
Expand Down
46 changes: 46 additions & 0 deletions CmisSync.Console/YesCertPolicyHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// CmisSync, 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.Net;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;

namespace CmisSync
{
/**
* Certificate policy handler.
* This handler gets invoked when an untrusted certificate is encountered
* while connecting via https.
* It Presents the user with a dialog, asking if the cert should be trusted.
*/

class YesCertPolicyHandler : ICertificatePolicy
{
/**
* Verification callback.
* Return true to accept a certificate.
*/
public bool CheckValidationResult(ServicePoint sp, X509Certificate certificate,
WebRequest request, int error)
{
// Always accept.
// Note: Command-line users often have self-made certificates, and know what they are doing.
return true;
}
}
}
8 changes: 8 additions & 0 deletions CmisSync.Console/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
<longPathAware>true</longPathAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
12 changes: 11 additions & 1 deletion CmisSync.Lib/Cmis/CmisProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CmisProfile()
/// </summary>
public string localFilename(IDocument document)
{
// Can be useful for tests, making local filenames radically different, thus making bugs easier to catch.
// Can be useful for tests, making local filenames radically different, thus making bugs easier to catch:
// return document.Id;

if (UseCmisStreamName)
Expand All @@ -72,6 +72,16 @@ public string localFilename(IDocument document)
}


/// <summary>
/// Name used as part of the remote path in the local CmisSync database.
/// This must be unique on the remote folder.
/// </summary>
public string remoteFilename(IDocument document)
{
return (string)document.GetPropertyValue("cmis:name");
}


/// <summary>
/// Prepare the given OperationContext for use with this CMIS profile.
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions CmisSync.Lib/Cmis/CmisUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static public Dictionary<string,string> GetRepositories(ServerCredentials creden
IList<IRepository> repositories;
try
{
repositories = Auth.Auth.GetCmisRepositories(credentials.Address, credentials.UserName, credentials.Password.ToString());
repositories = Auth.Authentication.GetCmisRepositories(credentials.Address, credentials.UserName, credentials.Password.ToString());
}
catch (CmisPermissionDeniedException e)
{
Expand Down Expand Up @@ -216,7 +216,7 @@ static public string[] GetSubfolders(string repositoryId, string path,
List<string> result = new List<string>();

// Connect to the CMIS repository.
ISession session = Auth.Auth.GetCmisSession(url, user, password, repositoryId);
ISession session = Auth.Authentication.GetCmisSession(url, user, password, repositoryId);

// Get the folder.
IFolder folder;
Expand Down Expand Up @@ -306,7 +306,7 @@ public FolderTree(IList<ITree<IFileableCmisObject>> trees, IFolder folder, int d
static public FolderTree GetSubfolderTree(CmisRepoCredentials credentials, string path, int depth)
{
// Connect to the CMIS repository.
ISession session = Auth.Auth.GetCmisSession(credentials.Address.ToString(), credentials.UserName, credentials.Password.ToString(), credentials.RepoId);
ISession session = Auth.Authentication.GetCmisSession(credentials.Address.ToString(), credentials.UserName, credentials.Password.ToString(), credentials.RepoId);

// Get the folder.
IFolder folder;
Expand Down Expand Up @@ -404,7 +404,7 @@ static public string GetBrowsableURL(RepoInfo repo)
try
{
// Connect to the CMIS repository.
ISession session = Auth.Auth.GetCmisSession(repo.Address.ToString(), repo.User, repo.Password.ToString(), repo.RepoID);
ISession session = Auth.Authentication.GetCmisSession(repo.Address.ToString(), repo.User, repo.Password.ToString(), repo.RepoID);

if (session.RepositoryInfo.ThinClientUri == null
|| String.IsNullOrEmpty(session.RepositoryInfo.ThinClientUri.ToString()))
Expand Down
62 changes: 54 additions & 8 deletions CmisSync.Lib/Cmis/MimeType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.IO;
using log4net;

namespace CmisSync.Lib.Cmis
{
Expand All @@ -12,24 +13,56 @@ namespace CmisSync.Lib.Cmis
/// </summary>
public static class MimeType
{
/// <summary>
/// Log.
/// </summary>
private static readonly ILog Logger = LogManager.GetLogger(typeof(MimeType));


/// <summary>
/// Guess the MIME type of a file.
/// </summary>
/// <param name="fileName">Relative filename, for instance mydoc.odt</param>
/// <returns>MIME type, for instance </returns>
public static string GetMIMEType(string fileName)
{
if (Path.GetExtension(fileName).Length > 1 && /* File with an extension */
MIMETypesDictionary.ContainsKey(Path.GetExtension(fileName).Remove(0, 1)))
// If no extension or no match, return generic MIME type.
string result = "application/octet-stream";

string extensionWithDot = Path.GetExtension(fileName);
if (extensionWithDot.Length > 1) /* File with an extension */
{
return MIMETypesDictionary[Path.GetExtension(fileName).Remove(0, 1)];
string extension = Path.GetExtension(fileName).Remove(0, 1);
if (extension2mime.ContainsKey(extension))
{
result = extension2mime[extension];
}
}

// If no match, return generic MIME type.
return "application/octet-stream";
Logger.Debug("Filename to MIME: " + fileName + "->" + result);
return result;
}


/*public static string GetExtension(string mimeType)
{
string result = null;
if (mimeType != null && mimeType.Length > 0
&& mime2extension.ContainsKey(mimeType))
{
result = mime2extension[mimeType];
}
else
{
// If no such MIME type, return default extension: "unk" for "unknown"
result = "unk";
}
Logger.Debug("MIME to extension: " + mimeType + "->" + result);
return result;
}*/


/// <summary>
/// Static constructor to set <c>MIMETypesDictionary</c>
/// </summary>
Expand Down Expand Up @@ -1024,7 +1057,17 @@ static MimeType()

for (int x = 0; x < types.GetLength(0); ++x)
{
MIMETypesDictionary[types[x, 0]] = types[x, 1];
string extension = types[x, 0];
string mime = types[x, 1];
//MIMETypesDictionary.Add(types[x, 0], types[x, 1]);
//if (!mime2extension.ContainsKey(mime))
//{
// mime2extension.Add(mime, extension);
//}
if (!extension2mime.ContainsKey(extension))
{
extension2mime.Add(extension, mime);
}
}
}

Expand All @@ -1033,7 +1076,10 @@ static MimeType()
/// Dictionary of the most common filename extensions and associated MIME types.
/// List generated by https://github.com/nicolas-raoul/Filename_Extension_To_MIME_Type
/// </summary>
private static readonly Dictionary<string, string> MIMETypesDictionary =
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
//private static readonly BiDictionary<string, string> MIMETypesDictionary =
// new BiDictionary<string, string>();// StringComparer.OrdinalIgnoreCase);

//private static readonly Dictionary<string, string> mime2extension = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private static readonly Dictionary<string, string> extension2mime = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
}
8 changes: 7 additions & 1 deletion CmisSync.Lib/CmisSync.Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\Extras\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -113,6 +116,9 @@
<Name>DotCMIS</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="app.manifest" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
Expand All @@ -137,4 +143,4 @@
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
</Project>
</Project>
Loading

0 comments on commit db37962

Please sign in to comment.