Skip to content

Commit

Permalink
修正一些目录使用问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aiqinxuancai committed Mar 1, 2024
1 parent 71f1d1b commit 895b53a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Aria2Fast/Service/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public class AppConfig

public AppConfigData ConfigData { set; get; } = new AppConfigData();

private string _configPath = AppContext.BaseDirectory + @"Config.json";
private string _configPath = Path.Combine(Directory.GetCurrentDirectory(), @"Config.json");

private object _lock = new object();

Expand Down
77 changes: 23 additions & 54 deletions Aria2Fast/Service/Aria2ApiManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ private void StartupLocalAria2()
//port=6809
//StopLocalAria2();

var aria2Path = Path.Combine(AppContext.BaseDirectory, "Aria2");
var aria2Path = Path.Combine(Directory.GetCurrentDirectory(), "Aria2");
var aria2File = Path.Combine(aria2Path, "aria2c.exe");
var aria2Conf = Path.Combine(aria2Path, "aria2.conf");

EasyLogManager.Logger.Info(aria2Path);
EasyLogManager.Logger.Info(aria2File);
EasyLogManager.Logger.Info(aria2Conf);


if (File.Exists(aria2File))
{
if (!File.Exists(aria2Conf))
Expand Down Expand Up @@ -145,8 +151,13 @@ private void StartupLocalAria2()
AppConfig.Instance.ConfigData.AddTaskSavePathDict[AppConfig.Instance.ConfigData.Aria2RpcAuto] = dir;
AppConfig.Instance.Save();


EasyLogManager.Logger.Info($"本地Aria2:{rpc}");
EasyLogManager.Logger.Info($"本地Aria2下载路径:{dir}");

if (!IsLocalAria2Runing())
{
EasyLogManager.Logger.Info($"启动Aria2:{aria2File}");
//本地的Aria2已经在运行了,这里不再启动
ProcessStartInfo startInfo = new ProcessStartInfo
{
Expand All @@ -159,13 +170,18 @@ private void StartupLocalAria2()
RedirectStandardError = true
};
_aria2Process = Process.Start(startInfo);
}
else
{
EasyLogManager.Logger.Info($"Aria2已启动:{aria2File}");
}
//启动进程

}
else
{
//错误
EasyLogManager.Logger.Error("本地Aria2");
}
}

Expand All @@ -175,7 +191,7 @@ public bool IsLocalAria2Runing()
{
try
{
var aria2Path = Path.Combine(AppContext.BaseDirectory, "Aria2");
var aria2Path = Path.Combine(Directory.GetCurrentDirectory(), "Aria2");
var aria2File = Path.Combine(aria2Path, "aria2c.exe");
var path = process.MainModule.FileName;
if (aria2File == path)
Expand All @@ -187,55 +203,14 @@ public bool IsLocalAria2Runing()
}
catch (Exception ex)
{
EasyLogManager.Logger.Error(ex);
Debug.WriteLine($"Could not terminate process {process.Id}: {ex.Message}");
}
}
return false;
}

public void StopLocalAria2()
{
foreach (var process in Process.GetProcessesByName("aria2c"))
{
try
{
var aria2Path = Path.Combine(AppContext.BaseDirectory, "Aria2");
var aria2File = Path.Combine(aria2Path, "aria2c.exe");
var path = process.MainModule.FileName;
if (aria2File == path)
{
Debug.WriteLine($"Process {process.Id} {path} has been terminated.");
process.Kill();
process.WaitForExit();
}


}
catch (Exception ex)
{
Debug.WriteLine($"Could not terminate process {process.Id}: {ex.Message}");
}
}

if (_aria2Process != null)
{
try
{
_aria2Process.Kill();
_aria2Process = null;

}
catch
{

}
finally
{

}

}
}



public void UpdateLocalAria2()
Expand Down Expand Up @@ -271,15 +246,9 @@ private void SetupEvent()
{

}
if (AppConfig.Instance.ConfigData.Aria2UseLocal)
{
await Task.Delay(2000);
}
else
{
await Task.Delay(5000);
}


await Task.Delay(5000);


}
});
Expand Down
4 changes: 2 additions & 2 deletions Aria2Fast/Utils/ImageCacheUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ImageCacheUtils

public static async Task PreloadImageCache()
{
var dirPath = Path.Combine(AppContext.BaseDirectory, "ImageCached");
var dirPath = Path.Combine(Directory.GetCurrentDirectory(), "ImageCached");
var files = Directory.GetFiles(dirPath);
MemoryCache cache = MemoryCache.Default;

Expand Down Expand Up @@ -65,7 +65,7 @@ public static BitmapImage GetImageWithLocalCache(Uri uri)
// return bmp;
//}

var dirPath = Path.Combine(AppContext.BaseDirectory, "ImageCached");
var dirPath = Path.Combine(Directory.GetCurrentDirectory(), "ImageCached");
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
Expand Down

0 comments on commit 895b53a

Please sign in to comment.