55using System . Text ;
66using System . Text . RegularExpressions ;
77using System . Diagnostics ;
8- using NDesk . Options ;
98using System . Globalization ;
9+ using System . Configuration ;
10+ using System . Collections . Specialized ;
11+ using Mono . Options ;
1012
1113namespace Slic3rPostProcessing
1214{
@@ -21,6 +23,8 @@ internal class Program
2123 public static int ConsoleWidth { get ; set ; }
2224
2325 public static string strTimeformat = "yyMMdd-HHmmss" ;
26+ public static int intExportCounter ;
27+ public static int intSizeOfCounter ;
2428
2529 /// <summary>
2630 /// Post processing for Slic3r to color the toolpaths to view in Craftware
@@ -34,17 +38,22 @@ private static int Main(string[] args)
3438 {
3539 Properties . Settings . Default . Reload ( ) ;
3640
37- if ( Properties . Settings . Default . _UpdateRequired == true )
41+ string inifile = Path . Combine ( Path . GetDirectoryName ( System . Reflection . Assembly . GetExecutingAssembly ( ) . Location ) , "settings.ini" ) ;
42+ INI inisettings = new INI ( inifile ) ;
43+
44+ if ( ! File . Exists ( inifile ) )
3845 {
39- Properties . Settings . Default . Upgrade ( ) ;
40- Properties . Settings . Default . _UpdateRequired = false ;
41- Properties . Settings . Default . Save ( ) ;
46+ inisettings . WriteValue ( "ExportCounter" , "PostProcessing" , 0 . ToString ( ) ) ;
47+ inisettings . WriteValue ( "CounterPadding" , "PostProcessing" , 6 . ToString ( ) ) ;
48+ inisettings . Save ( ) ;
4249 }
4350
51+ int . TryParse ( inisettings . GetValue ( "ExportCounter" , "PostProcessing" ) , out intExportCounter ) ;
52+ int . TryParse ( inisettings . GetValue ( "CounterPadding" , "PostProcessing" ) , out intSizeOfCounter ) ;
53+
4454 bool show_help = false ;
4555
4656 int verbosity = 3 ;
47- int intSizeOfCounter = Properties . Settings . Default . _intCounterSize ;
4857 double stopbeadheater = 0d ;
4958 string strINputFile = null ;
5059 string strOUTputFile = null ;
@@ -67,11 +76,9 @@ private static int Main(string[] args)
6776 os . Add ( "o|output=" , "The {OUTPUT} filename. " + Environment . NewLine + "Optional. {INPUT} will get overwritten if {OUTPUT} is not specified. File extension will be added if omitted." ,
6877 o => strOUTputFile = o ) ;
6978
70- os . Add ( "c|counter=" , "Adds an export-counter to the FRONT of the filename ({+ or -})." + Environment . NewLine + "Default: -c + (true)" + Environment . NewLine + "If the timestamp is set to true as well, only the counter will be added." ,
79+ os . Add ( "c|counter=" , "Adds an export-counter to the FRONT of the filename ({+ or -}). Default: -c+ (true) " + Environment . NewLine + "Next counter: " + ( intExportCounter ) . ToString ( "D" + intSizeOfCounter ) + Environment . NewLine + "( If the timestamp is set to true as well, only the counter will be added.) " ,
7180 c => booCounter = c != null ) ;
7281
73- os . Add ( "cd|counterdigits=" , "Counter padded with this many zeros {1-10}. Default " + intSizeOfCounter . ToString ( ) + ". Next counter: " + ( Properties . Settings . Default . export_counter + 1 ) . ToString ( "D" + intSizeOfCounter . ToString ( ) ) , ( int cd ) => { if ( cd > 0 & cd < 11 ) intSizeOfCounter = cd ; } ) ;
74-
7582 os . Add ( "r|removeconfig=" , "Removes Configuration at end of file ({+ or -}). Everything after \" END FOOTER\" will be removed." + Environment . NewLine + "Default: -r- (false)." ,
7683 r => booRemoveConfig = r != null ) ;
7784
@@ -128,23 +135,16 @@ private static int Main(string[] args)
128135
129136 if ( booResetCounter )
130137 {
131- Properties . Settings . Default . export_counter = 0 ;
132- Properties . Settings . Default . Save ( ) ;
138+ intExportCounter = 0 ;
139+ inisettings . WriteValue ( "ExportCounter" , "PostProcessing" , 0 . ToString ( ) ) ;
140+ inisettings . Save ( ) ;
133141 Environment . Exit ( 3 ) ;
134142 return 3 ;
135143 }
136144
137- if ( Properties . Settings . Default . _intCounterSize != intSizeOfCounter )
138- {
139- // add settings to user-settings
140- Properties . Settings . Default . _intCounterSize = intSizeOfCounter ;
141- Properties . Settings . Default . Save ( ) ;
142- //
143- }
144-
145145 if ( strINputFile == null )
146146 {
147- // Console.WriteLine("I need an arguement ; your's not good!");
147+ // Console.WriteLine("I need an argument ; your's not good!");
148148 ShowHelp ( os ) ;
149149 Environment . Exit ( 1 ) ;
150150 return 1 ;
@@ -444,12 +444,6 @@ private static int Main(string[] args)
444444
445445 if ( booCounter & booTimestamp ) booTimestamp = false ;
446446
447- if ( booCounter )
448- {
449- Properties . Settings . Default . export_counter ++ ;
450- Properties . Settings . Default . Save ( ) ;
451- }
452-
453447 Logger . LogInfo ( "Output :" ) ;
454448 if ( strOUTputFile != null & File . Exists ( newfilename ) )
455449 {
@@ -464,8 +458,8 @@ private static int Main(string[] args)
464458 }
465459 else if ( booCounter )
466460 {
467- string newfile = strOUTputFile . PrependCounter ( intSizeOfCounter ) ;
468- File . Move ( newfilename , strOUTputFile . PrependCounter ( intSizeOfCounter ) ) ;
461+ string newfile = strOUTputFile . PrependCounter ( ) ;
462+ File . Move ( newfilename , newfile ) ;
469463 PrintFileSummary ( newfile ) ;
470464 }
471465 else
@@ -486,7 +480,7 @@ private static int Main(string[] args)
486480 }
487481 else if ( booCounter )
488482 {
489- string newfile = strINputFile . PrependCounter ( intSizeOfCounter ) ;
483+ string newfile = strINputFile . PrependCounter ( ) ;
490484 File . Move ( newfilename , newfile ) ;
491485 PrintFileSummary ( newfile ) ;
492486 }
@@ -500,6 +494,18 @@ private static int Main(string[] args)
500494 if ( stopbeadheater > 0 ) { Logger . LogInfo ( "Bed Heater disabled after height " + stopbeadheater + " mm." ) ; }
501495 if ( booRemoveConfig ) { Logger . LogInfo ( "Configuration/Settings have been removed from GCode." ) ; }
502496
497+ intExportCounter ++ ;
498+ inisettings . WriteValue ( "ExportCounter" , "PostProcessing" , intExportCounter . ToString ( ) ) ;
499+ inisettings . Save ( ) ;
500+
501+ string ts = ( ( char ) ( '\u25a0 ' ) ) . ToString ( ) . PadRight ( 5 , '\u25a0 ' ) ;
502+ Logger . LogInfo ( ts + " All Done " + ts ) ;
503+
504+ //
505+ //
506+ //
507+ // END OF EVERYTHING
508+
503509#if DEBUG
504510 {
505511 Console . WriteLine ( "Press any key to continue . . ." ) ;
@@ -509,10 +515,6 @@ private static int Main(string[] args)
509515 System . Threading . Thread . Sleep ( 500 ) ;
510516#endif
511517
512- string ts = ( ( char ) ( '\u25a0 ' ) ) . ToString ( ) ;
513- ts = ts . PadRight ( 5 , '\u25a0 ' ) ;
514- Logger . LogInfo ( ts + " All Done " + ts ) ;
515-
516518 Environment . Exit ( 0 ) ;
517519 return 0 ;
518520 }
@@ -584,22 +586,22 @@ private static bool WaitForFile(string filename, int timeout = 30)
584586
585587 private static void Progressbar ( double Progress , bool ReportAsPercentage = true , int Value = - 1 )
586588 {
587- int conswidth = ConsoleWidth - 20 ;
589+ int conswidth = ConsoleWidth - 2 ;
588590 char pad = '\u2588 ' ; // '█';
589591 char spad = '\u2591 ' ; // '░';
590592 string prog = "" ;
591593 string progformat = "" ;
592- double newprog ;
593-
594- newprog = ( Value != - 1 ) ? Value : Progress / 100 ;
594+ double newprog = ( Value != - 1 ) ? Value : Progress / 100 ;
595595
596- progformat = ReportAsPercentage ? String . Format ( "{0:P0} " , newprog ) . PadRight ( 5 ) : String . Format ( "{0} " , newprog ) . PadRight ( 5 ) ;
596+ progformat = ReportAsPercentage ? String . Format ( "{0:P0} " , newprog ) . PadRight ( 5 ) . PadLeft ( 10 ) : String . Format ( "{0} " , newprog ) . PadRight ( 5 ) . PadLeft ( 10 ) ;
597+ //progformat = " " + progformat;
597598
598- double doh = Progress / 100 * conswidth ;
599+ conswidth -= progformat . Length ;
600+ double consprog = Progress / 100 * conswidth ;
599601
600- int progr = ( int ) Math . Round ( doh , 0 ) ;
602+ int progr = ( int ) Math . Round ( consprog , 0 ) ;
601603
602- string mynewfunkyprogressbar = " " +
604+ string mynewfunkyprogressbar =
603605 progformat +
604606 prog . PadLeft ( progr , pad ) +
605607 prog . PadLeft ( conswidth - progr , spad ) ;
@@ -630,37 +632,39 @@ private static string TrimComment(string line)
630632
631633 private static void ShowHelp ( OptionSet p )
632634 {
635+ string pathname = Path . GetFullPath ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) ;
636+
633637 ConsoleColor fg = Console . ForegroundColor ;
634638 ConsoleColor bg = Console . BackgroundColor ;
635639
636640 Console . WriteLine ( ) ;
637641 Console . BackgroundColor = ConsoleColor . Black ;
638642 Console . ForegroundColor = ConsoleColor . Yellow ;
639643
640- string textnote = "This program is for use with Slic3r (or standalone)." ;
641- int paaad = ( Program . ConsoleWidth - textnote . Length ) / 2 ;
644+ string textnote = "This program is for use with Slic3r (standalone use see below )." ;
645+ int paddin = ( Program . ConsoleWidth - textnote . Length ) / 2 ;
642646
643- Console . WriteLine ( "" . PadLeft ( paaad ) + textnote . PadRight ( Program . ConsoleWidth - paaad ) ) ;
647+ Console . WriteLine ( "" . PadLeft ( paddin ) + textnote . PadRight ( Program . ConsoleWidth - paddin ) ) ;
644648 Console . ResetColor ( ) ;
645649 Console . WriteLine ( ) ;
646650 Console . WriteLine ( " Print Settings -> Output options" ) ;
647651 Console . WriteLine ( " * Enable Verbose G-Code (!)" ) ;
648652
649- Console . WriteLine ( " * Put this filename " + Path . GetFileName ( System . Reflection . Assembly . GetEntryAssembly ( ) . Location ) + " in Post-Processing Scripts. ") ;
650- Console . WriteLine ( " Current filename: \" " + System . Reflection . Assembly . GetEntryAssembly ( ) . Location + "\" " ) ;
653+ Console . WriteLine ( " * Put this filename in Post-Processing Scripts: " ) ;
654+ Console . WriteLine ( " \" " + pathname + "\" " ) ;
651655
652656 Console . WriteLine ( "" ) ;
653657 Console . WriteLine ( " Printer Settings:" ) ;
654- Console . WriteLine ( " * Add \" ; START Header\" and \" ; END Header\" to your Start GCode." ) ;
655- Console . WriteLine ( " * Add \" ; START Footer\" and \" ; END Footer\" to your End GCode." ) ;
658+ Console . WriteLine ( " * Add \' ; START Header\' and \' ; END Header\' to your Start GCode." ) ;
659+ Console . WriteLine ( " * Add \' ; START Footer\' and \' ; END Footer\' to your End GCode." ) ;
656660
657661 Console . WriteLine ( ) ;
658662 Console . BackgroundColor = ConsoleColor . Black ;
659663 Console . ForegroundColor = ConsoleColor . Yellow ;
660664
661- textnote = "Standalone usage : Slic3rPostProcessing [OPTIONS]" ;
662- paaad = ( Program . ConsoleWidth - textnote . Length ) / 2 ;
663- Console . WriteLine ( "" . PadLeft ( paaad ) + textnote . PadRight ( Program . ConsoleWidth - paaad ) ) ;
665+ textnote = "Standalone use : Slic3rPostProcessing [OPTIONS]" ;
666+ paddin = ( Program . ConsoleWidth - textnote . Length ) / 2 ;
667+ Console . WriteLine ( "" . PadLeft ( paddin ) + textnote . PadRight ( Program . ConsoleWidth - paddin ) ) ;
664668
665669 Console . ResetColor ( ) ;
666670 Console . WriteLine ( ) ;
@@ -709,6 +713,11 @@ public static class DonotReset
709713
710714 public static class MyExtensions
711715 {
716+ public static double hoch ( this double das , double Exponent )
717+ {
718+ return Math . Pow ( das , Exponent ) ;
719+ }
720+
712721 public static string AppendTimeStamp ( this string fileName )
713722 {
714723 return Path . Combine ( Path . GetDirectoryName ( fileName ) ,
@@ -718,14 +727,19 @@ public static string AppendTimeStamp(this string fileName)
718727 + Path . GetExtension ( fileName ) ) ;
719728 }
720729
721- public static string PrependCounter ( this string fileName , int digits )
730+ /// <summary>
731+ /// Adds counter to fileName
732+ /// </summary>
733+ /// <param name="fileName">Filename to add counter to</param>
734+ /// <param name="counter">Counter to add</param>
735+ /// <param name="digits">Number of digits padded with zero</param>
736+ /// <returns></returns>
737+ public static string PrependCounter ( this string fileName )
722738 {
723- int counter = Properties . Settings . Default . export_counter ;
724-
725- string numformat = "D" + digits . ToString ( ) ;
739+ string numformat = "D" + Program . intSizeOfCounter . ToString ( ) ;
726740
727741 return Path . Combine ( Path . GetDirectoryName ( fileName ) ,
728- counter . ToString ( numformat )
742+ Program . intExportCounter . ToString ( numformat )
729743 + "_"
730744 + Path . GetFileNameWithoutExtension ( fileName )
731745 + Path . GetExtension ( fileName ) ) ;
0 commit comments