Made AddFilesToLibrary not abstract
Removed SaveToLibrary
This commit is contained in:
parent
396b9984be
commit
17bd020218
5 changed files with 51 additions and 78 deletions
|
|
@ -35,6 +35,7 @@ using MatterHackers.PolygonMesh;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
||||
|
|
@ -68,6 +69,14 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null)
|
||||
{
|
||||
foreach (string file in files)
|
||||
{
|
||||
AddItem(new PrintItemWrapper(new PrintItem(Path.GetFileNameWithoutExtension(file), file), this));
|
||||
}
|
||||
}
|
||||
|
||||
// A key,value list that threads into the current collection looks like "key0,displayName0|key1,displayName1|key2,displayName2|...|keyN,displayNameN".
|
||||
public List<ProviderLocatorNode> GetProviderLocator()
|
||||
{
|
||||
|
|
@ -86,7 +95,10 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
#region Abstract Methods
|
||||
|
||||
public abstract void AddItem(PrintItemWrapper itemToAdd);
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
public abstract int CollectionCount { get; }
|
||||
|
||||
public abstract int ItemCount { get; }
|
||||
|
|
@ -101,10 +113,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public abstract void AddCollectionToLibrary(string collectionName);
|
||||
|
||||
public abstract void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null);
|
||||
|
||||
public abstract void AddItem(PrintItemWrapper itemToAdd);
|
||||
|
||||
public abstract PrintItemCollection GetCollectionItem(int collectionIndex);
|
||||
|
||||
public abstract Task<PrintItemWrapper> GetPrintItemWrapperAsync(int itemIndex, ReportProgressRatio reportProgress = null);
|
||||
|
|
@ -117,8 +125,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
|
||||
public abstract void RemoveItem(int itemIndexToRemove);
|
||||
|
||||
public abstract void SaveToLibrary(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> providerSavePath = null);
|
||||
|
||||
#endregion Abstract Methods
|
||||
|
||||
#region Static Methods
|
||||
|
|
|
|||
|
|
@ -152,20 +152,15 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public override void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null)
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
{
|
||||
string destPath = rootPath;
|
||||
|
||||
CopyAllFiles(files, destPath);
|
||||
CopyFile(itemToAdd.FileLocation, destPath);
|
||||
|
||||
GetFilesAndCollectionsInCurrentDirectory();
|
||||
}
|
||||
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override PrintItemCollection GetCollectionItem(int collectionIndex)
|
||||
{
|
||||
string directoryName = currentDirectoryDirectories[collectionIndex];
|
||||
|
|
@ -213,12 +208,7 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
GetFilesAndCollectionsInCurrentDirectory();
|
||||
}
|
||||
|
||||
public override void SaveToLibrary(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> providerSavePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static void CopyAllFiles(IList<string> files, string destPath)
|
||||
private static void CopyFile(string file, string destPath)
|
||||
{
|
||||
// make sure the directory exists
|
||||
try
|
||||
|
|
@ -230,46 +220,43 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
|
||||
// save it to the root directory
|
||||
foreach (string file in files)
|
||||
string outputFileName = Path.Combine(destPath, Path.GetFileName(file));
|
||||
// and copy the file
|
||||
try
|
||||
{
|
||||
string outputFileName = Path.Combine(destPath, Path.GetFileName(file));
|
||||
// and copy the file
|
||||
try
|
||||
if (!File.Exists(outputFileName))
|
||||
{
|
||||
if (!File.Exists(outputFileName))
|
||||
{
|
||||
File.Copy(file, outputFileName);
|
||||
}
|
||||
else // make a new file and append a number so that we are not destructive
|
||||
{
|
||||
string directory = Path.GetDirectoryName(outputFileName);
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(outputFileName);
|
||||
string extension = Path.GetExtension(outputFileName);
|
||||
// get the filename without a number on the end
|
||||
int lastSpaceIndex = fileNameWithoutExtension.LastIndexOf(' ');
|
||||
if (lastSpaceIndex != -1)
|
||||
{
|
||||
int endingNumber;
|
||||
// check if the last set of characters is a number
|
||||
if (int.TryParse(fileNameWithoutExtension.Substring(lastSpaceIndex), out endingNumber))
|
||||
{
|
||||
fileNameWithoutExtension = fileNameWithoutExtension.Substring(0, lastSpaceIndex);
|
||||
}
|
||||
}
|
||||
int numberToAppend = 2;
|
||||
string fileNameToUse = Path.Combine(directory, fileNameWithoutExtension + " " + numberToAppend.ToString() + extension);
|
||||
while (File.Exists(fileNameToUse))
|
||||
{
|
||||
numberToAppend++;
|
||||
fileNameToUse = Path.Combine(directory, fileNameWithoutExtension + " " + numberToAppend.ToString() + extension);
|
||||
}
|
||||
File.Copy(file, fileNameToUse);
|
||||
}
|
||||
File.Copy(file, outputFileName);
|
||||
}
|
||||
catch (Exception e)
|
||||
else // make a new file and append a number so that we are not destructive
|
||||
{
|
||||
string directory = Path.GetDirectoryName(outputFileName);
|
||||
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(outputFileName);
|
||||
string extension = Path.GetExtension(outputFileName);
|
||||
// get the filename without a number on the end
|
||||
int lastSpaceIndex = fileNameWithoutExtension.LastIndexOf(' ');
|
||||
if (lastSpaceIndex != -1)
|
||||
{
|
||||
int endingNumber;
|
||||
// check if the last set of characters is a number
|
||||
if (int.TryParse(fileNameWithoutExtension.Substring(lastSpaceIndex), out endingNumber))
|
||||
{
|
||||
fileNameWithoutExtension = fileNameWithoutExtension.Substring(0, lastSpaceIndex);
|
||||
}
|
||||
}
|
||||
int numberToAppend = 2;
|
||||
string fileNameToUse = Path.Combine(directory, fileNameWithoutExtension + " " + numberToAppend.ToString() + extension);
|
||||
while (File.Exists(fileNameToUse))
|
||||
{
|
||||
numberToAppend++;
|
||||
fileNameToUse = Path.Combine(directory, fileNameWithoutExtension + " " + numberToAppend.ToString() + extension);
|
||||
}
|
||||
File.Copy(file, fileNameToUse);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void DiretoryContentsChanged(object sender, EventArgs e)
|
||||
|
|
|
|||
|
|
@ -198,11 +198,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
|
@ -242,11 +237,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void SaveToLibrary(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> providerSavePath = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion Overriden Abstract Methods
|
||||
}
|
||||
}
|
||||
|
|
@ -252,15 +252,15 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
LoadLibraryItems();
|
||||
}
|
||||
|
||||
public override async void AddFilesToLibrary(IList<string> files, ReportProgressRatio reportProgress = null)
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
{
|
||||
if (files != null && files.Count > 0)
|
||||
if (itemToAdd != null && itemToAdd.FileLocation != null)
|
||||
{
|
||||
// create enough info to show that we have items pending (maybe use names from this file list for them)
|
||||
// refresh the display to show the pending items
|
||||
//LibraryProvider.OnDataReloaded(null);
|
||||
|
||||
await Task.Run(() => loadFilesIntoLibraryBackgoundWorker_DoWork(files));
|
||||
Task.Run(() => loadFilesIntoLibraryBackgoundWorker_DoWork(new string[] { itemToAdd.FileLocation }));
|
||||
|
||||
if (baseLibraryCollection != null)
|
||||
{
|
||||
|
|
@ -270,12 +270,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
}
|
||||
}
|
||||
|
||||
public override void AddItem(PrintItemWrapper itemToAdd)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
LibraryProvider.OnDataReloaded(null);
|
||||
}
|
||||
|
||||
public void AddItem(PrintItemWrapper item, int indexToInsert = -1)
|
||||
{
|
||||
if (indexToInsert == -1)
|
||||
|
|
@ -361,11 +355,6 @@ namespace MatterHackers.MatterControl.PrintLibrary.Provider
|
|||
LibraryProvider.OnDataReloaded(null);
|
||||
}
|
||||
|
||||
public override void SaveToLibrary(PrintItemWrapper printItemWrapper, List<MeshGroup> meshGroupsToSave, List<ProviderLocatorNode> providerSavePath)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private static void AddStlOrGcode(LibraryProviderSQLite libraryToAddTo, string loadedFileName, string extension)
|
||||
{
|
||||
PrintItem printItem = new PrintItem();
|
||||
|
|
|
|||
|
|
@ -479,7 +479,8 @@ namespace MatterHackers.MatterControl.PrintQueue
|
|||
{
|
||||
foreach (QueueRowItem queueItem in queueDataView.SelectedItems)
|
||||
{
|
||||
LibraryDataView.CurrentLibraryProvider.AddItem(queueItem.PrintItemWrapper);
|
||||
// TODO: put up a library chooser and let the user put it where they want
|
||||
LibraryProviderSQLite.Instance.AddFilesToLibrary(new string[] {queueItem.PrintItemWrapper.FileLocation });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue