Directories are created using C++ when a song is uploaded
This commit is contained in:
@@ -38,6 +38,7 @@ namespace Icarus.Controllers.Managers
|
||||
coverArt);
|
||||
|
||||
song.CoverArtId = coverArt.CoverArtId;
|
||||
_logger.Info("Cover art Process saving complete");
|
||||
}
|
||||
public void DeleteCoverArtFromDatabase(CoverArt coverArt,
|
||||
CoverArtRepository coverArtRepository)
|
||||
@@ -122,6 +123,14 @@ namespace Icarus.Controllers.Managers
|
||||
Console.WriteLine("Copied Stock Cover Art");
|
||||
}
|
||||
}
|
||||
#region Testing
|
||||
private void PrintCoverArtDetails(CoverArt cover)
|
||||
{
|
||||
Console.WriteLine("\nCover art");
|
||||
Console.WriteLine($"Song Title: {cover.SongTitle}");
|
||||
Console.WriteLine($"ImagePath: {cover.ImagePath}\n");
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
@@ -94,7 +95,8 @@ namespace Icarus.Controllers.Managers
|
||||
}
|
||||
}
|
||||
[DllImport("libicarus.so")]
|
||||
public static extern void create_directory(SongManager.Sng song);
|
||||
public static extern void create_directory(SongManager.Sng song, string root_path, StringBuilder created_dir);
|
||||
//public static extern void create_directory(SongManager.Sng song, string root_path, string created_dir);
|
||||
public void DeleteEmptyDirectories()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Configuration;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -362,17 +363,21 @@ namespace Icarus.Controllers.Managers
|
||||
var song = await SaveSongTemp(songFile, fileTempPath);
|
||||
song.SongPath = fileTempPath;
|
||||
|
||||
DirectoryManager dirMgr = new DirectoryManager(_config, song);
|
||||
dirMgr.CreateDirectory();
|
||||
|
||||
var sng = ConvertSongToSng(song);
|
||||
|
||||
DirectoryManager.create_directory(sng);
|
||||
var rootPath = _config.GetValue<string>("RootMusicPath");
|
||||
var strCount = rootPath.Length + song.Artist.Length +
|
||||
song.AlbumTitle.Length + 2;
|
||||
|
||||
var filePathSB = new StringBuilder(strCount);
|
||||
|
||||
DirectoryManager.create_directory(sng,
|
||||
rootPath, filePathSB);
|
||||
|
||||
var filePath = filePathSB.ToString().Substring(0, strCount);
|
||||
|
||||
System.IO.File.Delete(fileTempPath);
|
||||
Environment.Exit(1);
|
||||
|
||||
var filePath = dirMgr.SongDirectory;
|
||||
|
||||
var songFilename = songFile.FileName;
|
||||
|
||||
if (!songFilename.EndsWith(".mp3"))
|
||||
|
||||
@@ -14,12 +14,12 @@ namespace Icarus.Database.Contexts
|
||||
{
|
||||
public DbSet<CoverArt> CoverArtImages { get; set; }
|
||||
|
||||
public CoverArtContext(DbContextOptions<CoverArtContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<CoverArt>()
|
||||
.ToTable("CoverArt");
|
||||
}
|
||||
public CoverArtContext(DbContextOptions<CoverArtContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<CoverArt>()
|
||||
.ToTable("CoverArt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -2,9 +2,17 @@ cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(icarus)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
set(SOURCES
|
||||
src/icarus.cpp
|
||||
src/directory_manager.cpp
|
||||
)
|
||||
set(HEADERS
|
||||
include/models.h
|
||||
include/directory_manager.h
|
||||
)
|
||||
|
||||
add_library(icarus SHARED ${SOURCES})
|
||||
add_library(icarus SHARED ${SOURCES} ${HEADERS})
|
||||
include_directories(include)
|
||||
target_link_libraries(icarus "-lstdc++fs")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "models.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string create_directory_process(Song, const char*);
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
struct Song
|
||||
{
|
||||
int Id;
|
||||
char *Title;
|
||||
char *Artist;
|
||||
char *Album;
|
||||
char *Genre;
|
||||
int Year;
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
#include "directory_manager.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::string create_directory_process(Song song, const char *root_path)
|
||||
{
|
||||
auto curr_path = fs::path(root_path);
|
||||
|
||||
if (fs::exists(curr_path)) {
|
||||
std::cout<<"path exists"<<std::endl;
|
||||
} else {
|
||||
std::cout<<"creating path"<<std::endl;
|
||||
fs::create_directory(curr_path);
|
||||
}
|
||||
|
||||
auto art_path = fs::path(curr_path.string() + song.Artist);
|
||||
if (fs::exists(art_path)) {
|
||||
std::cout<<"artist path exists"<<std::endl;
|
||||
} else {
|
||||
std::cout<<"creating artist path"<<std::endl;
|
||||
fs::create_directory(art_path);
|
||||
}
|
||||
|
||||
auto alb_path = fs::path(art_path.string() + "/" + song.Album);
|
||||
if (fs::exists(alb_path)) {
|
||||
std::cout<<"album path exists"<<std::endl;
|
||||
} else {
|
||||
std::cout<<"creating album path"<<std::endl;
|
||||
fs::create_directory(alb_path);
|
||||
}
|
||||
|
||||
return alb_path.string() + "/";
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void create_directory(Song, const char*, char*);
|
||||
void print_song_details(const Song);
|
||||
|
||||
void create_directory(Song song, const char *root_path, char *dir)
|
||||
{
|
||||
std::cout<<"c++ creating directory"<<std::endl;
|
||||
|
||||
std::string tmp = create_directory_process(song, root_path);
|
||||
std::cout<<"tmp size "<<tmp.size()<<std::endl;
|
||||
//dir = (char*)tmp.c_str();
|
||||
std::cout<<"done"<<std::endl;
|
||||
size_t tmp_sz = tmp.size();
|
||||
tmp.copy(dir, tmp_sz, 0);
|
||||
//std::copy(tmp.begin(), tmp.end()-1, dir);
|
||||
std::cout<<"still c++ "<<dir<<"\n\n";
|
||||
}
|
||||
void print_song_details(const Song song)
|
||||
{
|
||||
std::cout<<"song details"<<std::endl;
|
||||
std::cout<<"title: "<<song.Title<<std::endl;
|
||||
std::cout<<"artist: "<<song.Artist<<std::endl;
|
||||
std::cout<<"album: "<<song.Album<<std::endl;
|
||||
std::cout<<"genre: "<<song.Genre<<std::endl;
|
||||
std::cout<<"year: "<<song.Year<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
constexpr auto app_setting = "appsettings.Development.json";
|
||||
|
||||
struct Song
|
||||
{
|
||||
int Id;
|
||||
char *Title;
|
||||
char *Artist;
|
||||
char *Album;
|
||||
char *Genre;
|
||||
int Year;
|
||||
};
|
||||
|
||||
void create_directory_process(Song);
|
||||
|
||||
void create_directory_process(Song song)
|
||||
{
|
||||
auto curr_path = fs::current_path();
|
||||
std::cout<<"current path "<<curr_path.string()<<std::endl;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void create_directory(Song);
|
||||
void print_song_details(const Song);
|
||||
|
||||
void create_directory(Song song)
|
||||
{
|
||||
std::cout<<"c++ creating directory"<<std::endl;
|
||||
print_song_details(song);
|
||||
create_directory_process(song);
|
||||
}
|
||||
|
||||
void print_song_details(const Song song)
|
||||
{
|
||||
std::cout<<"song details"<<std::endl;
|
||||
std::cout<<"title: "<<song.Title<<std::endl;
|
||||
std::cout<<"artist: "<<song.Artist<<std::endl;
|
||||
std::cout<<"album: "<<song.Album<<std::endl;
|
||||
std::cout<<"genre: "<<song.Genre<<std::endl;
|
||||
std::cout<<"year: "<<song.Year<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Text;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
@@ -14,6 +15,7 @@ namespace Icarus.Models
|
||||
public string SongTitle { get; set; }
|
||||
[JsonIgnore]
|
||||
public string ImagePath { get; set; }
|
||||
[NotMapped]
|
||||
[JsonProperty("song_id")]
|
||||
public int SongId { get; set; }
|
||||
[JsonIgnore]
|
||||
|
||||
Reference in New Issue
Block a user