AutoHotkey Community

It is currently May 27th, 2012, 12:40 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: March 14th, 2010, 2:04 am 
Offline

Joined: November 21st, 2009, 11:06 am
Posts: 63
a_h_k wrote:
Here's the first basic working version :D ---> AutoIncludes.exe

Compiled for WinXP

You need to manually (possibly will put into gui later) create your "Include Set" file, which is a .txt file containing the full path(s) to the include folders to be included

I will post the code here at some point

Awesome thanks mate, looks fantastic and am trying it out now!
How exactly are we supposed to format the includes text file? It keeps telling me the folder doesn't exist.

Also, will I be able to fix my problem from the first post with this so that I can read the data from multiple files?

So thanks again, looks fantastic, and would love to see the code. With your permission I (or you can) post it up to lifehacker soon and if the right person sees it is should get on the tips page.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 14th, 2010, 5:26 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Greetings,..

chris96 wrote:
Also, will I be able to fix my problem from the first post with this so that I can read the data from multiple files?
a_h_k wrote:
Display all hotkeys that script uses (in main & its includes) . . . . . . . . . . yet to to
Once it's working reliably enough, this is the next thing i will do :)


Format of the Includes Set text file...
eg MySet.txt
Code:
C:\Will include all the scripts within this folder into one script   ;trailing "" optional
  ;can have blank lines between paths if want
C:\Another folder of files to include\



* All include files are backed-up before altering (renamed as "..._backup")


chris96 wrote:
It keeps telling me the folder doesn't exist
Could you give me some more details? (contents of file, working directory, line number of error)


I have made a few minor tweaks ... AutoIncludes


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 16th, 2010, 11:48 pm 
Thanks a_h_k,
could you share the code please, i would like to see the scripts that i run. :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: March 21st, 2010, 9:45 am 
Offline

Joined: November 21st, 2009, 11:06 am
Posts: 63
sorry for the delay in posting, have some other stuff going on right now and will test and reply back soon.
can you post the source?
cheers


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2010, 1:44 am 
Offline

Joined: November 21st, 2009, 11:06 am
Posts: 63
okay it appears to be messing up my scripts a bit, it added some random numbers which caused errors in the script
e.g.

910
Return

it was weird though, like in a different font in notepad to the rest!

Yeh it isn't working now, whenever i try to load it it just says error in line 4: text is a 3 digit number.

And how about that source :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2010, 3:33 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
Here's the source... :)

Code:
#SingleInstance, Force

; Init
;Change WHICH file(s) included --> recreate ahk
;Change CONTENT of file(s) included --> a) Interpreted > (do nout)
;               b) Compiled > Recompile exe


; @MyWorkingDir:
; Sets the "working directory" of the running script
MyWorkingDir = %A_ScriptDir%

MainFolder = %A_ScriptDir%

; @IncludeOrCombine:
; Determines if the output script will be
; a list of "#Include"d files, or
; a single file with the text from all files
; combined.
IncludeOrCombine = INCLUDE
;IncludeOrCombine = COMBINE

include_count = 0

TempFileName = %A_Temp%\AutoInclude.ahk
; End of the customizable section




; Main

;;FileSelectFolder, IncludeFolders1, *%MainFolder%, 2, Prompt]   ;can't select >1 folders


; Display main Gui
Gui, Add, Button, x6 y9 w180 h40 gNew, New
Gui, Add, Button, x186 y9 w180 h40 gOpen, Load Set
Gui, Add, Button, x366 y9 w180 h40 gSave, Save Set
Gui, Add, Button, x546 y9 w180 h40 gSaveAs, Save Set As
Gui, Add, Button, x730 y9 w180 h40 gQuit, Quit   ;was x726
;;Gui, Add, Button, x6 y60 w180 h40 gEdit, Edit Set
Gui, Add, Button, x6 y60 w180 h40 gBuild, Build
Gui, Show, w918 h108, Include Set Editor      ;was w952


While build_it <> 1
  Sleep, 100

;;return




;Gui, Submit [, NoHide]


