ShareX/ShareX/TaskInfo.cs

220 lines
6.8 KiB
C#
Raw Normal View History

2013-11-03 23:53:49 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
2024-01-03 12:57:14 +13:00
Copyright (c) 2007-2024 ShareX Team
2013-11-03 23:53:49 +13:00
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
2014-12-11 09:25:20 +13:00
using ShareX.HelpersLib;
using ShareX.HistoryLib;
using ShareX.UploadersLib;
2014-12-11 12:19:28 +13:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
2014-12-11 12:19:28 +13:00
using System.IO;
2013-11-03 23:53:49 +13:00
namespace ShareX
{
public class TaskInfo
{
public TaskSettings TaskSettings { get; set; }
public string Status { get; set; }
public TaskJob Job { get; set; }
public bool IsUploadJob
{
get
{
2016-07-20 22:35:45 +12:00
switch (Job)
{
case TaskJob.Job:
return TaskSettings.AfterCaptureJob.HasFlag(AfterCaptureTasks.UploadImageToHost);
case TaskJob.DataUpload:
case TaskJob.FileUpload:
case TaskJob.TextUpload:
case TaskJob.ShortenURL:
case TaskJob.ShareURL:
case TaskJob.DownloadUpload:
return true;
}
return false;
2013-11-03 23:53:49 +13:00
}
}
public ProgressManager Progress { get; set; }
private string filePath;
public string FilePath
{
get
{
return filePath;
}
set
{
filePath = value;
if (string.IsNullOrEmpty(filePath))
{
2016-05-25 06:15:45 +12:00
FileName = "";
}
else
{
FileName = Path.GetFileName(filePath);
}
2013-11-03 23:53:49 +13:00
}
}
public string FileName { get; set; }
public string ThumbnailFilePath { get; set; }
2013-11-03 23:53:49 +13:00
public EDataType DataType { get; set; }
2021-12-12 00:56:42 +13:00
public TaskMetadata Metadata { get; set; }
2013-11-03 23:53:49 +13:00
public EDataType UploadDestination
{
get
{
if ((DataType == EDataType.Image && TaskSettings.ImageDestination == ImageDestination.FileUploader) ||
(DataType == EDataType.Text && TaskSettings.TextDestination == TextDestination.FileUploader))
2013-11-03 23:53:49 +13:00
{
return EDataType.File;
}
return DataType;
}
}
public string UploaderHost
{
get
{
if (IsUploadJob)
2013-11-03 23:53:49 +13:00
{
switch (UploadDestination)
{
case EDataType.Image:
2014-10-25 13:04:41 +13:00
return TaskSettings.ImageDestination.GetLocalizedDescription();
case EDataType.Text:
2014-10-25 13:04:41 +13:00
return TaskSettings.TextDestination.GetLocalizedDescription();
case EDataType.File:
switch (DataType)
{
case EDataType.Image:
2014-10-25 13:04:41 +13:00
return TaskSettings.ImageFileDestination.GetLocalizedDescription();
case EDataType.Text:
2014-10-25 13:04:41 +13:00
return TaskSettings.TextFileDestination.GetLocalizedDescription();
default:
case EDataType.File:
2014-10-25 13:04:41 +13:00
return TaskSettings.FileDestination.GetLocalizedDescription();
}
case EDataType.URL:
if (Job == TaskJob.ShareURL)
{
2014-10-25 13:04:41 +13:00
return TaskSettings.URLSharingServiceDestination.GetLocalizedDescription();
}
2014-10-25 13:04:41 +13:00
return TaskSettings.URLShortenerDestination.GetLocalizedDescription();
}
2013-11-03 23:53:49 +13:00
}
2016-05-25 06:15:45 +12:00
return "";
2013-11-03 23:53:49 +13:00
}
}
public DateTime TaskStartTime { get; set; }
public DateTime TaskEndTime { get; set; }
2013-11-03 23:53:49 +13:00
2017-06-12 08:01:11 +12:00
public TimeSpan TaskDuration => TaskEndTime - TaskStartTime;
2013-11-03 23:53:49 +13:00
public Stopwatch UploadDuration { get; set; }
2013-11-03 23:53:49 +13:00
public UploadResult Result { get; set; }
public TaskInfo(TaskSettings taskSettings)
{
if (taskSettings == null)
{
taskSettings = TaskSettings.GetDefaultTaskSettings();
}
TaskSettings = taskSettings;
2021-12-14 13:45:17 +13:00
Metadata = new TaskMetadata();
2013-11-03 23:53:49 +13:00
Result = new UploadResult();
}
public Dictionary<string, string> GetTags()
{
2021-12-12 00:56:42 +13:00
if (Metadata != null)
{
Dictionary<string, string> tags = new Dictionary<string, string>();
2021-12-12 00:56:42 +13:00
if (!string.IsNullOrEmpty(Metadata.WindowTitle))
{
2021-12-12 00:56:42 +13:00
tags.Add("WindowTitle", Metadata.WindowTitle);
}
2021-12-12 00:56:42 +13:00
if (!string.IsNullOrEmpty(Metadata.ProcessName))
{
2021-12-12 00:56:42 +13:00
tags.Add("ProcessName", Metadata.ProcessName);
}
if (tags.Count > 0)
{
return tags;
}
}
return null;
}
public override string ToString()
{
2016-04-25 02:43:57 +12:00
string text = Result.ToString();
2016-04-25 02:43:57 +12:00
if (string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(FilePath))
{
text = FilePath;
}
return text;
}
2013-11-03 23:53:49 +13:00
public HistoryItem GetHistoryItem()
{
return new HistoryItem
{
2019-10-22 00:20:21 +13:00
FileName = FileName,
FilePath = FilePath,
DateTime = TaskEndTime,
2013-11-03 23:53:49 +13:00
Type = DataType.ToString(),
Host = UploaderHost,
URL = Result.URL,
ThumbnailURL = Result.ThumbnailURL,
DeletionURL = Result.DeletionURL,
ShortenedURL = Result.ShortenedURL,
Tags = GetTags()
2013-11-03 23:53:49 +13:00
};
}
}
}