PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/UploadersLib/UploadersConfig.cs

https://github.com/llehouerou/ShareX
C# | 428 lines | 280 code | 96 blank | 52 comment | 68 complexity | df85fc5d0cdab37b4869dcc606d2720e MD5 | raw file
Possible License(s): GPL-3.0
  1. #region License Information (GPL v3)
  2. /*
  3. ShareX - A program that allows you to take screenshots and share any file type
  4. Copyright (C) 2007-2014 ShareX Developers
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. Optionally you can also view the license at <http://www.gnu.org/licenses/>.
  17. */
  18. #endregion License Information (GPL v3)
  19. using CG.Web.MegaApiClient;
  20. using HelpersLib;
  21. using System;
  22. using System.Collections.Generic;
  23. using System.Windows.Forms;
  24. using UploadersLib.FileUploaders;
  25. using UploadersLib.HelperClasses;
  26. using UploadersLib.ImageUploaders;
  27. using UploadersLib.TextUploaders;
  28. namespace UploadersLib
  29. {
  30. public class UploadersConfig : SettingsBase<UploadersConfig>
  31. {
  32. #region Image uploaders
  33. // ImageShack
  34. public ImageShackOptions ImageShackSettings = new ImageShackOptions();
  35. // TinyPic
  36. public AccountType TinyPicAccountType = AccountType.Anonymous;
  37. public string TinyPicRegistrationCode = string.Empty;
  38. public string TinyPicUsername = string.Empty;
  39. public string TinyPicPassword = string.Empty;
  40. public bool TinyPicRememberUserPass = false;
  41. // Imgur
  42. public AccountType ImgurAccountType = AccountType.Anonymous;
  43. public ImgurThumbnailType ImgurThumbnailType = ImgurThumbnailType.Large_Thumbnail;
  44. public OAuth2Info ImgurOAuth2Info = null;
  45. public string ImgurAlbumID = string.Empty;
  46. // Flickr
  47. public FlickrAuthInfo FlickrAuthInfo = new FlickrAuthInfo();
  48. public FlickrSettings FlickrSettings = new FlickrSettings();
  49. // Photobucket
  50. public OAuthInfo PhotobucketOAuthInfo = null;
  51. public PhotobucketAccountInfo PhotobucketAccountInfo = null;
  52. // TwitPic
  53. public bool TwitPicShowFull = false;
  54. public TwitPicThumbnailType TwitPicThumbnailMode = TwitPicThumbnailType.Thumb;
  55. // YFrog
  56. public string YFrogUsername = string.Empty;
  57. public string YFrogPassword = string.Empty;
  58. // Picasa
  59. public OAuth2Info PicasaOAuth2Info = null;
  60. public string PicasaAlbumID = string.Empty;
  61. #endregion Image uploaders
  62. #region Text uploaders
  63. // Pastebin
  64. public PastebinSettings PastebinSettings = new PastebinSettings();
  65. // Paste.ee
  66. public string Paste_eeUserAPIKey = "public";
  67. // Gist
  68. public bool GistAnonymousLogin = true;
  69. public OAuth2Info GistOAuth2Info = null;
  70. public bool GistPublishPublic = false;
  71. // uPaste
  72. public string UpasteUserKey = string.Empty;
  73. public bool UpasteIsPublic = false;
  74. // Pushbullet
  75. public PushbulletSettings PushbulletSettings = new PushbulletSettings();
  76. #endregion Text uploaders
  77. #region File uploaders
  78. // Dropbox
  79. public OAuth2Info DropboxOAuth2Info = null;
  80. public DropboxAccountInfo DropboxAccountInfo = null;
  81. public string DropboxUploadPath = "Public/ShareX/%y/%mo";
  82. public bool DropboxAutoCreateShareableLink = false;
  83. public DropboxURLType DropboxURLType = DropboxURLType.Default;
  84. // Copy
  85. public OAuthInfo CopyOAuthInfo = null;
  86. public CopyAccountInfo CopyAccountInfo = null;
  87. public string CopyUploadPath = "ShareX/%y/%mo";
  88. public CopyURLType CopyURLType = CopyURLType.Shortened;
  89. // Google Drive
  90. public OAuth2Info GoogleDriveOAuth2Info = null;
  91. public bool GoogleDriveIsPublic = false;
  92. // RapidShare
  93. public string RapidShareUsername = string.Empty;
  94. public string RapidSharePassword = string.Empty;
  95. public string RapidShareFolderID = string.Empty;
  96. // SendSpace
  97. public AccountType SendSpaceAccountType = AccountType.Anonymous;
  98. public string SendSpaceUsername = string.Empty;
  99. public string SendSpacePassword = string.Empty;
  100. // Minus
  101. public OAuth2Info MinusOAuth2Info = null;
  102. public MinusOptions MinusConfig = new MinusOptions();
  103. // Box
  104. public OAuth2Info BoxOAuth2Info = null;
  105. public BoxFileEntry BoxSelectedFolder = Box.RootFolder;
  106. public bool BoxShare = true;
  107. // Ge.tt
  108. public Ge_ttLogin Ge_ttLogin = null;
  109. // Localhostr
  110. public string LocalhostrEmail = string.Empty;
  111. public string LocalhostrPassword = string.Empty;
  112. public bool LocalhostrDirectURL = true;
  113. // FTP Server
  114. public List<FTPAccount> FTPAccountList = new List<FTPAccount>();
  115. public int FTPSelectedImage = 0;
  116. public int FTPSelectedText = 0;
  117. public int FTPSelectedFile = 0;
  118. // Shared Folder
  119. public List<LocalhostAccount> LocalhostAccountList = new List<LocalhostAccount>();
  120. public int LocalhostSelectedImages = 0;
  121. public int LocalhostSelectedText = 0;
  122. public int LocalhostSelectedFiles = 0;
  123. // Email
  124. public string EmailSmtpServer = "smtp.gmail.com";
  125. public int EmailSmtpPort = 587;
  126. public string EmailFrom = "...@gmail.com";
  127. public string EmailPassword = string.Empty;
  128. public bool EmailRememberLastTo = true;
  129. public bool EmailConfirmSend = true;
  130. public string EmailLastTo = string.Empty;
  131. public string EmailDefaultSubject = "Sending email from " + Application.ProductName;
  132. public string EmailDefaultBody = "Screenshot is attached.";
  133. // Jira
  134. public string JiraHost = "http://";
  135. public string JiraIssuePrefix = "PROJECT-";
  136. public OAuthInfo JiraOAuthInfo = null;
  137. // Mega
  138. public MegaApiClient.AuthInfos MegaAuthInfos = null;
  139. public string MegaParentNodeId = null;
  140. // Amazon S3
  141. public AmazonS3Settings AmazonS3Settings = new AmazonS3Settings()
  142. {
  143. ObjectPrefix = "ShareX/%y/%mo",
  144. UseReducedRedundancyStorage = true
  145. };
  146. #endregion File uploaders
  147. #region URL shorteners
  148. // bit.ly
  149. public OAuth2Info BitlyOAuth2Info = null;
  150. // Google URL Shortener
  151. public AccountType GoogleURLShortenerAccountType = AccountType.Anonymous;
  152. public OAuth2Info GoogleURLShortenerOAuth2Info = null;
  153. // yourls.org
  154. public string YourlsAPIURL = "http://yoursite.com/yourls-api.php";
  155. public string YourlsSignature = string.Empty;
  156. public string YourlsUsername = string.Empty;
  157. public string YourlsPassword = string.Empty;
  158. #endregion URL shorteners
  159. #region Social networking services
  160. // Twitter
  161. public List<OAuthInfo> TwitterOAuthInfoList = new List<OAuthInfo>();
  162. public int TwitterSelectedAccount = 0;
  163. public TwitterClientSettings TwitterClientConfig = new TwitterClientSettings();
  164. #endregion Social networking services
  165. #region Custom Uploaders
  166. public List<CustomUploaderItem> CustomUploadersList = new List<CustomUploaderItem>();
  167. public int CustomImageUploaderSelected = 0;
  168. public int CustomTextUploaderSelected = 0;
  169. public int CustomFileUploaderSelected = 0;
  170. public int CustomURLShortenerSelected = 0;
  171. #endregion Custom Uploaders
  172. #region Helper Methods
  173. public bool IsActive<T>(int index)
  174. {
  175. Enum destination = (Enum)Enum.ToObject(typeof(T), index);
  176. if (destination is ImageDestination)
  177. {
  178. return IsActive((ImageDestination)destination);
  179. }
  180. if (destination is TextDestination)
  181. {
  182. return IsActive((TextDestination)destination);
  183. }
  184. if (destination is FileDestination)
  185. {
  186. return IsActive((FileDestination)destination);
  187. }
  188. if (destination is UrlShortenerType)
  189. {
  190. return IsActive((UrlShortenerType)destination);
  191. }
  192. if (destination is SocialNetworkingService)
  193. {
  194. return IsActive((SocialNetworkingService)destination);
  195. }
  196. return true;
  197. }
  198. public bool IsActive(ImageDestination destination)
  199. {
  200. switch (destination)
  201. {
  202. case ImageDestination.ImageShack:
  203. return ImageShackSettings != null && (ImageShackSettings.AccountType == AccountType.Anonymous || !string.IsNullOrEmpty(ImageShackSettings.Auth_token));
  204. case ImageDestination.TinyPic:
  205. return TinyPicAccountType == AccountType.Anonymous || !string.IsNullOrEmpty(TinyPicRegistrationCode);
  206. case ImageDestination.Imgur:
  207. return ImgurAccountType == AccountType.Anonymous || OAuth2Info.CheckOAuth(ImgurOAuth2Info);
  208. case ImageDestination.Flickr:
  209. return !string.IsNullOrEmpty(FlickrAuthInfo.Token);
  210. case ImageDestination.Photobucket:
  211. return PhotobucketAccountInfo != null && OAuthInfo.CheckOAuth(PhotobucketOAuthInfo);
  212. case ImageDestination.Picasa:
  213. return OAuth2Info.CheckOAuth(PicasaOAuth2Info);
  214. case ImageDestination.Twitpic:
  215. case ImageDestination.Twitsnaps:
  216. return TwitterOAuthInfoList != null && TwitterOAuthInfoList.IsValidIndex(TwitterSelectedAccount);
  217. case ImageDestination.yFrog:
  218. return !string.IsNullOrEmpty(YFrogUsername) && !string.IsNullOrEmpty(YFrogPassword);
  219. case ImageDestination.CustomImageUploader:
  220. return CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomImageUploaderSelected);
  221. default:
  222. return true;
  223. }
  224. }
  225. public bool IsActive(TextDestination destination)
  226. {
  227. switch (destination)
  228. {
  229. case TextDestination.CustomTextUploader:
  230. return CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomTextUploaderSelected);
  231. default:
  232. return true;
  233. }
  234. }
  235. public bool IsActive(FileDestination destination)
  236. {
  237. switch (destination)
  238. {
  239. case FileDestination.Dropbox:
  240. return OAuth2Info.CheckOAuth(DropboxOAuth2Info);
  241. case FileDestination.Copy:
  242. return OAuthInfo.CheckOAuth(CopyOAuthInfo);
  243. case FileDestination.GoogleDrive:
  244. return OAuth2Info.CheckOAuth(GoogleDriveOAuth2Info);
  245. case FileDestination.RapidShare:
  246. return !string.IsNullOrEmpty(RapidShareUsername) && !string.IsNullOrEmpty(RapidSharePassword);
  247. case FileDestination.SendSpace:
  248. return SendSpaceAccountType == AccountType.Anonymous || (!string.IsNullOrEmpty(SendSpaceUsername) && !string.IsNullOrEmpty(SendSpacePassword));
  249. case FileDestination.Minus:
  250. return MinusConfig != null && MinusConfig.MinusUser != null;
  251. case FileDestination.Box:
  252. return OAuth2Info.CheckOAuth(BoxOAuth2Info);
  253. case FileDestination.Ge_tt:
  254. return Ge_ttLogin != null && !string.IsNullOrEmpty(Ge_ttLogin.AccessToken);
  255. case FileDestination.Localhostr:
  256. return !string.IsNullOrEmpty(LocalhostrEmail) && !string.IsNullOrEmpty(LocalhostrPassword);
  257. case FileDestination.CustomFileUploader:
  258. return CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomFileUploaderSelected);
  259. case FileDestination.FTP:
  260. return FTPAccountList != null && FTPAccountList.IsValidIndex(FTPSelectedFile);
  261. case FileDestination.SharedFolder:
  262. return LocalhostAccountList != null && LocalhostAccountList.IsValidIndex(LocalhostSelectedFiles);
  263. case FileDestination.Email:
  264. return !string.IsNullOrEmpty(EmailSmtpServer) && EmailSmtpPort > 0 && !string.IsNullOrEmpty(EmailFrom) && !string.IsNullOrEmpty(EmailPassword);
  265. case FileDestination.Jira:
  266. return OAuthInfo.CheckOAuth(JiraOAuthInfo);
  267. case FileDestination.Mega:
  268. return MegaAuthInfos != null && MegaAuthInfos.Email != null && MegaAuthInfos.Hash != null && MegaAuthInfos.PasswordAesKey != null;
  269. case FileDestination.Pushbullet:
  270. return PushbulletSettings != null && !string.IsNullOrEmpty(PushbulletSettings.UserAPIKey) && PushbulletSettings.DeviceList != null &&
  271. PushbulletSettings.DeviceList.IsValidIndex(PushbulletSettings.SelectedDevice);
  272. default:
  273. return true;
  274. }
  275. }
  276. public bool IsActive(UrlShortenerType destination)
  277. {
  278. switch (destination)
  279. {
  280. case UrlShortenerType.Google:
  281. return GoogleURLShortenerAccountType == AccountType.Anonymous || OAuth2Info.CheckOAuth(GoogleURLShortenerOAuth2Info);
  282. case UrlShortenerType.BITLY:
  283. return OAuth2Info.CheckOAuth(BitlyOAuth2Info);
  284. case UrlShortenerType.YOURLS:
  285. return !string.IsNullOrEmpty(YourlsAPIURL) && (!string.IsNullOrEmpty(YourlsSignature) || (!string.IsNullOrEmpty(YourlsUsername) && !string.IsNullOrEmpty(YourlsPassword)));
  286. case UrlShortenerType.CustomURLShortener:
  287. return CustomUploadersList != null && CustomUploadersList.IsValidIndex(CustomURLShortenerSelected);
  288. default:
  289. return true;
  290. }
  291. }
  292. public bool IsActive(SocialNetworkingService destination)
  293. {
  294. switch (destination)
  295. {
  296. case SocialNetworkingService.Twitter:
  297. return TwitterOAuthInfoList != null && TwitterOAuthInfoList.IsValidIndex(TwitterSelectedAccount);
  298. default:
  299. return true;
  300. }
  301. }
  302. public int GetFTPIndex(EDataType dataType)
  303. {
  304. switch (dataType)
  305. {
  306. case EDataType.Image:
  307. return FTPSelectedImage;
  308. case EDataType.Text:
  309. return FTPSelectedText;
  310. default:
  311. return FTPSelectedFile;
  312. }
  313. }
  314. public int GetLocalhostIndex(EDataType dataType)
  315. {
  316. switch (dataType)
  317. {
  318. case EDataType.Image:
  319. return LocalhostSelectedImages;
  320. case EDataType.Text:
  321. return LocalhostSelectedText;
  322. default:
  323. return LocalhostSelectedFiles;
  324. }
  325. }
  326. #endregion Helper Methods
  327. }
  328. }