;Let's collect all the Auto-Execute lines from each file,
;as well as all the code from each file,
;and create a new script that includes all of them!


;We have to "Split" the folders list for each line:
inc_folder_count = 0
Loop, Parse, IncludeFolders, `n
{
   inc_folder_count++
   IncludeFolder := A_LoopField

   ; Check that <IncludeFolder> exists
   IfNotExist, %IncludeFolder%
   {
      MsgBox, The specified Include folder `n`n %IncludeFolder% `n`n does not exist!
      ExitApp
   }

   ; #Include folder
   Include_folder_text%inc_folder_count% =
   (ltrim
                           #Include %IncludeFolder%
   )

   ;Let's load all the files from the folder:
;;   SetWorkingDir %IncludeFolder%
   Gosubs_text =                     ;for all files within this include folder
   Labels_text =                     ;      "            "            "               ;Labels_Includes_Contents_text
   Loop %IncludeFolder%\*.ahk, 0, 1         ;recursive
   {
      ; Ignore's
      ; Ignore any files with "exclude" in the title:
      If RegexMatch(A_LoopFileName, "i)\bexclude\b")
         continue

      ; Ignore any files with "_backup" in the title:
      If RegexMatch(A_LoopFileName, "i)_backup")
         continue

   
      ; We are going to create an "#Include" directive for each file

   
      ; FILE-ALTERING STUFF
      ; Make backup of this file first before altering it
      A_LoopFileNameNoExt := A_LoopFileNameNoExt()
      ;backup_filename := IncludeFolder "\" A_LoopFileDir "\" A_LoopFileNameNoExt "_backup." A_LoopFileExt
      backup_filename := A_LoopFileDir "\" A_LoopFileNameNoExt "_backup." A_LoopFileExt
      ;msgbox % backup_filename
      FileCopy, %A_LoopFileFullPath%, %backup_filename%, 1


      ; [ Insert a "Return" at end of auto-execute section ]
         ; Locate end of auto-execute section
         Gosub Locate_End_Auto_Execute

         ; Make room for my "Return" line
         ;msgbox end_of_auto_execute = %end_of_auto_execute%
         InsertBlankArrayLine2("FileLines", end_of_auto_execute, 4)

         ; Write my "Return" line (to array)
         Return_line := end_of_auto_execute + 1
         ;msgbox Return_line = %Return_line%
         FileLines%Return_line% = Return      ;This is the end of the auto-execute section

         ; Now write back to file
         FileLines := FileLines0
         file_variable =
         Loop, %FileLines%
         {
            line := FileLines%A_Index%
            file_variable .= line . "`n"
         }
         ;;msgbox about to save
         FileDelete, %A_LoopFileFullPath%
         FileAppend, %file_variable%, %A_LoopFileFullPath%



      ; Create a Gosub/Label/Return for this include file
      include_file_count++

      label = Include%include_file_count%
      ;;Gosubs_text := Gosubs_text%inc_folder_count%
      Gosubs_text =
      (ltrim
                           %Gosubs_text%
                           GoSub %label%      ; Run the Auto-Execute code for this file
      )

      ;;Labels_text := Labels_text%inc_folder_count%      ;Labels_Includes_Contents_text
      Labels_text =
      (ltrim
                        %Labels_text%
                        %label%:
      )
   


      ; Add #Include or <actual file contents>
      ;;Labels_text := Labels_text%inc_folder_count%      ;Labels_Includes_Contents_text
      ;
      If IncludeOrCombine = COMBINE
      {   FileRead FullFile, %A_LoopFileFullPath%
         Labels_text =         ;actual content of file         ;Labels_Includes_Contents_text
         (ltrim
                              %Labels_text%
                              ; #############################################################################
                              ; ###################################### Beginning of file %A_LoopFileFullPath%
                              ; #############################################################################
                              %FullFile%
                              ; #############################################################################
                              ; ###################################### End Of File %A_LoopFileFullPath%
                              ; #############################################################################
         )
      }
      Else
      {   ; IncludeOrCombine = INCLUDE
         Labels_text =
         (ltrim
                           %Labels_text%
                           %A_Space%#Include %A_LoopFileName%
         )
      }


      ; Add trailing Return
      ;;Labels_text := Labels_text%inc_folder_count%      ;Labels_Includes_Contents_text
      Labels_text =
      (ltrim
                           %Labels_text%
                           Return
      )


      Gosubs_text%inc_folder_count% := Gosubs_text
      Labels_text%inc_folder_count% :=   Labels_text      ;Labels_Includes_Contents_text
   }
}


; Delete temp file
FileDelete %TempFileName%


; Create our new file:
; Create Top_text
Top_text =
(ltrim
                           ;*** This script was automatically created from all the scripts found in the IncludeFolder(s) ***

                           #SingleInstance Force


)

; Create/combine Gosubs_text &  Include_folder_Labels_text
inc_folders := inc_folder_count
Gosubs_text := ""     ,     Include_folder_text := ""     ,     Labels_text := ""
;Include_folder_Labels_text := ""
Loop, %inc_folders%
{
   Gosubs_text .= Gosubs_text%A_Index%   ; . "`n"
   ;
   Include_folder_text := Include_folder_text%A_Index%
   Labels_text := Labels_text%A_Index%
   Include_folder_Labels_text .= Include_folder_text . Labels_text . "`n"
   If (inc_folders>1 and A_Index<inc_folders)
      Include_folder_Labels_text .= "`;`n"
}

; Create Your_Code_text
Your_Code_text =
(ltrim




                           ;PUT YOUR CODE HERE  (optional)




)

; Create Return_text
Return_text =
(ltrim
                           Return


)

; Create/combine all text into one variable --> Write to file
main_file_text := Top_text . Gosubs_text . Your_Code_text . Return_text . Include_folder_Labels_text
FileAppend, %main_file_text%, %TempFileName%
;>fe


; Open our new file
Run %TempFileName%

;>mainEnd


ExitApp


; Subroutines

