-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utilities.cs
68 lines (60 loc) · 2.15 KB
/
Utilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using RestSharp;
using RestSharp.Serializers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.XPath;
using FileManagement;
using UltiDrive.SkyDrive;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using UltiDrive.Dropbox.Api;
namespace UltiDrive
{
public partial class file
{
public string fullpath { get { return this.rootFolder + this.relativeFilePath; } }
}
public interface API
{
void Login(bool asDialog);
void Logout();
file DownloadFile(string guid, string downloadLocation);
file UpdateFile(string fullfilepath);
file UploadFile(string guid, string fullfilepath);
bool DeleteFile();
}
class Utilities
{
public static string ParseSourceForIdentifier(string identifier, string source)
{
//looks through the URL to find the specified identifier and returns the value of the identifier
//i.e. if given string moneymaker = "?source=desktop&view=mobile"
//method(view, moneymaker) returns mobile
string result = "";
if (source.IndexOf(identifier) == -1)
return null;
int NextEqualSign = source.IndexOf('=', source.IndexOf(identifier));
if (source.LastIndexOf('&') > source.IndexOf(identifier))
{
int NextAmpersand = source.IndexOf('&', NextEqualSign);
result = source.Substring(NextEqualSign + 1, NextAmpersand - NextEqualSign - 1);
}
else
{
result = source.Substring(NextEqualSign + 1, source.Length - NextEqualSign-1);
}
return result;
}
public static void WriteDropboxSettings()
{
string json = Newtonsoft.Json.JsonConvert.SerializeObject(DropboxApi.Api.AccessToken);
System.IO.File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\UltiDrive\\Dropbox.json", json);
}
}
}