Directories are created using C++ when a song is uploaded

This commit is contained in:
amazing-username
2019-08-04 14:04:40 +00:00
parent 2d984813ec
commit 15948c4783
10 changed files with 126 additions and 67 deletions
+9
View File
@@ -38,6 +38,7 @@ namespace Icarus.Controllers.Managers
coverArt); coverArt);
song.CoverArtId = coverArt.CoverArtId; song.CoverArtId = coverArt.CoverArtId;
_logger.Info("Cover art Process saving complete");
} }
public void DeleteCoverArtFromDatabase(CoverArt coverArt, public void DeleteCoverArtFromDatabase(CoverArt coverArt,
CoverArtRepository coverArtRepository) CoverArtRepository coverArtRepository)
@@ -122,6 +123,14 @@ namespace Icarus.Controllers.Managers
Console.WriteLine("Copied Stock Cover Art"); 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 #endregion
} }
} }
+3 -1
View File
@@ -2,6 +2,7 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
@@ -94,7 +95,8 @@ namespace Icarus.Controllers.Managers
} }
} }
[DllImport("libicarus.so")] [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() public void DeleteEmptyDirectories()
{ {
try try
+12 -7
View File
@@ -4,6 +4,7 @@ using System.Configuration;
using System.Data; using System.Data;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@@ -362,17 +363,21 @@ namespace Icarus.Controllers.Managers
var song = await SaveSongTemp(songFile, fileTempPath); var song = await SaveSongTemp(songFile, fileTempPath);
song.SongPath = fileTempPath; song.SongPath = fileTempPath;
DirectoryManager dirMgr = new DirectoryManager(_config, song);
dirMgr.CreateDirectory();
var sng = ConvertSongToSng(song); 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); System.IO.File.Delete(fileTempPath);
Environment.Exit(1);
var filePath = dirMgr.SongDirectory;
var songFilename = songFile.FileName; var songFilename = songFile.FileName;
if (!songFilename.EndsWith(".mp3")) if (!songFilename.EndsWith(".mp3"))
+7 -7
View File
@@ -14,12 +14,12 @@ namespace Icarus.Database.Contexts
{ {
public DbSet<CoverArt> CoverArtImages { get; set; } public DbSet<CoverArt> CoverArtImages { get; set; }
public CoverArtContext(DbContextOptions<CoverArtContext> options) : base(options) { } public CoverArtContext(DbContextOptions<CoverArtContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<CoverArt>() modelBuilder.Entity<CoverArt>()
.ToTable("CoverArt"); .ToTable("CoverArt");
} }
} }
} }
+10 -2
View File
@@ -2,9 +2,17 @@ cmake_minimum_required(VERSION 3.10)
project(icarus) project(icarus)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(SOURCES 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")
+5
View File
@@ -0,0 +1,5 @@
#include "models.h"
#include <string>
std::string create_directory_process(Song, const char*);
+10
View File
@@ -0,0 +1,10 @@
struct Song
{
int Id;
char *Title;
char *Artist;
char *Album;
char *Genre;
int Year;
};
+68
View File
@@ -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;
}
}
-50
View File
@@ -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;
}
}
+2
View File
@@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text; using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
@@ -14,6 +15,7 @@ namespace Icarus.Models
public string SongTitle { get; set; } public string SongTitle { get; set; }
[JsonIgnore] [JsonIgnore]
public string ImagePath { get; set; } public string ImagePath { get; set; }
[NotMapped]
[JsonProperty("song_id")] [JsonProperty("song_id")]
public int SongId { get; set; } public int SongId { get; set; }
[JsonIgnore] [JsonIgnore]