Skip to content

Commit

Permalink
- Added Option to delete/move associated .funscript files
Browse files Browse the repository at this point in the history
- Huge Code optimization
- Cleaned up code
- Fixed some bugs
  • Loading branch information
Peanutccino authored and Peanutccino committed Mar 8, 2024
1 parent ea1f7b6 commit 931b91d
Show file tree
Hide file tree
Showing 32 changed files with 897 additions and 832 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.Random Video Player/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/.idea.Random Video Player/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/.idea.Random Video Player/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.Random Video Player/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.Random Video Player/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 30 additions & 22 deletions RandomVideoPlayerV3/Controls/FlatProgressBar.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Mpv.NET.API;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;

namespace RandomVideoPlayerV3
namespace RandomVideoPlayer
{
public class FlatProgressBar : Control
{
Expand All @@ -19,8 +18,10 @@ public class FlatProgressBar : Control
private Color _completedGraphBrush = Color.White;
private Color _remainingGraphBrush = Color.Black;
private Color _mouseOverColor = Color.Black;
private Bitmap? progressBitmap;
private Bitmap? remainingBitmap;

private Bitmap progressBitmapBuffer;
private Bitmap remainingBitmapBuffer;
private readonly object bitmapLock = new object();
private List<ActionPoint> actionPoints = new List<ActionPoint>();

public FlatProgressBar()
Expand Down Expand Up @@ -188,18 +189,13 @@ public void DeleteActionsPoints()
}
private void PreRenderGraph()
{
progressBitmap?.Dispose();
remainingBitmap?.Dispose();

if (actionPoints == null || actionPoints.Count == 0 || this.Width == 0 || this.Height == 0)
{
progressBitmap = null;
remainingBitmap = null;
return;
}

progressBitmap = new Bitmap(Width, Height);
remainingBitmap = new Bitmap(Width, Height);
Bitmap progressBitmap = new Bitmap(Width, Height);
Bitmap remainingBitmap = new Bitmap(Width, Height);

using (Graphics g = Graphics.FromImage(progressBitmap))
{
Expand All @@ -215,14 +211,22 @@ private void PreRenderGraph()

DrawFunscriptGraph(g, _remainingGraphBrush);
}

lock (bitmapLock)
{
progressBitmapBuffer?.Dispose();
remainingBitmapBuffer?.Dispose();
progressBitmapBuffer = progressBitmap;
remainingBitmapBuffer = remainingBitmap;
}
}
private void DrawFunscriptGraph(Graphics g, Color graphcolor)
{
if (actionPoints.Count < 2) return;

int maxTime = Maximum;

using (Pen remainingGraphPen = new Pen(graphcolor, _graphThickness))
using (Pen GraphPen = new Pen(graphcolor, _graphThickness))
{
for (int i = 0; i < actionPoints.Count - 1; i++)
{
Expand All @@ -234,7 +238,7 @@ private void DrawFunscriptGraph(Graphics g, Color graphcolor)
float endX = (float)endPoint.At / maxTime * Width;
float endY = (1 - (float)endPoint.Pos / 100) * Height;

g.DrawLine(remainingGraphPen, startX, startY, endX, endY);
g.DrawLine(GraphPen, startX, startY, endX, endY);

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
}
Expand All @@ -255,14 +259,22 @@ protected override void OnPaint(PaintEventArgs e)
}
else
{
Bitmap progressBitmapToDraw, remainingBitmapToDraw;

lock (bitmapLock)
{
progressBitmapToDraw = progressBitmapBuffer;
remainingBitmapToDraw = remainingBitmapBuffer;
}

// Draw the pre-rendered graph bitmap
if (progressBitmap != null && remainingBitmap != null)
if (progressBitmapToDraw != null && remainingBitmapToDraw != null)
{
Rectangle progressRect = new Rectangle(0, 0, progressWidth, Height);
e.Graphics.DrawImage(progressBitmap, progressRect, progressRect, GraphicsUnit.Pixel);
e.Graphics.DrawImage(progressBitmapToDraw, progressRect, progressRect, GraphicsUnit.Pixel);

Rectangle remainingRect = new Rectangle(progressWidth, 0, Width - progressWidth, Height);
e.Graphics.DrawImage(remainingBitmap, remainingRect, remainingRect, GraphicsUnit.Pixel);
e.Graphics.DrawImage(remainingBitmapToDraw, remainingRect, remainingRect, GraphicsUnit.Pixel);
}
}
// Draw border if ShowBorder is true
Expand All @@ -272,13 +284,9 @@ protected override void OnPaint(PaintEventArgs e)
var pen = new Pen(_borderColor, BorderThickness);
e.Graphics.DrawRectangle(pen, borderRect);
}

}



}
public class ActionPoint
public struct ActionPoint
{
public long At { get; set; } // Time in milliseconds
public int Pos { get; set; } // Position value
Expand Down
2 changes: 1 addition & 1 deletion RandomVideoPlayerV3/Controls/ToggleButton.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Drawing.Drawing2D;
using System.ComponentModel;

namespace RandomVideoPlayerV3
namespace RandomVideoPlayer
{
public class ToggleButton : CheckBox
{
Expand Down
7 changes: 3 additions & 4 deletions RandomVideoPlayerV3/Functions/CustomSettings.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using System.Collections.Specialized;
namespace RandomVideoPlayerV3

namespace RandomVideoPlayer.Functions
{
public class CustomSettings
{
Expand All @@ -9,6 +10,7 @@ public class CustomSettings
public bool lastSize { get; set; } = false;
public string removeFolder { get; set; } = @"C:\";
public bool deleteFull { get; set; } = true;
public bool includeScripts { get; set; } = true;
public string listFolder { get; set; }
public bool recentCheckedSaved { get; set; } = false;
public int recentCountSaved { get; set; } = 50;
Expand All @@ -23,7 +25,6 @@ public class CustomSettings
public StringCollection favoriteCollection { get; set; } = new StringCollection();
public StringCollection customListConfig { get; set; } = new StringCollection();

// The path to the settings file
private static string settingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RVP-Config.json");

private static CustomSettings _instance;
Expand All @@ -45,13 +46,11 @@ public static CustomSettings Instance
}
}
}
// Save settings to a file
public void Save()
{
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
File.WriteAllText(settingsFilePath, json);
}
// Load settings from a file
public static CustomSettings Load()
{
if (File.Exists(settingsFilePath))
Expand Down
50 changes: 50 additions & 0 deletions RandomVideoPlayerV3/Functions/FavFunctions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using RandomVideoPlayer.Model;

namespace RandomVideoPlayer.Functions
{
public class FavFunctions
{
public static List<string> AddToFavorites(string currentFile)
{
var favFile = PathHandler.FolderList + @"\Favorites.txt";
var fromTXT = new List<string>();

if (File.Exists(favFile))
{
fromTXT = File.ReadLines(favFile).ToList();
}
if (!fromTXT.Contains(currentFile))
{
fromTXT.Add(currentFile);
}
File.WriteAllLines(favFile, fromTXT);

return fromTXT;
}

public static List<string> DeleteFromFavorites(string currentFile, List<string> tempFavorites)
{
string favFile = PathHandler.FolderList + @"\Favorites.txt";

tempFavorites.Remove(currentFile);

File.WriteAllLines(favFile, tempFavorites);

return tempFavorites;
}

public static bool IsFavoriteMatched(string currentVideo, List<string> tempFavorites, FontAwesome.Sharp.IconButton ctrl)
{
if (tempFavorites.Contains(currentVideo))
{
ctrl.IconColor = Color.Red;
return true;
}
else
{
ctrl.IconColor = Color.Black;
return false;
}
}
}
}
82 changes: 82 additions & 0 deletions RandomVideoPlayerV3/Functions/FileManipulation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace RandomVideoPlayer.Functions
{
public class FileManipulation
{
/// <summary>
/// Take a filepath and changes the extension to a chosen one
/// </summary>
/// <param name="originalFilePath">String with full filepath</param>
/// <param name="newExtension">Extension to replace the original with</param>
/// <returns>Original filepath with selected extension instead of original</returns>
public static string GetFilePathWithDifferentExtension(string originalFilePath, string newExtension)
{
string directory = Path.GetDirectoryName(originalFilePath);

string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(originalFilePath);

string newFilePath = Path.Combine(directory, fileNameWithoutExtension + newExtension);

return newFilePath;
}
/// <summary>
/// Searches for available .funscript variants of the provided file
/// </summary>
/// <param name="originalFilePath">String with full filepath</param>
/// <returns>List with all found funscripts</returns>
public static List<string> GetAssociatedFunscripts(string originalFilePath)
{
var funscriptList = new List<string>();
var filePathWithoutExtension = Path.Combine(Path.GetDirectoryName(originalFilePath), Path.GetFileNameWithoutExtension(originalFilePath));

var suffixes = new string[] { "", ".pitch", ".roll", ".surge", ".sway", ".twist" };

foreach (var suffix in suffixes)
{
string fullFileName = $"{filePathWithoutExtension}{suffix}.funscript";
if (File.Exists(fullFileName))
{
funscriptList.Add(fullFileName);
}
}
return funscriptList;
}
/// <summary>
/// Get directory path from a string
/// </summary>
/// <param name="filePath">String with full filepath</param>
/// <returns>Path to directory that holds the file</returns>
public static string GetFileDirectory(string filePath)
{
string directory = Path.GetDirectoryName(filePath);

if (string.IsNullOrWhiteSpace(directory)) return "";
return directory;
}
/// <summary>
/// Get Filename with extension from a string
/// </summary>
/// <param name="filePath">String with full filepath</param>
/// <returns>Filename with extension without path</returns>
public static string GetFileName(string filePath)
{
string fileName = Path.GetFileName(filePath);

if (string.IsNullOrWhiteSpace(fileName)) return "";
return fileName;
}
/// <summary>
/// Trim string to length and optionally add string at the end (e.g. "...")
/// </summary>
/// <param name="text">String to trim</param>
/// <param name="length">Trim to length</param>
/// <param name="end">Add string to end of trimmed string</param>
/// <returns>Trimmed text</returns>
public static string TrimText(string text, int length, string end)
{
int maxLength = length; // Maximum text length.
string truncatedText = text.Length <= maxLength ? text : text.Substring(0, maxLength) + end;

return truncatedText;
}
}
}
12 changes: 2 additions & 10 deletions RandomVideoPlayerV3/Functions/FormResize.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RandomVideoPlayerV3.Functions
namespace RandomVideoPlayer.Functions
{
public class FormResize
{
//private static CustomSettings _settingsInstance = CustomSettings.Load();

private int _borderSize = 2;
private bool _windowExclusiveFullscreen = false;
private Size _tempSize;
Expand Down Expand Up @@ -93,7 +85,7 @@ public bool WindowExclusiveFullscreen
f.WindowState = FormWindowState.Minimized;
}

private void PlayerIsWindowSize(Form f, Panel top, Panel bottom, Panel player) //Logic to align panels automaticcaly in window mode
private void PlayerIsWindowSize(Form f, Panel top, Panel bottom, Panel player) //Logic to align panels automatically in window mode
{
player.Location = new Point(_borderSize, top.Height + _borderSize);
player.Size = new Size(f.Width - (_borderSize * 2), f.Height - top.Height - bottom.Height - (_borderSize * 2));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

namespace RandomVideoPlayerV3.Model
namespace RandomVideoPlayer.Functions
{
static class RandomExtension
{
public static IEnumerable<T> Shuffle<T>(this Random rng, IEnumerable<T> input)
{
List<T> list = input.ToList();
List<T> list = input.ToList();
int n = list.Count;
while (n > 1)
{
Expand Down

0 comments on commit 931b91d

Please sign in to comment.