public bool remove(string app_id) { lock (appList) { if (!appList.ContainsKey(app_id)) { return(false); } CustomApp app = appList[app_id]; Directory.Delete(Path.Combine(appsPath, app.id), true); appList.Remove(app_id); return(true); } }
public void start() { if (started) { Logging.warn("Custom App Manager already started."); return; } started = true; lock (appList) { foreach (var path in Directory.EnumerateDirectories(appsPath)) { string app_info_path = Path.Combine(path, "appinfo.spixi"); if (!File.Exists(app_info_path)) { continue; } CustomApp app = new CustomApp(File.ReadAllLines(app_info_path)); appList.Add(app.id, app); } } }
public string install(string url) { string file_name = Path.GetRandomFileName(); string source_app_file_path = Path.Combine(tmpPath, file_name); using (HttpClient client = new HttpClient()) { try { File.WriteAllBytes(source_app_file_path, client.GetByteArrayAsync(url).Result); } catch (Exception e) { Logging.error("Exception occured while downloading file: " + e); if (File.Exists(source_app_file_path)) { File.Delete(source_app_file_path); } return(null); } } string app_name = ""; string source_app_path = Path.Combine(tmpPath, file_name + ".dir"); string target_app_path = ""; try { using (ZipArchive archive = ZipFile.Open(source_app_file_path, ZipArchiveMode.Read)) { if (Directory.Exists(source_app_path)) { Directory.Delete(source_app_path, true); } Directory.CreateDirectory(source_app_path); // extract the app to tmp location archive.ExtractToDirectory(source_app_path); // read app info CustomApp app = new CustomApp(File.ReadAllLines(Path.Combine(source_app_path, "appinfo.spixi"))); if (appList.ContainsKey(app.id)) { // TODO except when updating - version check Logging.warn("App {0} already installed.", app.id); if (File.Exists(source_app_file_path)) { File.Delete(source_app_file_path); } if (Directory.Exists(source_app_path)) { Directory.Delete(source_app_path, true); } return(null); } app_name = app.name; // TODO sig check target_app_path = Path.Combine(appsPath, app.id); // move to apps directory Directory.Move(source_app_path, target_app_path); lock (appList) { // add app to the list appList.Add(app.id, app); } } File.Delete(source_app_file_path); } catch (Exception e) { Logging.error("Error installing app: " + e); if (File.Exists(source_app_file_path)) { File.Delete(source_app_file_path); } if (Directory.Exists(source_app_path)) { Directory.Delete(source_app_path, true); } if (target_app_path != "" && Directory.Exists(target_app_path)) { Directory.Delete(target_app_path, true); } return(null); } return(app_name); }