Core Dream Studios
Core Dream Studios
CC#
Created by Core Dream Studios on 6/18/2024 in #help
Dependency Injection + MVVM?
I followed a Tim Corey tutorial on Dependency Injection in WPF but he did not use MVVM just raw code behind. How hard would be to switch over to MVVM? I just want an app where I have a MainView, SettingsView, and a few other Views. He uses Interfaces, etc and I'm lost. :< What should I do?
431 replies
CC#
Created by Core Dream Studios on 5/4/2024 in #help
BindModel with DateTimePicker
I have a simple WinForms Dapper ORM w/SQLite app I've written, everything works except binding to the DateTimePicker controls. My model:
namespace TaskMinder.Model;

public class Entry
{
public int Id { get; set; } = 0;
public DateTime EntryDate { get; set; }
public DateTime EntryTime { get; set; }
public string EntryData { get; set; } = string.Empty;
}
namespace TaskMinder.Model;

public class Entry
{
public int Id { get; set; } = 0;
public DateTime EntryDate { get; set; }
public DateTime EntryTime { get; set; }
public string EntryData { get; set; } = string.Empty;
}
My method:
private void BindModel(Entry model)
{
NewEntryDatePicker.DataBindings.Add("Value", model, "EntryDate", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTimePicker.DataBindings.Add("Value", model, "EntryTime", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTextBox.DataBindings.Add("Text", model, "EntryData", true, DataSourceUpdateMode.OnPropertyChanged);
}
private void BindModel(Entry model)
{
NewEntryDatePicker.DataBindings.Add("Value", model, "EntryDate", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTimePicker.DataBindings.Add("Value", model, "EntryTime", true, DataSourceUpdateMode.OnPropertyChanged);
NewEntryTextBox.DataBindings.Add("Text", model, "EntryData", true, DataSourceUpdateMode.OnPropertyChanged);
}
What am I doing wrong? Thank you in advance.
3 replies
CC#
Created by Core Dream Studios on 1/29/2024 in #help
_sdbModel Model not being referenced
I am trying to enumerate my model and insert it into my SQLite database, but when I try, the model is null. Doing a debug on the ImportFileSDB() does show data in the model before the next method is called. Did I miss a step somewhere? I appreciate your advice. Main Form Class
using System.Diagnostics;
using TitanSTUDIO.Helpers.Parsers;
using TitanSTUDIO.Models;
using TitanSTUDIO.Repositories;

namespace TitanSTUDIO.Presentation
{
public partial class FTUEView : Form
{
static StringDatabaseModel? _sdbModel;

public FTUEView()
{
InitializeComponent();
}

private static async Task ImportSDBFile()
{
try
{
using (var ofd = new OpenFileDialog())
{
ofd.Filter = "String Database File (*.sdb)|*.sdb";
ofd.RestoreDirectory = true;

if (ofd.ShowDialog() == DialogResult.OK)
{
Debug.WriteLine("Reading SDB File...");

_sdbModel = await StringDatabase.ReadStringAsync(ofd.FileName);

// Import model data into the sqlite table.
await StringFileRepository.ImportData("StringsEnglishTable", StringFileRepository._sdbModel);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private async void NextStepBtn_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}

private async void ImportSDB_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}
}
}
using System.Diagnostics;
using TitanSTUDIO.Helpers.Parsers;
using TitanSTUDIO.Models;
using TitanSTUDIO.Repositories;

namespace TitanSTUDIO.Presentation
{
public partial class FTUEView : Form
{
static StringDatabaseModel? _sdbModel;

public FTUEView()
{
InitializeComponent();
}

private static async Task ImportSDBFile()
{
try
{
using (var ofd = new OpenFileDialog())
{
ofd.Filter = "String Database File (*.sdb)|*.sdb";
ofd.RestoreDirectory = true;

if (ofd.ShowDialog() == DialogResult.OK)
{
Debug.WriteLine("Reading SDB File...");

_sdbModel = await StringDatabase.ReadStringAsync(ofd.FileName);

// Import model data into the sqlite table.
await StringFileRepository.ImportData("StringsEnglishTable", StringFileRepository._sdbModel);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private async void NextStepBtn_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}

private async void ImportSDB_Click(object sender, EventArgs e)
{
await ImportSDBFile();
}
}
}
Repository class: https://paste.mod.gg/tqxazwksrppy/0
2 replies
CC#
Created by Core Dream Studios on 1/6/2024 in #help
Exporting all model data to a CSV
Hello. I have successfully pulled data out of a custom .sdb (not sqlite), from a old game and was trying to save it to a .CSV so I can import it into a database later (SQLite). I can do the last part just fine but getting a bit lost on the Export side. Thank you in advance.
5 replies
CC#
Created by Core Dream Studios on 11/7/2023 in #help
❔ WF to WPF Help Needed
Hello sharpers. I have a issue where I need to convert at least the LoadFileSyncs to work with CommunityToolkit.MVVM in WPF I know how to Bind a ICommand to a button, I know how to do very basic ViewModel stuff so far but this is very new to me. OG Code is @ https://pastebin.com/EQyMRsvf My VM is @ https://pastebin.com/7cxT0ntv I appreciate you all!
8 replies
CC#
Created by Core Dream Studios on 9/27/2023 in #help
❔ Bytes to UInt64
I am having a issue trying to turn the hex output to ulong, (UINT64). I keep getting 6687895829614943646 from 5CD02DD2B303DD9E I know 5CD02DD2B303DD9E should be 11447309898705915996 since my hex editor is right. I am using Little Endian. Any help would be appreciated, thank you. Here is my code:
private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;

string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));

}

if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{

// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);

if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);

ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
}
private void GenerateHash()
{
// Make sure the input is not empty.
if (HashInput.Text.Length > 0)
{
// Convert \ to /
string hashInput = HashInput.Text.Replace(@"\", "/");
HashInput.Text = hashInput;

string hashString;
if (HashTypeList.SelectedIndex == 0)
{
hashString = ByteConverter.ByteArrayToString(HashFNV1.Hash(hashInput));
}
else
{
hashString = ByteConverter.ByteArrayToString(HashFNV1A.Hash(hashInput));

}

if (OutputAsHex.Checked)
{
HashResult.Text = hashString;
}
else
{
try
{

// Convert to UInt64
byte[] byteArray = HashFNV1A.Hash(hashInput);

if (BitConverter.IsLittleEndian)
Array.Reverse(byteArray);

ulong ulongValue = Convert.ToUInt64(hashString, 16);
HashResult.Text = ulongValue.ToString();
}
catch (OverflowException)
{
Console.WriteLine("Unable to convert '{0}' to an unsigned long integer.", hashString);
}
catch (FormatException)
{
Console.WriteLine("'{0}' is not in the correct format.", hashString);
}
}
}
}
67 replies
CC#
Created by Core Dream Studios on 8/17/2023 in #help
❔ Async Method with current code.
I am having a hell of a brain fart, probably my damn ASD again. Can someone help me fix this?
private static string GetFilePath(StringBuilder builder, TrackViewModel track, string downloadPath, FileFormat fileFormat)
{
// Change ReleaseDate format to yyyy-MM-dd (Added by Core Dream Studios)

DateTime formattedDate = track.ReleaseDate;
var formattedDateString = formattedDate.ToString("yyyy-MM-dd");

builder.Clear();
builder.Append(formattedDateString);
builder.Append(" - ");
builder.Append(track.ArtistsTitle);
builder.Append(" - ");
builder.Append(track.Title);

if (!string.IsNullOrWhiteSpace(track.Version))
{
builder.Append('(');
builder.Append(track.Version);
builder.Append(')');
}

builder.Append(GetFileExtension(fileFormat));

var fileName = builder.ToString().SanitizeAsFileName();

var archivedFolderPath = $@"{downloadPath}\{formattedDateString} - {track.CatalogId} - {track.Title}";

// Create a subfolder inside the users download path based on the year, catalog id then the artist.
if (!Directory.Exists(archivedFolderPath))
Directory.CreateDirectory(archivedFolderPath);

// Added a ability to download coverart.
// Credit to @mtreit (https://github.com/treit)
// Credit to @angius (https://github.com/Atulin)


var cover = $"https://cdx.monstercat.com/?width={3000}&encoding=jpg&url=https://www.monstercat.com/release/{track.CatalogId}/cover";
DownloadCoverArtAsync(cover, archivedFolderPath);

return Path.Combine(archivedFolderPath, fileName!);
}

private static async Task DownloadCoverArtAsync(string coverURL, string downloadPath)
{
var _client = new HttpClient();
using var stream = await _client.GetStreamAsync(coverURL);
using var fs = new FileStream($@"{downloadPath}\cover.jpg", FileMode.Create);

stream.CopyTo(fs);
}
private static string GetFilePath(StringBuilder builder, TrackViewModel track, string downloadPath, FileFormat fileFormat)
{
// Change ReleaseDate format to yyyy-MM-dd (Added by Core Dream Studios)

DateTime formattedDate = track.ReleaseDate;
var formattedDateString = formattedDate.ToString("yyyy-MM-dd");

builder.Clear();
builder.Append(formattedDateString);
builder.Append(" - ");
builder.Append(track.ArtistsTitle);
builder.Append(" - ");
builder.Append(track.Title);

if (!string.IsNullOrWhiteSpace(track.Version))
{
builder.Append('(');
builder.Append(track.Version);
builder.Append(')');
}

builder.Append(GetFileExtension(fileFormat));

var fileName = builder.ToString().SanitizeAsFileName();

var archivedFolderPath = $@"{downloadPath}\{formattedDateString} - {track.CatalogId} - {track.Title}";

// Create a subfolder inside the users download path based on the year, catalog id then the artist.
if (!Directory.Exists(archivedFolderPath))
Directory.CreateDirectory(archivedFolderPath);

// Added a ability to download coverart.
// Credit to @mtreit (https://github.com/treit)
// Credit to @angius (https://github.com/Atulin)


var cover = $"https://cdx.monstercat.com/?width={3000}&encoding=jpg&url=https://www.monstercat.com/release/{track.CatalogId}/cover";
DownloadCoverArtAsync(cover, archivedFolderPath);

return Path.Combine(archivedFolderPath, fileName!);
}

private static async Task DownloadCoverArtAsync(string coverURL, string downloadPath)
{
var _client = new HttpClient();
using var stream = await _client.GetStreamAsync(coverURL);
using var fs = new FileStream($@"{downloadPath}\cover.jpg", FileMode.Create);

stream.CopyTo(fs);
}
Thanks
94 replies
CC#
Created by Core Dream Studios on 7/18/2023 in #help
❔ ✅ ListView Annoyances.
I am trying to use await/async to pull all files from all folders in a chosen path. The issue I have is when trying to add them to a listview, and it keeps erroring out with the message: :'Cannot add or insert the item 'bakedfile00/AI/AIGOSGameObject.jsfb' in more than one place. You must first remove it from its current location or clone it. (Parameter 'item')' I am close to solving it, been trying various things but no luck. Can anyone help me? Thank you. My code is at this URL due to Discord message limit. https://pastebin.com/Eab8dP9F Thank you! ❤️
141 replies
CC#
Created by Core Dream Studios on 4/6/2023 in #help
❔ VB to C# for Moving all folders and files?
Is there a way to do this in C# without relying on Microsoft.VisualBasic.FileIO? Thank you.
Sub MoveAllItems(ByVal fromPath As String, ByVal toPath As String)
My.Computer.FileSystem.CopyDirectory(fromPath, toPath, True)
'Here we want to not recycle the files since the files are moved
My.Computer.FileSystem.DeleteDirectory(fromPath, FileIO.DeleteDirectoryOption.DeleteAllContents)
End Sub
Sub MoveAllItems(ByVal fromPath As String, ByVal toPath As String)
My.Computer.FileSystem.CopyDirectory(fromPath, toPath, True)
'Here we want to not recycle the files since the files are moved
My.Computer.FileSystem.DeleteDirectory(fromPath, FileIO.DeleteDirectoryOption.DeleteAllContents)
End Sub
4 replies
CC#
Created by Core Dream Studios on 2/7/2023 in #help
❔ Enumerating Running Processes
I am missing something, besides brain cells but what should I be returning if I want a ComboBox to have the list of Windows processes?
internal class ProcessHelpers
{
public static List<string> RunningProcessList = new();

public static string GetRunningProcesses()
{
Process[] processes = Process.GetProcesses().Where(p => (long)p.MainWindowHandle != 0).ToArray();

foreach (Process process in processes)
{
RunningProcessList.Add(process.ProcessName);
}

return List<string> RunningProcessList;
}
}
internal class ProcessHelpers
{
public static List<string> RunningProcessList = new();

public static string GetRunningProcesses()
{
Process[] processes = Process.GetProcesses().Where(p => (long)p.MainWindowHandle != 0).ToArray();

foreach (Process process in processes)
{
RunningProcessList.Add(process.ProcessName);
}

return List<string> RunningProcessList;
}
}
140 replies
CC#
Created by Core Dream Studios on 2/1/2023 in #help
❔ System.AccessViolationException: 'Attempted to read or write protected memory.
Even with <AllowUnsafeCodeBlocks> enabled and using unsafe { }, this error does not go away. And before anyone asks, no this is not a cheat app or related to online gaming. Is this a limitation of C#? Thanks! System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
41 replies
CC#
Created by Core Dream Studios on 10/30/2022 in #help
Need Python to C Sharp Conversion
``` Summary: Trying to port a CRC32 lib Martin Scharrer created in Python, I see no known C# version and I am barely a Python dev. Sources: https://github.com/MartinScharrer/crccheck/blob/main/crccheck/crc.py https://github.com/MartinScharrer/crccheck/blob/main/crccheck/checksum.py I do have the crc.py, I will add it to this post if anyone can give me a clue. I appreciate you so much and yes I'd include his license and credit. 🙂
39 replies
CC#
Created by Core Dream Studios on 8/19/2022 in #help
BinaryReader Question
Trying to read the values AS bytes, but reader reads them as decimals, is there a trick to making it bytes?
private void ReadArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];
int offset = 288;

if (File.Exists(fileName))
{
using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
{
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
reader.Read(bytesCrowdType, 0, 8);
}
}
}
private void ReadArenaDefs(string arenaSlotNumber)
{
string fileName = @$"{AppDomain.CurrentDomain.BaseDirectory}\ArenaDefinition_00505.jsfb";

byte[] bytesCrowdType = new byte[8];
int offset = 288;

if (File.Exists(fileName))
{
using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
{
reader.BaseStream.Seek(offset, SeekOrigin.Begin);
reader.Read(bytesCrowdType, 0, 8);
}
}
}
49 replies