Locate_End_Auto_Execute:
; Search for any/1st "::" hotkey (ie for end of A-E section)
FileRead, FileContents, %A_LoopFileFullPath%
;;msgbox reading %A_LoopFileFullPath%
;;msgbox contents = %FileContents%
StringSplit, FileLines, FileContents, `n, `r
;
end_of_auto_execute = 0
;;msgbox in here
;;msgbox FileLines0 = %FileLines0%
Loop, %FileLines0%
{
   file_line := FileLines%A_Index%
;;msgbox file_line = %file_line%
   If (pos:=InStr(file_line,"Return") > 0)         ;DOESN'T handle commented :: (after ;)
   {
      ; Check that not PART of another word
      ;
      char_after := SubStr(file_line,pos+6,1)
      If ( char_after=" " or char_after=A_Tab or char_after="" )      ;after
      {
         If (pos = 1)                     ;before
         {
            ;end_of_auto_execute := A_Index         (keep at 0 - so DOESN'T write "Return")
            Break
         }
         Else
         {   
            char_before := SubStr(file_line,pos-1,1)
            If ( char_before=" " or char_before=%A_Tab% )
            {
               ;end_of_auto_execute := A_Index         (keep at 0 - so DOESN'T write "Return")
               Break
            }
         }
      }
   }

   IfInString, file_line, ::            ;DOESN'T handle commented :: (after ;)
   {
;;msgbox here -- %A_LoopFileFullPath%
      end_of_auto_execute := A_Index
      Break
   }

   IfInString, file_line, #IfWin            ;DOESN'T handle commented #IfWin (after ;)
   {
      end_of_auto_execute := A_Index
      Break
   }
}
Return



/*
Edit:
   FileSelectFolder, sel_folder_path, %MainFolder%
Return
*/

Build:
   If (sel_set_file_path = "")
   {
      MsgBox,,, No Set File selected!, 2
      return
   }
   Else
   {
      ; @IncludeFolders:
      ; A list of all the folders to search:

      ; Read include folders data from selected Set File
      FileRead, file_data, %sel_set_file_path%
      StringSplit, file_data_array, file_data, `n, `r

      ; Add (valid) include folders to array (& Ignore/rid blank lines)
      IncludeFolders =
      raw_count := file_data_array0
      Loop, %raw_count%
      {
         line := file_data_array%A_Index%

         If  ( Right(line,1) = "\" )
            StringTrimRight, line, line, 1      ;Rid trailing "\"  (normalize)

         If (line <> "")
            IncludeFolders .= line . "`n"
      }
      StringTrimRight, IncludeFolders, IncludeFolders, 1      ;rid trailing `n
      build_it = 1
;;msgbox %IncludeFolders%
;;exitapp
}
Return

New:
Return

Open:
   FileSelectFile, sel_set_file_path,, %MainFolder%,, *.txt
Return

Save:
Return

SaveAs:
Return

Quit:
Return


; Functions

A_LoopFileNameNoExt()
{
  ;MUST be within a "Loop, FilePattern" loop
  ;In main script:  A_LoopFileNameNoExt := A_LoopFileNameNoExt()

  len_ext := StrLen(A_LoopFileExt) + 1   ;1 = "."
  StringTrimRight, A_LoopFileNameNoExt, A_LoopFileName, %len_ext%

  return A_LoopFileNameNoExt
}

InsertBlankArrayLine2(arrayName, at_element, blank_elements)
{
   Global   ;So can access the array

   array_elements := %arrayName%0

   to_element := array_elements + blank_elements
   from_element := array_elements

   Loop
   {
      %arrayName%%to_element% := %arrayName%%from_element%

      If (from_element = at_element)
      {
         ; "Blank" the necessary lines
         blank_this_element := at_element      ;=from_element
         Loop, %blank_elements%
         {
            %arrayName%%blank_this_element% =
            blank_this_element++
         }

         Break      ;Done all that NEED to do (can LEAVE all of array below this point)
      }

      to_element--
      from_element--
   }

   ; Update element count (re-write to array)
   %arrayName%0 := array_elements + blank_elements
}

Right(String, Count=0)
{
  StringRight, result, String, %Count%
  return result
}


Ps: I haven't had any time to work on this in the past couple of weeks, but hopefully i'll get some time in a week or so

Edit: Added my 3 functions to the source


Last edited by a_h_k on May 23rd, 2010, 11:29 am, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2010, 7:41 am 
Offline

Joined: March 29th, 2010, 9:12 pm
Posts: 1
Thank you for the source, there are some missing functions:
A_LoopFileNameNoExt()
InsertBlankArrayLine2
Right(line,1)

Where can i find them?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2010, 11:11 am 
Offline

Joined: February 2nd, 2008, 4:35 am
Posts: 643
I didn't consider that!
I created them, so you can't get them from anywhere else

Here they are...
Code:
A_LoopFileNameNoExt()
{
  ;MUST be within a "Loop, FilePattern" loop
  ;In main script:  A_LoopFileNameNoExt := A_LoopFileNameNoExt()

  len_ext := StrLen(A_LoopFileExt) + 1   ;1 = "."
  StringTrimRight, A_LoopFileNameNoExt, A_LoopFileName, %len_ext%

  return A_LoopFileNameNoExt
}

Code:
InsertBlankArrayLine2(arrayName, at_element, blank_elements)
{
   Global   ;So can access the array

   array_elements := %arrayName%0

   to_element := array_elements + blank_elements
   from_element := array_elements

   Loop
   {
      %arrayName%%to_element% := %arrayName%%from_element%

      If (from_element = at_element)
      {
         ; "Blank" the necessary lines
         blank_this_element := at_element      ;=from_element
         Loop, %blank_elements%
         {
            %arrayName%%blank_this_element% =
            blank_this_element++
         }

         Break      ;Done all that NEED to do (can LEAVE all of array below this point)
      }

      to_element--
      from_element--
   }

   ; Update element count (re-write to array)
   %arrayName%0 := array_elements + blank_elements
}

Code:
Right(String, Count=0)
{
  StringRight, result, String, %Count%
  return result
}


Just paste them at the end of the script .. actually .. i will also add them to the code in my other post


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], chaosad, jrav, Yahoo [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group