source: trunk/src/org/expeditee/auth/account/Contacts.java@ 1391

Last change on this file since 1391 was 1391, checked in by bln4, 5 years ago

Formatting and syntax corrections on feedback to user.

File size: 3.6 KB
Line 
1package org.expeditee.auth.account;
2
3import java.awt.Desktop;
4import java.io.File;
5import java.io.IOException;
6import java.net.URI;
7import java.net.URISyntaxException;
8import java.net.URL;
9import java.nio.file.Files;
10import java.nio.file.Path;
11import java.nio.file.Paths;
12
13import org.expeditee.gui.FrameIO;
14import org.expeditee.settings.UserSettings;
15
16public class Contacts {
17
18 public static String distributeContactDetails(String username) {
19 StringBuilder sb = new StringBuilder();
20 String nl = System.getProperty("line.separator");
21 String me = UserSettings.UserName.get();
22 Path profilePath = Paths.get(FrameIO.PROFILE_PATH).resolve(me);
23 Path resourcesUsernamePath = Paths.get(FrameIO.PARENT_FOLDER).resolve("resources-" + username);
24 if (resourcesUsernamePath.toFile().exists()) {
25 sb.append("Detected the presence of the user " + username + " in your Expeditee file system. Contact details automatically distributed.");
26 Path credentialsDirectoryToSharePath = profilePath.resolve(me + "-credentials");
27 Path partnerContactsDirectory = resourcesUsernamePath.resolve("contacts");
28 try {
29 copyFileTree(credentialsDirectoryToSharePath, partnerContactsDirectory.resolve(me + "-credentials"));
30 return sb.toString();
31 } catch (IOException e) {
32 sb = new StringBuilder();
33 }
34 }
35
36 try {
37 Desktop.getDesktop().open(profilePath.toFile());
38 sb.append("We have opened your profile directory for you.");
39 sb.append("1. Tab to it (if not visible) and right click on the " + me + "-credentials directory." + nl);
40 } catch (IOException e) {
41 sb.append("1. Open your profile directory (" + profilePath + ") and right click on the " + me + "-credentials directory." + nl);
42 }
43
44 sb.append("2. Click on 'Share with Google Drive'." + nl);
45 sb.append("3. Enter " + username + "'s email in the text box." + nl);
46 sb.append("4. Click on the button to the right of the text box in order to set the share to 'View Only'." + nl);
47 sb.append("5. Optionally add a note for " + username + " to read. Click the send button.");
48
49 return sb.toString();
50 }
51
52 public static String addContactDetails(String username) {
53 StringBuilder sb = new StringBuilder();
54 String nl = System.getProperty("line.separator");
55 String me = UserSettings.UserName.get();
56 String driveSharedWithMeString = "https://drive.google.com/drive/shared-with-me";
57 try {
58 URI driveSharedWithMeURL = new URL(driveSharedWithMeString).toURI();
59 Desktop.getDesktop().browse(driveSharedWithMeURL);
60 sb.append("We have opened Google Drive to the 'Shared With Me' page in your browser.");
61 sb.append("1. Right click on " + username + "-credentials and click on 'Add To My Drive'." + nl);
62 } catch (IOException | URISyntaxException e) {
63 sb.append("1. Open your web browser to " + driveSharedWithMeString + ". Right click on " + username + "-credentials and click on 'Add To My Drive'." + nl);
64 }
65
66 sb.append("2. Click organise and navigate the dialog to resources-" + me + "/contacts and click the 'Move Here' button to relocate your copy of " + username + "'s credentials folder.");
67
68 return sb.toString();
69 }
70
71 private static void copyFileTree(Path source, Path target) throws IOException {
72 if (source.toFile().isDirectory()) {
73 if (!target.toFile().exists()) {
74 Files.copy(source, target);
75 }
76 File[] files = source.toFile().listFiles();
77 for (File file: files) {
78 Path asPath = Paths.get(file.getAbsolutePath());
79 copyFileTree(asPath, target.resolve(asPath.getFileName()));
80 }
81 } else {
82 Files.copy(source, target);
83 }
84 }
85}
Note: See TracBrowser for help on using the repository browser.