Fix some events not firing and deleting of temporary repos

This commit is contained in:
Hylke Bons 2010-08-01 13:31:11 +01:00
parent 83c39669d7
commit b3d7a2bd2e
3 changed files with 43 additions and 24 deletions

View file

@ -33,13 +33,11 @@ namespace SparkleShare {
private string Folder; private string Folder;
private string RemoteOriginUrl; private string RemoteOriginUrl;
private string RepoName;
public SparkleFetcher (string url, string folder) public SparkleFetcher (string url, string folder)
{ {
RepoName = Path.GetDirectoryName (folder);
Folder = folder; Folder = folder;
RemoteOriginUrl = url; RemoteOriginUrl = url;
@ -81,16 +79,13 @@ namespace SparkleShare {
} else { } else {
InstallUserInfo ();
InstallExcludeRules (); InstallExcludeRules ();
args = new SparkleEventArgs ("CloningFinished"); args = new SparkleEventArgs ("CloningFinished");
Console.WriteLine ("FINISHED"); if (CloningFinished != null)
if (CloningFinished != null) {
Console.WriteLine ("EVENT FIRED");
CloningFinished (this, args); CloningFinished (this, args);
}
} }
@ -101,13 +96,19 @@ namespace SparkleShare {
} }
private void InstallUserInfo ()
{
// Install username and email from global file
}
// Add a .gitignore file to the repo // Add a .gitignore file to the repo
private void InstallExcludeRules () private void InstallExcludeRules ()
{ {
TextWriter writer; TextWriter writer = new StreamWriter (SparkleHelpers.CombineMore (Folder, ".git/info/exclude"));
writer = new StreamWriter (SparkleHelpers.CombineMore (SparklePaths.SparklePath,
RepoName, ".git/info/exclude"));
writer.WriteLine ("*~"); // Ignore gedit swap files writer.WriteLine ("*~"); // Ignore gedit swap files
writer.WriteLine (".*.sw?"); // Ignore vi swap files writer.WriteLine (".*.sw?"); // Ignore vi swap files

View file

@ -334,7 +334,8 @@ namespace SparkleShare {
string url = server + "/" + name; string url = server + "/" + name;
string tmp_folder = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, name); string tmp_folder = SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath,
System.IO.Path.GetFileNameWithoutExtension (name));
SparkleFetcher fetcher = new SparkleFetcher (url, tmp_folder); SparkleFetcher fetcher = new SparkleFetcher (url, tmp_folder);
@ -349,14 +350,11 @@ namespace SparkleShare {
fetcher.CloningFinished += delegate { fetcher.CloningFinished += delegate {
Console.WriteLine ("CLONING FINISHED");
SparkleHelpers.DebugInfo ("Git", "[" + name + "] Repository cloned"); SparkleHelpers.DebugInfo ("Git", "[" + name + "] Repository cloned");
Directory.Move (tmp_folder, ClearAttributes (tmp_folder);
SparkleHelpers.CombineMore (SparklePaths.SparklePath, name));
// Install username and email from global file Directory.Move (tmp_folder, SparklePaths.SparklePath);
ShowFinishedStep (); ShowFinishedStep ();
@ -367,20 +365,18 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("Git", "[" + name + "] Cloning failed"); SparkleHelpers.DebugInfo ("Git", "[" + name + "] Cloning failed");
try { if (Directory.Exists (tmp_folder)) {
Directory.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, ClearAttributes (tmp_folder);
name)); Directory.Delete (tmp_folder, true);
SparkleHelpers.DebugInfo ("Config", SparkleHelpers.DebugInfo ("Config",
"[" + name + "] Deleted temporary directory"); "[" + name + "] Deleted temporary directory");
} catch (System.IO.DirectoryNotFoundException) { }
ShowErrorStep (); ShowErrorStep ();
}
}; };
ShowStepTwoAndAHalf (); ShowStepTwoAndAHalf ();
@ -420,6 +416,27 @@ namespace SparkleShare {
} }
// Recursively sets access rights of a folder to 'Normal'
private void ClearAttributes (string path)
{
if (Directory .Exists (path)) {
string [] folders = Directory .GetDirectories (path);
foreach (string folder in folders)
ClearAttributes (folder);
string [] files = Directory .GetFiles(path);
foreach (string file in files)
File.SetAttributes (file, FileAttributes.Normal);
}
}
private void ShowErrorStep () private void ShowErrorStep ()
{ {
@ -440,7 +457,7 @@ namespace SparkleShare {
Label header = new Label ("<span size='x-large'><b>" + Label header = new Label ("<span size='x-large'><b>" +
_("Something went wrong…") + _("Something went wrong…") +
"</b></span>") { "</b></span>\n") {
UseMarkup = true, UseMarkup = true,
Xalign = 0 Xalign = 0
}; };

View file

@ -40,6 +40,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="SparkleBubble.cs" /> <Compile Include="SparkleBubble.cs" />
<Compile Include="SparkleFetcher.cs" />
<Compile Include="SparkleIntro.cs" /> <Compile Include="SparkleIntro.cs" />
<Compile Include="SparkleHelpers.cs" /> <Compile Include="SparkleHelpers.cs" />
<Compile Include="SparklePaths.cs" /> <Compile Include="SparklePaths.cs" />