Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
code
Browse files Browse the repository at this point in the history
  • Loading branch information
depler committed Nov 25, 2022
1 parent 52a78fb commit f306528
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions app/Code/ExternalFilesManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Text;
using System.Threading;

Expand All @@ -24,64 +25,64 @@ public ExternalFilesManager(Context context)

public string CombinePath(string relativePath)
{
return System.IO.Path.Combine(_externalFilesFolder.Value, relativePath);
return Path.Combine(_externalFilesFolder.Value, relativePath);
}

public string CombinePath(string relativePath1, string relativePath2)
{
return System.IO.Path.Combine(_externalFilesFolder.Value, relativePath1, relativePath2);
return Path.Combine(_externalFilesFolder.Value, relativePath1, relativePath2);
}

public bool TryCreateFolder(string relativePath)
{
var path = CombinePath(relativePath);
if (System.IO.Directory.Exists(path))
if (Directory.Exists(path))
return false;

System.IO.Directory.CreateDirectory(path);
Directory.CreateDirectory(path);
return true;
}

public bool TryClearFolder(string relativePath)
{
var path = CombinePath(relativePath);
if (!System.IO.Directory.Exists(path))
if (!Directory.Exists(path))
return false;

foreach (var file in System.IO.Directory.GetFiles(path))
System.IO.File.Delete(file);
foreach (var file in Directory.GetFiles(path))
File.Delete(file);

return true;
}

public string[] ReadFileLines(string relativePath)
{
var path = CombinePath(relativePath);
return System.IO.File.ReadAllLines(path, _utf8);
return File.ReadAllLines(path, _utf8);
}

public void WriteFile(string assetPath)
{
var destinationPath = CombinePath(assetPath);

using var assetStream = _assetManager.Open(assetPath);
using var fileStream = System.IO.File.OpenWrite(destinationPath);
using var fileStream = File.OpenWrite(destinationPath);

assetStream.CopyTo(fileStream);
}

public void WriteConfigFile(string assetPath)
{
var torrentsFolder = System.IO.Path.Combine(_externalStorageFolder.Value, "Torrents");
var torrentsFolder = Path.Combine(_externalStorageFolder.Value, "Torrents");
var content = ReadAssetString(assetPath).Replace("TORRENT_FOLDER_PATH", torrentsFolder);

var destinationPath = CombinePath(assetPath);
System.IO.File.WriteAllText(destinationPath, content, _utf8);
File.WriteAllText(destinationPath, content, _utf8);
}

public void WriteArgsFile(string assetPath)
{
var configRelativePath = System.IO.Path.GetDirectoryName(assetPath);
var configRelativePath = Path.GetDirectoryName(assetPath);
var configFolder = CombinePath(configRelativePath);
var logFile = CombinePath(configRelativePath, "log.txt");

Expand All @@ -90,13 +91,13 @@ public void WriteArgsFile(string assetPath)
.Replace("LOG_FILE_PATH", logFile);

var destinationPath = CombinePath(assetPath);
System.IO.File.WriteAllText(destinationPath, content, _utf8);
File.WriteAllText(destinationPath, content, _utf8);
}

private string ReadAssetString(string assetPath)
{
using var stream = _assetManager.Open(assetPath);
using var reader = new System.IO.StreamReader(stream, _utf8);
using var reader = new StreamReader(stream, _utf8);
return reader.ReadToEnd();
}
}
Expand Down

0 comments on commit f306528

Please sign in to comment.