/// <summary> /// Creates a shortcut for an URL /// </summary> /// <param name="shortcutName">The name of the shortcut file</param> /// <param name="destinationDirectory">The path of the directory</param> /// <param name="targetURL">The URL</param> public void CreateURLShortcut(FileSystemPath shortcutName, FileSystemPath destinationDirectory, string targetURL) { try { // Make sure the file extension is correct or else Windows won't treat it as an URL shortcut shortcutName = shortcutName.ChangeFileExtension(new FileExtension(".url")); // Delete if a shortcut with the same name already exists DeleteFile(destinationDirectory + shortcutName); // Create the shortcut WindowsHelpers.CreateURLShortcut(shortcutName, destinationDirectory, targetURL); } catch (Exception ex) { ex.HandleUnexpected("Creating URL shortcut", destinationDirectory); throw; } }
/// <summary> /// Creates a file shortcut /// </summary> public void CreateFileShortcut(FileSystemPath ShortcutName, FileSystemPath DestinationDirectory, FileSystemPath TargetFile, string arguments = null) { try { // Make sure the file extension is correct or else Windows won't treat it as a shortcut ShortcutName = ShortcutName.ChangeFileExtension(new FileExtension(".lnk")); // Delete if a shortcut with the same name already exists DeleteFile(DestinationDirectory + ShortcutName); // Create the shortcut WindowsHelpers.CreateFileShortcut(ShortcutName, DestinationDirectory, TargetFile, arguments); RL.Logger?.LogInformationSource($"The shortcut {ShortcutName} was created"); } catch (Exception ex) { ex.HandleUnexpected("Creating shortcut", DestinationDirectory); throw; } }
/// <summary> /// Imports files to the directory /// </summary> /// <returns>The task</returns> public async Task ImportAsync() { // Run as a load operation using (Archive.LoadOperation.Run()) { // Lock the access to the archive using (await Archive.ArchiveLock.LockAsync()) { // Run as a task await Task.Run(async() => { // Get the directory var result = await Services.BrowseUI.BrowseDirectoryAsync(new DirectoryBrowserViewModel() { Title = Resources.Archive_ImportDirectoryHeader, }); if (result.CanceledByUser) { return; } // Keep track of the number of files getting imported var imported = 0; // Get the import data var importData = new List <ArchiveImportData>(); try { // Enumerate each directory view model foreach (var dir in this.GetAllChildren(true)) { // Enumerate each file foreach (var file in dir.Files) { // Get the file directory, relative to the selected directory FileSystemPath fileDir = result.SelectedDirectory + dir.FullPath.Remove(0, FullPath.Length).Trim(Path.DirectorySeparatorChar); // Get the base file path var baseFilePath = fileDir + new FileSystemPath(file.FileName); // Get the file path, without an extension FileSystemPath filePath = baseFilePath.RemoveFileExtension(true); if (!fileDir.DirectoryExists) { continue; } // Make sure there are potential file matches if (!Directory.GetFiles(fileDir, $"{filePath.Name}*", SearchOption.TopDirectoryOnly).Any()) { continue; } // Initialize the file bytes file.FileData.GetDecodedFileBytes(Archive.ArchiveFileStream, Archive.ArchiveFileGenerator, true); // Check if the base file exists without changing the extensions if (baseFilePath.FileExists) { // Import the file ImportFile(baseFilePath); continue; } // Attempt to find a file for each supported extension foreach (var ext in file.FileData.SupportedImportFileExtensions) { // Get the path var fullFilePath = filePath.ChangeFileExtension(ext); // Make sure the file exists if (!fullFilePath.FileExists) { continue; } // Import the file ImportFile(fullFilePath); // Break the loop break; } // Helper method for importing a file void ImportFile(FileSystemPath fullFilePath) { // Import the file var data = file.ImportFile(fullFilePath); // Add the data to the collection importData.Add(data); imported++; } } } } catch (Exception ex) { ex.HandleError("Importing archive directory", DisplayName); await Services.MessageUI.DisplayExceptionMessageAsync(ex, Resources.Archive_RepackError); return; } // Make sure at least one file has been imported if (imported == 0) { await Services.MessageUI.DisplayMessageAsync(Resources.Archive_ImportNoFilesError, MessageType.Error); return; } // Update the archive var repackSucceeded = await Archive.UpdateArchiveAsync(importData); if (!repackSucceeded) { return; } await Services.MessageUI.DisplaySuccessfulActionMessageAsync(Resources.Archive_ImportFilesSuccess); }); } } }