2014-02-17 16:35:24 -08:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2014, Lars Brubaker
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
2015-04-08 15:20:10 -07:00
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
2014-02-17 16:35:24 -08:00
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
2015-04-08 15:20:10 -07:00
|
|
|
|
list of conditions and the following disclaimer.
|
2014-02-17 16:35:24 -08:00
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
2015-04-08 15:20:10 -07:00
|
|
|
|
and/or other materials provided with the distribution.
|
2014-02-17 16:35:24 -08:00
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
2015-04-08 15:20:10 -07:00
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
2014-02-17 16:35:24 -08:00
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
2022-02-17 13:25:43 -08:00
|
|
|
|
using System.Linq;
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
using MatterHackers.MatterControl.DataStorage;
|
|
|
|
|
|
using Newtonsoft.Json;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
2022-02-17 08:08:24 -08:00
|
|
|
|
public class QueueData
|
|
|
|
|
|
{
|
|
|
|
|
|
private static QueueData instance;
|
|
|
|
|
|
public static QueueData Instance
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2022-02-17 08:08:24 -08:00
|
|
|
|
if (instance == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
instance = new QueueData();
|
|
|
|
|
|
}
|
2020-07-24 14:03:45 -07:00
|
|
|
|
|
2022-02-17 08:08:24 -08:00
|
|
|
|
return instance;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-17 08:08:24 -08:00
|
|
|
|
public int ItemCount
|
|
|
|
|
|
{
|
2015-04-08 15:20:10 -07:00
|
|
|
|
get
|
2022-02-17 08:08:24 -08:00
|
|
|
|
{
|
2022-02-17 13:25:43 -08:00
|
|
|
|
var queueDirectory = LegacyQueueFiles.QueueDirectory;
|
2022-07-15 17:28:39 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
return Directory.EnumerateFiles(queueDirectory).Count();
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (DirectoryNotFoundException)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
2022-02-17 13:25:43 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-02-17 08:08:24 -08:00
|
|
|
|
|
|
|
|
|
|
public void AddItem(string filePath)
|
|
|
|
|
|
{
|
2022-02-17 13:25:43 -08:00
|
|
|
|
var queueDirectory = LegacyQueueFiles.QueueDirectory;
|
|
|
|
|
|
Directory.CreateDirectory(queueDirectory);
|
|
|
|
|
|
var destFile = Path.Combine(queueDirectory, Path.GetFileName(filePath));
|
|
|
|
|
|
File.Copy(filePath, destFile, true);
|
|
|
|
|
|
}
|
2022-02-17 08:08:24 -08:00
|
|
|
|
|
2022-02-17 13:25:43 -08:00
|
|
|
|
public string GetFirstItem()
|
2022-02-17 08:08:24 -08:00
|
|
|
|
{
|
2022-02-17 13:25:43 -08:00
|
|
|
|
return new DirectoryInfo(LegacyQueueFiles.QueueDirectory).GetFiles().OrderBy(f => f.LastWriteTime).Select(f => f.FullName).FirstOrDefault();
|
2022-02-17 08:08:24 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<string> GetItemNames()
|
|
|
|
|
|
{
|
2022-02-17 13:25:43 -08:00
|
|
|
|
return new DirectoryInfo(LegacyQueueFiles.QueueDirectory).GetFiles().Select(f => f.FullName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-02-17 08:08:24 -08:00
|
|
|
|
|
|
|
|
|
|
public class LegacyQueueFiles
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2022-02-17 13:25:43 -08:00
|
|
|
|
public static string QueueDirectory => Path.Combine(ApplicationDataStorage.Instance.ApplicationLibraryDataPath, "Queue");
|
|
|
|
|
|
|
2022-02-17 08:08:24 -08:00
|
|
|
|
public List<PrintItem> ProjectFiles { get; set; }
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2022-02-17 13:25:43 -08:00
|
|
|
|
public static void ImportFromLegacy()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2022-02-17 13:25:43 -08:00
|
|
|
|
var legacyQueuePath = Path.Combine(ApplicationDataStorage.ApplicationUserDataPath, "data", "default.mcp");
|
2015-09-03 09:26:54 -07:00
|
|
|
|
|
2022-02-17 13:25:43 -08:00
|
|
|
|
if (!File.Exists(legacyQueuePath))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2022-02-17 08:08:24 -08:00
|
|
|
|
// nothing to do
|
|
|
|
|
|
return;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-17 13:25:43 -08:00
|
|
|
|
string json = File.ReadAllText(legacyQueuePath);
|
2015-08-08 11:25:51 -07:00
|
|
|
|
|
2022-02-17 08:08:24 -08:00
|
|
|
|
LegacyQueueFiles newProject = JsonConvert.DeserializeObject<LegacyQueueFiles>(json);
|
|
|
|
|
|
if (newProject.ProjectFiles.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-17 13:25:43 -08:00
|
|
|
|
var queueDirectory = QueueDirectory;
|
|
|
|
|
|
Directory.CreateDirectory(queueDirectory);
|
2022-02-17 08:08:24 -08:00
|
|
|
|
foreach (var printItem in newProject.ProjectFiles)
|
|
|
|
|
|
{
|
2022-02-17 13:25:43 -08:00
|
|
|
|
var destFile = Path.Combine(queueDirectory, Path.ChangeExtension(printItem.Name, Path.GetExtension(printItem.FileLocation)));
|
2022-02-17 08:08:24 -08:00
|
|
|
|
if (!File.Exists(destFile)
|
|
|
|
|
|
&& File.Exists(printItem.FileLocation))
|
|
|
|
|
|
{
|
|
|
|
|
|
// copy the print item to the destination directory
|
|
|
|
|
|
File.Copy(printItem.FileLocation, destFile, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-02-17 13:25:43 -08:00
|
|
|
|
|
|
|
|
|
|
// and rename the .mcp file no that we have migrated it
|
|
|
|
|
|
File.Move(legacyQueuePath, Path.ChangeExtension(legacyQueuePath, ".bak"));
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|